Batch to VBScript for Logon

I am interested in using vbscript for my logon script in my domain instead of batch. Currently, I have four sites and in my current batch file logon script, there is a " CALL %LOGONSERVER%.bat" command in the script which will map drives specific to that location for office workers who travel all of the offices. The name f each logon script is "DomainControllerName".bat. How do I accomplish this in a vbscript?
TrihimbulusAsked:
Who is Participating?
 
RobSampsonConnect With a Mentor Commented:
BDF is right....you can use something like the below that has each script integrated...

That probably makes things easier with everything in the one place....

Rob.
Set objShell = CreateObject("WScript.Shell")
strLogonServer = objShell.ExpandEnvironmentStrings("%LOGONSERVER%")
Select Case strLogonServer
    Case "Server1"
        Server1_Script
    Case "Server2"
        Server2_Script
End Select
 
Sub Server1_Script
   ' Do stuff here for Server1 logons
End Sub
 
Sub Server2_Script
   ' Do stuff here for Server2 logons
End Sub

Open in new window

0
 
RobSampsonCommented:
Hi there. In VBScript, you can use:

Set objShell = CreateObject("WScript.Shell")
strLogonServer = objShell.ExpandEnvironmentStrings("%LOGONSERVER%")
objShell.Run strLogonServer & ".bat"

Regards,

Rob.
0
 
David LeeCommented:
Hi, Trihimbulus.

Something like this will get the job done.
Set objShell = CreateObject("WScript.Shell")
strLogonServer = objShell.ExpandEnvironmentStrings("%LOGONSERVER%")
Select Case strLogonServer
    Case "Server1"
        'Commands for logins using server1'
    Case "Server2"
        'Commands for logins using server2'
End Select

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
David LeeCommented:
Rob types faster than I do.  :-(
0
 
RobSampsonCommented:
:-)  Well you've just shown that you could go a step further and not even call the batch file, but re-write it in VBS.....that's another option for Trihimbulus, and by the sounds of it, the ultimate goal anyway....

Regards,

Rob.
0
 
TrihimbulusAuthor Commented:
Thanks all! Each login script will be site specific and I would prefer not to have a universal script for all offices. Yes, my end goal is to go from using a batch file to vb script.

Quick question Rob, where you have:

objShell.Run strLogonServer & ".bat"

should .bat be .vbs, since there will no longer be a logonserver.bat? Also, I suspect I will need to name each logon script, "logon-server".vbs (submit logon-server for actual name of server).
0
 
RobSampsonCommented:
Yes, that's right. If you're going to re-write your batch scripts into VBS files, but keep seperate VBS files, you will need to create <logonserver>.vbs files in place of those batch files.

However, you will then need to change
objShell.Run strLogonServer & ".bat"

to this
objShell.Run "wscript.exe " & Replace(WScript.ScriptFullName, WScript.ScriptName, "") & strLogonServer & ".vbs", 1, True

so that it forces wscript.exe (the scripting engine) to run the vbs file.  The
Replace(WScript.ScriptFullName, WScript.ScriptName, "")
part just evaluates to the current directory where the first script is being run from....

Regards,

Rob.
0
 
David LeeCommented:
I'm curious.  Why have different script files for different offices instead of one script file that can handle them all?
0
 
David LeeCommented:
Exactly.  There's simply no value in having separate files and having to shell out to run them.  
0
 
TrihimbulusAuthor Commented:
Thanks!
0
All Courses

From novice to tech pro — start learning today.