BAT vs VBS for Logon Script for Windows 7 Com

Hewlett-packard Ms windows server 2003 r...
January 27, 2011 at 10:24:57
Specs: Windows Vista, Quad Core / 2Gig
I have logon scripts for mapping drives and printers. I first used the NET USE in BATCH scripts to do this and it worked fine on XP machines but as we started getting Windows VISTA and Windows 7 the printers where not working right. So I made VBS scripts to do the work and it worked but once in a great while the drives would take a very long time to map through the VBS where they would work fine using BAT.

Is there something that would cause mapping of drives to be slow through VBS?

Here is my code if you need it:

Option Explicit
On Error Resume Next

' Initializes Vars
Dim objNetwork                  ' Creates Networking Object.
Dim strStartingDrive            ' Start all drives at this letter.
Dim strRemotePath(10)           ' Stores UNC paths.
Dim strDriveLetter(10)          ' Stores Drive Letters.
Dim strUserName                 ' Stores the Users Login Name. 
Dim intNoDrives                 ' Number of Drives. 
Dim intLoop                     ' Loop Var.
Dim strPort, strUNCPrinter, strPrnDrv

strStartingDrive    = ""        
strRemotePath(10)   = ""        
strDriveLetter(10)  = ""        
strUserName         = ""
strPort             = ""
strUNCPrinter       = ""
strPrnDrv           = ""
intNoDrives         = 0         
intLoop             = 0         

' Constructs Object to get login info. 
set objNetwork      = WScript.CreateObject("WScript.Network") 
strUserName         = objNetwork.UserName

' Setsup Drive Arrays 
strStartingDrive    = "H"
intNoDrives         = 9  

For intLoop = 0 to intNoDrives-1          
  strDriveLetter(intLoop) = chr(Asc(strStartingDrive) + intLoop) & ":"

' Map the Drives 
strRemotePath(0)    = "\\svr040\users\" & strUserName
strRemotePath(1)    = "\\svr040\share"
strRemotePath(2)    = "\\svr040\department\general"
strRemotePath(3)    = "\\svr040\department\OAM"
strRemotePath(5)    = "\\svr040\department\OMH"
strRemotePath(6)    = "\\svr040\department\OFM"
strRemotePath(7)    = "\\svr040\department\OCP"
strRemotePath(8)    = "\\svr040\archives"

' Create Drive letters 
For intLoop = 0 to intNoDrives-1 
  objNetwork.MapNetworkDrive strDriveLetter(intLoop), strRemotePath(intLoop)

'****** Ad-Hoc Drives ******
objNetwork.MapNetworkDrive "X:", "\\svr040\Backups\inactiveuserfiles"
objNetwork.MapNetworkDrive "Y:", "\\svr040\backups\userfiles"
objNetwork.MapNetworkDrive "Z:", "\\svr040\users"

' Add Printers

strPort = LPT2
strUNCPrinter = "\\\TOSHIBA Color Copier (Back)"

Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter
objNetwork.AddPrinterConnection strPort,strUNCPrinter


See More: BAT vs VBS for Logon Script for Windows 7 Com

Report •

January 28, 2011 at 07:31:48
Ok, after talking with our programmer, he seems to think the problem is that the run32dll has to load before it maps the drives. This is why they map right away when using NET USE but take time when doing it through VBS.

Is there a way I can force it to execute sooner. Using the VBS people keep calling me telling me their drives have not mapped and I have to tell them to wait.

Report •

January 28, 2011 at 11:56:23
I've had problems with McAfee and Symantec delaying execution of VBScripts for up to two minutes. You might want to run some tests, and see where the script hangs (if it is), or see what's holding up the scripting engine.

How To Ask Questions The Smart Way

Report •

January 28, 2011 at 12:48:33
Interesting, I am running Trend Micro but I never thought it could be the anti-virus.

Report •

Related Solutions

January 28, 2011 at 16:27:22
Ok, working off what you said (sorry I had to wait until every one was off) I found that the VBS would not run until the Anti-Virus loaded. Being it was the last TSR to load it took a long time to map the drive.

My solution was to make two files, one mapdrives.bat and another addprinters.vbs. Then I made a second GPO for the printers and added it to the Users OU. This way I did not have the problem of Windows security not allowing VBS from being called with in a BAT file kicking in. It work great. Granted the printers do not connect until the anti-virus runs but I don't care when they connect. Just need the drives right away.

Thanks for your help.

Report •

Ask Question