How do I determine if VBScript is running in RDP Console?
I have an MSI installer that fails if it is running over remote desktop. (Unless it is run with the /admin or /console option so that it gets session 0)
I want to use a VBScript custom action to determine if I am running as Session 0. I've learned that I can use two WMI calls to determine this:
- GetCurrentProcessID()
- ProcessIdToSessionId()
However, I have no clue how to call these things in VBS开发者_运维知识库cript. And ideas?
Set oShell = CreateObject("WScript.Shell")
connection = oShell.ExpandEnvironmentStrings("%SESSIONNAME%")
WScript.Echo connection
"Console" = local machine
"RDP-Tcp#0" = Remote Desktop (0 can be any number)
Here's a much easier solution:
Set oShell = CreateObject( "WScript.Shell" )
sessionName=oShell.ExpandEnvironmentStrings("%SESSIONNAME%")
if ( sessionName = "Console" ) then
Msgbox "You are running directly!"
else
MsgBox "You are in a Remote Session!"
end if
精彩评论