此VBScript运行一些PowerShell脚本。我将调用notepad.exe
放在那里,以确保它以管理员身份运行。
我的PowerShell脚本打开控制台,但随后它们立即关闭 我想让他们保持开放。
有什么问题?
这是我的VBScript:
RunAsAdmin()
Set shell = WScript.CreateObject("WScript.shell")
shell.Run("powershell.exe -noexit -executionpolicy bypass -file .\Source\RemoveWindows10Apps-2.0.ps1"), 1 , True
Set shell = WScript.CreateObject("WScript.shell")
shell.Run("powershell.exe -noexit -executionpolicy bypass -file .\Source\ChangeWin10StartLayout.ps1"), 1 , True
Set shell = WScript.CreateObject("WScript.shell")
shell.Run("powershell.exe -noexit -executionpolicy bypass -file .\Source\NewFolder.ps1"), 1 , True
Set shell = WScript.CreateObject("WScript.shell")
shell.Run("notepad.exe"), 1 , True
Function RunAsAdmin()
Dim objAPP
If WScript.Arguments.length = 0 Then
Set objAPP = CreateObject("Shell.Application")
objAPP.ShellExecute "wscript.exe", """" & _
WScript.ScriptFullName & """" & " RunAsAdministrator",,"runas", 1
WScript.Quit
End If
End Function
答案 0 :(得分:2)
我想这是因为您使用相对路径,所以当您的脚本将自己称为管理员时,您当前的目录将更改为...\WINDOWS\system32
。
尝试构建绝对路径并将其传递给PowerShell,如此
RunAsAdmin()
strScriptPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strScriptPath )
strScriptFolder = objFSO.GetParentFolderName(objFile)
Set shell = WScript.CreateObject("WScript.shell")
shell.Run("powershell.exe -noexit -executionpolicy bypass -file " & strScriptFolder & "\Source\RemoveWindows10Apps-2.0.ps1"), 1 , True
...