首页 > 解决方案 > 如何使用 PowerShell 远程执行 VBScript?

问题描述

我有一个 VBScript 将 Internet Explorer 设置为默认浏览器。我想使用 PowerShell 远程执行该 VBScript。我尝试了以下命令:

$result = Invoke-Command -ComputerName $computerName  -ScriptBlock { 
    Invoke-Expression -Command:"cmd.exe /c cscript.exe 
    C:\Users\mani\Desktop\test.vbs"
} -Credential $MySecureCreds

我也尝试过以下方法:

$result = Invoke-Command -ComputerName $computerName -ScriptBlock { 
    cscript.exe C:\Users\mani\Desktop\test.vbs"
} -Credential $MySecureCreds

test.vbs代码如下:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\system32\control.exe /name Microsoft.DefaultPrograms 
/page pageDefaultProgram\pageAdvancedSettings?pszAppName=Internet%20Explorer"
WScript.Sleep 1200
WshShell.SendKeys "{TAB}"
WshShell.SendKeys " "
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys " "
WshShell.Popup " Internet Explorer set as Default Browser Successfully!!!. ", 3, "Default Browser"
WScript.Quit

但是,通过使用上述命令,默认浏览器不会改变。如果我手动运行 VBScript,它可以工作。如何远程执行 VBScript?

标签: windowspowershellvbscriptremotinginvoke-command

解决方案


推荐阅读