我正在试着用我做的简单的脚本用CMD来加载outlook。当我以admin (我的用户帐户)身份通过CMD ran在用户的计算机上打开这个脚本时,问题变成了,它将打开我的outlook,就像我现在打开它的用户一样。这样我的收件箱就不是用户了。如果我只是在普通的cmd模式下运行它,而不是在提升的模式下运行,那么脚本运行得很好。
如何确保从提升的CMD打开我的用户的收件箱,而不是打开已引发CMD的用户的收件箱?
strPath = WshShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")
outlook15 = strPath & "\Microsoft Office\Office15\outlook.exe"
outlook14 = strPath & "\Microsoft Office\Office14\outlook.exe"
If fso.FileExists(outlook15) Then
msgbox "TITUS successfully fixed!", 64
WScript.Sleep 3000
WshShell.Run Chr(34) & outlook15 & Chr(34)
Set fso = Nothing
Set WshShell = Nothing
Else
msgbox "TITUS successfully fixed!", 64
WScript.Sleep 3000
WshShell.Run Chr(34) & outlook14 & Chr(34)
Set fso = Nothing
Set WshShell = Nothing
End If发布于 2014-07-04 02:06:57
要检测正在运行CMD的当前用户,您可以像这样获取whoami命令的输出:
Set oExec = WshShell.Exec("whoami")
strUser = oExec.StdOut.ReadLine然后,您可以将runa添加到WshShell.Run语句中以更改用户上下文:
If strUser = "admin" Then
WshShell.Run "runas /user:" & otherUser & " " & Chr(34) & outlook15 & Chr(34)
End If另一个用户名需要通过输入提示符提供,或者可以从另一个命令(qwinsta、psloggedon等)捕获并通过regex提取。还应该注意的是,runas将提示输入其他用户的密码。
https://stackoverflow.com/questions/24525627
复制相似问题