[英]How to Call Powershell Copy-Script from VBS Logon Script
我目前正在將登錄腳本從VBS轉換為Powershell,並且其中一個子程序(如果它是較舊的版本,則更新特定文件)已簡化為:
sub UrgentSupportApp()
On Error Resume Next
Set objShell = CreateObject("WScript.Shell")
objShell.Run "powershell -file ""\\DC1\NETLOGON\PSSubs\UrgentSupportApp.ps1""", 0, true
If Err <> 0 Then
strMessage = "ERROR: Sub - UrgentSupportApp"
DisplayCustomError(strMessage)
End If
End Sub
但是,當我登錄時會看到此錯誤:
數(十進制):-2147352567
十六進制數字:&H80020009
說明:無法等待過程。
來源:WshShell.Run
我知道Powershell可以工作,因為我已經將其作為獨立腳本進行了測試。 但是,我不確定通過網絡訪問它是否對env:USERPROFILE
變量有影響(這里是哪個用戶?)。
我嘗試將bWaitOnReturn
參數更改為false
,這沒有導致任何錯誤,但是腳本實際上並未完成工作。
有人對我如何調試它或可能出了什么問題有任何提示嗎?
ps1腳本如下所示:
$appsource = '\\file\Administration\Unused\Apps\IT Support App\IT Self Help.exe'
$apptarget = $env:USERPROFILE + '\desktop\IT Self Help.exe'
$oldapp1 = $env:USERPROFILE + '\desktop\Urgent IT Help Request.exe'
$oldapp2 = $env:USERPROFILE + '\desktop\IT Help Request.exe'
$currentversion = (Get-Command $appsource).FileVersionInfo.FileVersion
If (Test-Path $oldapp1) {Remove-Item $oldapp1}
If (Test-Path $oldapp2) {Remove-Item $oldapp2}
If (Test-Path $apptarget) {
If (!((Get-Command $apptarget).FileVersionInfo.FileVersion -eq $currentversion)) {
Copy-Item $appsource $env:USERPROFILE'\desktop' -Force
}
}
Else {Copy-Item $appsource $env:USERPROFILE'\desktop' -Force}
它只是刪除所有具有舊名稱的文件,然后復制最新版本(如果尚不存在)。
通過將VBS調用更改為:
objShell.Run("powershell.exe -noexit \\\\DC1\\NETLOGON\\PSSubs\\UrgentSupportApp.ps1"), 0
我不確定為什么會這樣,但是確實可以。
請注意,當用戶登錄計算機時,將通過登錄腳本在瘦客戶機上調用此方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.