bjv211
asked on
Check for remote desktop connection in VBscript
I currently have a logon.vbs that sends users to our intranet on logon. However, I want to not send them there if they are connecting through remote desktop. Is there a way to figure out if they are connecting through remote desktop and not do the following script?
MY CURRENT logon.vbs:
Set WshShell = CreateObject("WScript.Shel l")
strUserName = WshShell.ExpandEnvironment Strings("% username%" )
IF StrComp(strUserName,"EXEMP TUSER") = 0 Then
ELSE
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
ReturnCode = WshShell.Run("iexplore http://WEBSITE.com", 1, True)
END IF
MY CURRENT logon.vbs:
Set WshShell = CreateObject("WScript.Shel
strUserName = WshShell.ExpandEnvironment
IF StrComp(strUserName,"EXEMP
ELSE
Set WshShell = WScript.CreateObject("WScr
ReturnCode = WshShell.Run("iexplore http://WEBSITE.com", 1, True)
END IF
ASKER
TM, will this work even if the client is remote desktop connection to their individual workstation?
The script, if attached to a user logon, will run, no matter where they log on to. If they RDP to a Terminal Server, the script will run. When it's run, the script will show that it's running on the server, not on the users' local workstation. So if you put in some code that checks the computer name, and run if the computer name does NOT begin with "SRV", then it won't run the intranet page.
If you want an example of code: This script will find the ComputerName of where the user is logging on to and will only run the intranet kickoff if the computer name does not begin with "SRV" or "SERVER":
Set wshNetwork = CreateObject("WScript.Netw ork")
Set ADSysInfo = CreateObject("ADSystemInfo ")
Set objComputer = GetObject("LDAP://" & ADSysInfo.ComputerName)
StrComputerName = objComputer.sAMAccountName
Set WshShell = CreateObject("WScript.Shel l")
strUserName = WshShell.ExpandEnvironment Strings("% username%" )
If UCase(Left(StrComputerName , 3)) = "SRV" Or UCase(Left(StrComputerName , 6)) = "SERVER" Then
'Do Nothing
Else
ReturnCode = WshShell.Run("iexplore http://WEBSITE.com", 1, True)
End If
-TM
If you want an example of code: This script will find the ComputerName of where the user is logging on to and will only run the intranet kickoff if the computer name does not begin with "SRV" or "SERVER":
Set wshNetwork = CreateObject("WScript.Netw
Set ADSysInfo = CreateObject("ADSystemInfo
Set objComputer = GetObject("LDAP://" & ADSysInfo.ComputerName)
StrComputerName = objComputer.sAMAccountName
Set WshShell = CreateObject("WScript.Shel
strUserName = WshShell.ExpandEnvironment
If UCase(Left(StrComputerName
'Do Nothing
Else
ReturnCode = WshShell.Run("iexplore http://WEBSITE.com", 1, True)
End If
-TM
ASKER
we are not running a 'terminal server' , each workstation is being directly connected to through terminal services, all our machines have external IPs
It doesn't matter...if the user is logging on to any computer via local logon or over RDP, this will work.
Ohhh...I see what you're saying.
Check the SessionName:
Set WshShell = CreateObject("WScript.Shel l")
strSessionName = WshShell.ExpandEnvironment Strings("% SessionNam e%")
If Ucase(strSessionName) = "CONSOLE" Then
' You're logged on locally
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
ReturnCode = WshShell.Run("iexplore http://WEBSITE.com", 1, True)
Else
'Do Nothing: You're logged in remotely via RDP
End If
-TM
Check the SessionName:
Set WshShell = CreateObject("WScript.Shel
strSessionName = WshShell.ExpandEnvironment
If Ucase(strSessionName) = "CONSOLE" Then
' You're logged on locally
Set WshShell = WScript.CreateObject("WScr
ReturnCode = WshShell.Run("iexplore http://WEBSITE.com", 1, True)
Else
'Do Nothing: You're logged in remotely via RDP
End If
-TM
ASKER
sweet and can you integrate my existing check for username
What are you checking for...a specific user, or group of users? What do you want to happen for these users?
-TM
-TM
ASKER
heres the logic...
IF RDP,
do nothing
ELSE
IF NOT 1 specfic user
GOTO SITE
ELSE
d nothing
END IF
END IF
IF RDP,
do nothing
ELSE
IF NOT 1 specfic user
GOTO SITE
ELSE
d nothing
END IF
END IF
ASKER
i'm not so good at the logic of VBS, but i hope you get the point
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The last script just does what you asked...doesn't check for a group in AD.
-TM
-TM
Geeze....I keep missing this:
Since you have already SET the WshShell variable, you only need it once at the beginning of the script, you can delete the second occurance of:
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
Since you have already SET the WshShell variable, you only need it once at the beginning of the script, you can delete the second occurance of:
Set WshShell = WScript.CreateObject("WScr
ASKER
Thanks for the AD tip, we cannot do that in our enterprise setup :)
List the IPAddresses for a computer:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfig
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress)
For i=LBound(IPConfig.IPAddres
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next
SCRIPT TO GET COMPUTER NAME:
Set wshNetwork = CreateObject("WScript.Netw
Set ADSysInfo = CreateObject("ADSystemInfo
Set objComputer = GetObject("LDAP://" & ADSysInfo.ComputerName)
WScript.Echo objComputer.sAMAccountName
-TM