我一直致力於擴展一個基本批次來提取 IP 訊息,以包含與我的 IT 部門工作相關的其他資訊。我的部門在全國範圍內為最終用戶和伺服器上的思科設備進行故障排除。到目前為止,我已經獲得了 ipconfig 詳細資訊和 mac 位址以及一些排除項的檔案。到目前為止,這是我的程式碼:
@echo off
echo Listed below is your network IP information and physical MAC address.
echo\
echo I am logged as %UserName%.
echo My computer's name is %ComputerName%.
echo My IP settings are
ipconfig | find "." | find /i /v ""
echo\
echo My Mac address is
getmac | find /i /v "disconnected" | find /i /v "not present"
echo\
echo Provide this information to the IT team.
echo Press the Space bar to close this window.
echo\
pause > nul
我一直在瀏覽這裡和其他此類網站,尋找我可能能夠修改的相關範例,但顯然我只是對非思科的東西感到厭煩。這是從另一篇文章中提取的新程式碼,目前作為自己的批次:
@echo off
Setlocal Enableextensions
Setlocal Enabledelayedexpansion
for /r %%X in (*.URL) do (
set shortcut="%%X"
echo SHORTCUT: !shortcut!
for /f "tokens=2 delims==" %%i in ('findstr URL !shortcut!') do (
set URL=%%i
echo.
echo URL PATH: !URL!
)
echo ----------------------------------------------------------------
echo.
)
:end
Pause
我運行此程式得到的輸出是:
SHORTCUT: "C:\Users\***\Desktop\Application Catalog, IE only.url"
URL PATH: http://***/cmapplicationcatalog/#/SoftwareLibrary/AppListPageView.xaml
----------------------------------------------------------------
SHORTCUT: "C:\Users\***\Desktop\Test Yahoo.url"
URL PATH: http://www.yahoo.com/
----------------------------------------------------------------
Press any key to continue . . .
*** 是我截斷的路徑。
當我讓它發揮作用時,我會將它們結合在一起。我試圖從第二批中獲取的是每台電腦桌面上的一個特定文件,我們稱之為 CDK 驅動器,以提取其目標資訊。目標中是一個完整的IP位址(http://*。.**.*/) 我需要。捷徑的目標類型是Application,檔案本身的類型是Shortut(.lnk)。目標的一個例子是:
"C:\Program Files (x86)\Internet Explorer\iexplore.exe" http://***.**.209.42/bin/start/wsStart.application
我試圖提供盡可能多的具體信息,以便我能夠獲得最準確的幫助。
先感謝您。
更新:所以,我使用 Powershell 並讓我的批次運行它,取得了一些進展。到目前為止,這是我的 Powershell 程式碼,它「幾乎」按預期工作。
function Get-StartMenuShortcuts
{
$Shortcuts = Get-ChildItem -Recurse "$Env:C:\Users\alexandm\Desktop\Batching" -Include *.lnk
$Shell = New-Object -ComObject WScript.Shell
foreach ($Shortcut in $Shortcuts)
{
$Properties = @{
ShortcutName = $Shortcut.Name
Target = $Shell.CreateShortcut($Shortcut).targetpath
}
New-Object PSObject -Property $Properties
}
[Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null
}
$Output = Get-StartMenuShortcuts
$Output
當我的批次運行時,我得到的輸出顯示了基本目標路徑,它恰好是 iexplore.exe,但它沒有給我整個目標路徑,包括我們添加的 IP 位址。知道我缺少什麼嗎?
答案1
您的 powershell 程式碼可能如下所示:
$shell = New-Object -COM WScript.Shell
Get-ChildItem -Recurse "$env:UserProfile\Desktop\*.lnk","$env:PUBLIC\Desktop\*.lnk" |
ForEach-Object {
$shortcut = $shell.CreateShortcut($_.FullName)
$Args = $shortcut.Arguments
if ( $Args -match [system.Uri]::SchemeDelimiter) {
"shortcut: $($_.Name)"
"exe path: $($shortcut.TargetPath)"
"link URL: $($Args)"
"---"
}
}
省略了所有這些功能和PS對象東西(假設這是一個一次性腳本,它只會展示一個結果)。
[system.Uri]::SchemeDelimiter
Uri 字段,請參閱.NET
URI 類用於簡單地檢查是否$shortcut.Arguments
可以URI
(指定將通訊協定方案與位址部分分開的字元URI
);正如目前所寫的,該腳本不關心協議及其有效性。
更新。現在處理所有.lnk
資料夾目前用戶的桌面和從民眾桌面遞迴地。