2017-07-30 64 views
-1

能否請你幫我這個代碼PowerShell的下載和從註冊表中提取

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -windowstyle hidden -noexit -command (New-Object System.Net.WebClient).DownloadFile('Url',"$env:temp\cat.zip"); Expand-Archive "$env:temp\cat.zip" -DestinationPath "$env:temp\pp" -Force" 

添加在 HKLM \軟件\微軟\ WINDOWS \ currentversoin \運行,但沒有我把似乎重新啓動後工作。

+1

如果你試圖把一些簡單的命令進入註冊表,它不工作,然後你的問題是不是與PowerShell和這個問題不涉及編程。從cmd shell運行命令時,命令是否按預期工作? – TToni

+0

當我把代碼在註冊表中它成功添加,但重新啓動後它不會運行,但是當我打開Powershell並運行它與此代碼(New-Object System.Net.WebClient).DownloadFile('Url', 「$ ENV:TEMP \ cat.zip」);展開 - 存檔「$ env:temp \ cat.zip」-DestinationPath「$ env:temp \ pp」-Force「它的工作原理 – renwex

+0

您是否檢查過系統日誌以查看是否有未運行的原因 –

回答

0

你有很多引號,他們看起來不正確。你沒有用報價開始你的命令,但你用報價結束了它。這應做到:

powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -Command "(New-Object System.Net.WebClient).DownloadFile('Url',""$env:temp\cat.zip""); Expand-Archive ""$env:temp\cat.zip"" -DestinationPath ""$env:temp\pp"" -Force" 

另外,我放棄了-NoExit,但也許你確實想PowerShell來保持運行。

此外,PowerShell的執行處理的編碼命令,併爲您提供有關如何做到這一點的說明:powershell.exe /?

要使用-EncodedCommand參數:

$命令=「目錄「C:\程序文件」'

$字節= [System.Text.Encoding] :: Unicode.GetBytes($命令)

$ encodedCommand = [變換] ::巴爾王座ase64String($字節)

powershell.exe -encodedCommand $ encodedCommand

你沒給我URL否則我就編碼爲你,但是這將幫助您節省一些頭痛經過複雜的命令時進入powershell.exe像這樣。下面是你可以在命令從例如通過註冊表通:

powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand ZABpAHIAIAAiAGMAOgBcAHAAcgBvAGcAcgBhAG0AIABmAGkAbABlAHMAIgAgAA==