VPN Logonscript for domains
This article is meant for domain admins, and IT people looking for a method to have a VPN client invoke an end users log on script after they log on to the VPN.. If this is not you, then I’m not sure it will help.
Anyway. Since I could remember, VPN users have had the problem of hunting down their log on script and running it to map their drives, and whatever else needs to be done after logging on to the VPN. This is because if you log on to your computer from home, and you are not on the network, then your log on scripts wont run. Boo Hoo. I ran into the same issue, and decided to do something about it. I came up with some code snippets, added my own, tweaked it, polished it and created a VBS script (visual basic script, or VBScript) that will run the log on script after a user logs onto the VPN. This, however is not ordinary script. After it logs on to the VPN, it waits for 20 seconds, pings a server on your intranet (you have to set the IP) and if it can ping the server, it runs the script. If it CANT ping the server, it waits about 20 seconds and tries again. It does this 5 times, and after the 5th time, it stops and gives up.
The reason for the waiting and the Pinging is, if you are using the Cisco systems VPN Client, and choose Options > Application launcher, it launches that application as soon as you click Connect… However, after you hit connect, you are sometimes brought up to a username and password prompt, and sometimes have to agree to terms before connecting to the network. This takes more than 1 millisecond, to I thought 20 would do. You would have to take this script, save it in a file, and call it vpn.vbs (or whatever name you want to choose as long as it ends in .vbs) and place it in your VPN application launcher as shown above.
The only thing you have to specify in this script is the IP address to ping, and make sure it is in your INTRANET not the INTERNET.. because this is how the script knows the connection was successful. Line 5 in the script is where you should change the IP. This script will detect each users log on script, logon server etc…
Oh.. and one more thing…
GET PERMISSION FROM YOUR HELPDESK OR NETWORK ADMIN BEFORE USING THIS IF YOU ARE NOT ON THE HELPDESK, OR A NETWORK ADMIN ALREADY!!!
Ok… so on with the script:
Dim strHost,tries
wscript.sleep 10000
call main 'Script used from ForumUniversal.com
function main ' Enjoy
strHost = "10.11.1.110"
if Ping(strHost) = True then
call runlogonscript
Else
tries = tries + 1
call waitasec
end if
end function
Function Ping(strHost)
dim objPing, objRetStatus
set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strHost & "'")
for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
else
Ping = True
end if
next
End Function
function runlogonscript
strComputer = "."
Dim objNet,runme,x
Set objNet = CreateObject("WScript.NetWork")
strUserName = objNet.UserDomain & "\" & objNet.UserName
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objShell = CreateObject("Wscript.Shell")
Set objEnv = objShell.Environment("process")
strServer = objEnv("LOGONSERVER")
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
Set objTranslator = CreateObject("NameTranslate")
objTranslator.Init ADS_NAME_INITTYPE_GC, ""
objTranslator.Set ADS_NAME_TYPE_NT4, strUserName
strUserDN = objTranslator.Get(ADS_NAME_TYPE_1779)
Set objItem = GetObject("LDAP://" & strUserDN)
strscriptPath = objItem.Get("scriptPath")
Dim LogonScript
LogonScript = strServer & "\netlogon\" & strscriptPath
x = ("rundll32 url.dll,FileProtocolHandler " & LogonScript)
WshShell.run x
call goodquits
end function
function waitasec
if tries = 5 then
call quits
else
wscript.sleep 20
wscript.sleep 10000
call main
end if
end function
function quits
end function
Function goodquits
end function