Shell.Execute命令中的“ dir”参数在“ verb”参数包含“ runas”选项时不起作用

时间:2019-06-05 11:30:38

标签: vbscript

尽管我将当前目录传递给“ dir”参数,但当前目录仍为“ C:\ Windows \ System32”。

If CreateObject("WScript.Shell").Run("%ComSpec% /C ""NET FILE""", 0, True) <> 0 Then
    CreateObject("Shell.Application").ShellExecute WScript.FullName, """" & WScript.ScriptFullName & """", CreateObject("WScript.Shell").CurrentDirectory, "runas", 5
    WScript.Quit
End If

我该如何解决问题?

我的答案:

我解决了:

If WScript.Arguments.Count <> 0 Then WScript.Quit 1
RunAsAdmin
Main

Sub RunAsAdmin()
    Set Shell = CreateObject("WScript.Shell")
    Set Env = Shell.Environment("VOLATILE")
    If Shell.Run("%ComSpec% /C ""NET FILE""", 0, True) <> 0 Then
        Env("CurrentDirectory") = Shell.CurrentDirectory
        ArgsList = ""
        For i = 1 To WScript.Arguments.Count
            ArgsList = ArgsList & """ """ & WScript.Arguments(i - 1)
        Next
        CreateObject("Shell.Application").ShellExecute WScript.FullName, """" & WScript.ScriptFullName & ArgsList & """", , "runas", 5
        WScript.Quit
    End If
    Shell.CurrentDirectory = Env("CurrentDirectory")
    Env.Remove("CurrentDirectory")
End Sub

Sub Main()

End Sub

0 个答案:

没有答案