Windows Server - Running Login Script after establishing a VPN connection
Asked By TJCooper197
09-May-08 01:42 PM

I want to create a script the user can run that pulls his objuser.scriptpath
properties, and runs the login script specified.
Is there a way to simply restart the login process (the part that goes to
that location and runs the specified script)?
So far I have a script that get the correct field, but I dont know how to
run/launch a bat file using that information. Ive tried wscript.run and
wsshell.run, but they dont seem to work. Any suggestions?
Set oNet = Wscript.CreateObject("Wscript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & ADSysInfo.UserName &"")
Set WshShell = CreateObject("Scripting.FileSystemObject")
Wscript.echo "Script Path: \\domain.loc\netlogon\ou\"& objUser.ScriptPath
'wscript.run "\\domain.loc\netlogon\ou\"& objUser.ScriptPath
'wshshell.run "\\domain.loc\netlogon\ou\"& objUser.ScriptPath
Set oNet = Wscript.CreateObject("Wscript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & ADSysInfo.UserName &"")
Set WshShell = CreateObject("Scripting.FileSystemObject")
ADSysInfo.UserName
(1)
Scripting.FileSystemObject
(1)
Wscript.CreateObject
(1)
WScript.Shell
(1)
ObjNetwork.RemoveNetworkDrive
(1)
VB
(1)
ObjNetwork.MapNetworkDrive
(1)
Wscript.Network
(1)
TJCooper197 replied...
Well, I moved on and decided to map a network drive, run the bat file, then
disconnect the network drive.
Only one problem. The network drive disconnects before the bat file finishes
running.
What is the most gracefull way to fix this new issue (create a timer?)?
Set objNetwork = Wscript.CreateObject("Wscript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & ADSysInfo.UserName &"")
Set WshShell = WScript.CreateObject("WScript.Shell")
Wscript.echo "z:\"& objUser.ScriptPath
objNetwork.MapNetworkDrive "z:", "\\domainx.com\netlogon"
wshshell.run "z:\folder\login.bat"
objNetwork.RemoveNetworkDrive "z:"
---------------
Pegasus \(MVP\) replied...
Put the "net use z: /d" into "login.bat".
You could simplify things considerably if you used UNC coding
for your logon script. In this case you would not need to map
or unmap a share to drive Z:.
TJCooper197 replied...
We are using kixart in our login process. I cant really modify for the
login.bat file, because it would cause issues with people logging in normally.
I suppose I could call up the text file with the actuall mapped drives and
parse it for UNC paths. Put those UNC paths into an array and then map them.
Pegasus \(MVP\) replied...
What calls up your VB Script program? Do you have any
control over it? If so, turn it into a pure batch command!
This would be equivalent to your current VB Script program
but much simpler. It also avoids the timing issue.
Richard Mueller [MVP] replied...
You bind wshShell to "Scripting.FileSystemObject" instead of
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Al Dunbar replied...
Or, alternately:
The "true" will cause the .run to return only once the batch script has
completed.
/Al
TJCooper197 replied...
The login script is referenced in the user object login script field. That
calls a batch file with looks at a text file for map drives.
Is there a way to launch the same process that takes place when you log in?
TJCooper197 replied...
I dont know what you mean by a "pure batch command".
TJCooper197 replied...
Thanks!!!
It ALMOST works. It tries to disconnect the drive just a tad too soon.
TJCooper197 replied...
So I need to do?
Set Wscript.Shell = CreateObject("Scripting.FileSystemObject")
Pegasus \(MVP\) replied...
You previously wrote
and parse it for UNC paths. Put those UNC paths into an array and
then map them."
This sounded like a good idea to me - what's happened to it?
TJCooper197 replied...
I have to figure out how to parse the file correctly. I dont do a lot of
scripting, so everything is slow going for me. The file has a number of
mapped drives and commented lines. I can ignore commented lines and focus on
lines that start with a $. This is what I have to parse:
----------
;
; Windows NT and Windows For Workgroups Logon Script
;
$NameLine = "my region"
$HelpDesk = "555-555-5555"
$Drive1 = M:
$Name1 = "drivea"
$Dir1 = "\\server\mapm"
$Drive3 = W:
$Name3 = "driveb"
$Dir3 = "\\server\mapw"
;
; the following should reflect appropriate mapped drive for location
;
$Drive4 = H:
$Name4 = "drivec"
$Dir4 = "\\server\maph"
$Drive5 = P:
$Name5 = "drived"
$Dir5 = "\\server\mapp"
$Drive6 = k:
$Name6 = "drivee"
$Dir6 = "\\server\mapk"
--------------
Pegasus \(MVP\) replied...
Your reply is a little too vague to give you a precise
recipe but the following batch file may well do the job.
Here is what you need to do:
- Use copy & paste to copy the code into a batch file.
- Adjust Lines 03 and 04 to suit your own environment.
- Remove the line numbers.
- Test the batch file.
- When happy with the result, activate the batch file by
removing the word "echo" on Line 09.
01. @echo off
02. setlocal enabledelayedexpansion
03. set ShareName=$Dir6
04. set ShareList=c:\Shares.txt
05.
06. for /F "tokens=1,2 delims==" %%a in ('type %ShareList%') do (
07. set Share=%%a
08. set Share=!Share: =!
09. if /i !Share!==%ShareName% echo call %%b\netlogon.bat
10. )
Feel free to ask if you want to know how and why the code works.
Al Dunbar replied...
Wait a minute, the script shown is a kixtart script. Instead of writing a
script in another language, whether batch or vbscript, why not just get
kixtart to run the script?
/Al
Pegasus \(MVP\) replied...
Indeed, but then I'm by now hopelessly confused about the roles
of the various kixtart/batch/VB Script scripts and which ones
the OP can modify. I'm thinking of withdrawing altogether - if
your understanding is better than mine, would you care to take
over?
Al Dunbar replied...
No, you are doing a fine job.
/Al
TJCooper197 replied...
I dont know how. The kixtart script is launched via a batch file in their
profile (login script field). I cannot seem to recreate that process.
I dont know how to launch that batch file from a script. I tried it and it
didnt seem to work. How do I launch a bat file that resides in the netlogon
folder from a vbs script?
Below is the .bat file that pulls the map drives from the previous posted
txt file.
----------
TJCooper197 replied...
Got it..im an idiot!!!!!
This works just fine!!
Set objNetwork = Wscript.CreateObject("Wscript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & ADSysInfo.UserName &"")
Set WshShell = WScript.CreateObject("WScript.Shell")
wshshell.run "\\domain\netlogon\region\bat.bat"
Now I just have to create the correct path from info pulled in the user
account object
Thank you all for putting up with my obvious newbieness!!

name on command line has maximum length of 28 characters / / = = = = = = = = = = = = = = = = = = = = = = = = = = = [ Variables ] = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = var fso = new ActiveXObject("Scripting.FileSystemObject"); var FileHandle, ExitStatus = 0, BackupStatus = 0; var ForReading = 1, ForWriting = 2, ForAppending = 8; var EmailBody is enabled", LogHandle); IoXMLDataRaw("close", "Tape_Drives", LogHandle, ""); } return(tape0); } function GetTempPath(os) { var wsh; wsh = WScript.CreateObject("WScript.Shell").environment; return(wsh("TEMP")); } / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = / / JScript Library module: email functions / / Author: David Hewison / / Version: 2007.02 var ExitCode, LogF = 0x2; if (FsLogFlag(LogF)) IoLogEvent("open", LogHandle, "FsCheckFileExists"); var fso = new ActiveXObject("Scripting.FileSystemObject"); ExitCode = fso.FileExists(FileName) if (FsLogFlag(LogF)) { if (ExitCode) IoLogEvent("content", LogHandle, FileName +" does exist
Dim FileName, OutputName, Marker, CRLF, p Dim oFSO, oArgs, Input, InputStream, objOutFile Set oFSO = CreateObject("Scripting.FileSystemObject") Set oArgs = WScript.Arguments Marker = Chr(183) CRLF = Chr(13) & Chr(10) FileName = objArgs(0 Help, objFSO, objArgs· Set obj FSO = CreateObject("Scripting.FileSystem Object")· Set ObjWshShell = WScript.Crea teObject("WScript.Shell")· · Help = "RDi r Version 1.4 by Pegasus. 30.10.2007" & NL & NL & _· "Thi iSize, iFiles, elements· · Set objFS O = CreateObject("Scripting.FileSystemOb ject")· Set ObjWshShell = WScript.Create Object("WScript.Shell")·· NoFileOutput = False· index = 0· TotalF = 0· TotalS = 0·· 'Sort the temporary file· cmd = "%c omspec% 10) AccessDenied = False main() ' = = = = = = = = = = = = = = 'Main module ' = = = = = = = = = = = = = = Sub main Dim Help, objFSO, objArgs Set objFSO = CreateObject("Scripting.FileSystemObject") Set ObjWshShell = WScript.CreateObject("WScript.Shell") Help = "RDir Version 1.4 by Pegasus.30.10
Excel. Hope this helps, J Wolfgang Goerlich '- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - = - -- -- - Set oADInfo = 3D CreateObject("ADSystemInfo") Set oFso = 3D WScript.CreateObject("Scripting.Filesystemobject") Set oShell = 3D WScript.CreateObject("Wscript.Shell") LogPath = 3D oShell.SpecialFolders("MyDocuments") + " \ Privileged Local User Audit.txt" AdsiPath = 3D "WinNT: / / " + oADInfo.DomainShortName