Hi all - I was wondering if there is a way to set a timeout for adding printers / mapped drives in a vbs? The problem is the pcs with the printers aren't always on, and currently it sems the script never finishes. Is there a way to set the timeout? My logon script looks like this
_________________________________
Leozack
Code:
Dim WSHShell
Set WSHShell = CreateObject("Wscript.Shell")
'WSHShell.Run ("\\marksbury-srv\NETLOGON\ie7searchlist.bat")
WSHShell.Run ("regedit /s \\marksbury-srv\NETLOGON\ie7searchlist.reg")
'==========================================================================
'
' NAME: LogonScript.vbs
' FROM: [URL unfurl="true"]http://www.tek-tips.com/faqs.cfm?fid=5798[/URL]
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
' Maps and disconnects drives and printers
'
'==========================================================================
ON ERROR RESUME NEXT
Dim WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
'Grab the computer name
strComputer = WSHNetwork.ComputerName
'----------------------------------- Don't run anything below if this is the server -----------------------------------
If Not strComputer = "marksbury-srv" Then
'Synchronizes the time with our NTP Server
WSHShell.Run "NET TIME \\marksbury-srv /set /y"
'Disconnect any drive mappings as needed.
'WSHNetwork.RemoveNetworkDrive "F:", True, True
'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next
'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300
'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.
'WSHNetwork.MapNetworkDrive "H:", "\\server\users\" & UserString,True
WSHNetwork.MapNetworkDrive "P:", "\\marksbury-srv\Apps$",True
WSHNetwork.MapNetworkDrive "U:", "\\marksbury-srv\Students",True
'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
Case "Domain Admins"
WSHNetwork.MapNetworkDrive "I:", "\\marksbury-srv\ict$",True
WSHNetwork.MapNetworkDrive "N:", "\\marksbury-srv\NETLOGON",True
WSHNetwork.MapNetworkDrive "X:", "\\marksbury-srv\Setups$",True
WSHNetwork.MapNetworkDrive "Y:", "\\marksbury-srv\profiles$",True
WSHNetwork.MapNetworkDrive "Z:", "\\marksbury-srv\d$",True
Case "SimsUserGroup"
WSHNetwork.MapNetworkDrive "S:", "\\marksbury-srv\CP$",True
Case "AdminUserGroup"
WSHNetwork.MapNetworkDrive "O:", "\\marksbury-srv\OfficeDocs$",True
'Below is an example of how to set the default printer
WSHNetwork.SetDefaultPrinter "\\marksbury-srv\hpLJ1005"
Case "TeacherUserGroup"
WSHNetwork.MapNetworkDrive "S:", "\\marksbury-srv\TeachDocs$",True
End Select
Next
'Remove ALL old printers
'Enumerate all printers first, after that you can select the printers you want by performing some string checks
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'To remove only networked printers use this If Statement
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
End If
'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next
'Remove a specific printer
'WSHNetwork.RemovePrinterConnection "\\ServerOld\HP5si",True,True
'Install Printers
WSHNetwork.AddWindowsPrinterConnection "\\room1pc1\room1left"
WSHNetwork.AddWindowsPrinterConnection "\\room1pc3\room1right"
WSHNetwork.AddWindowsPrinterConnection "\\room2pc2\room2left"
WSHNetwork.AddWindowsPrinterConnection "\\room2pc3\room2right"
WSHNetwork.AddWindowsPrinterConnection "\\hut1\hutleft"
WSHNetwork.AddWindowsPrinterConnection "\\hut2\hutmiddle"
WSHNetwork.AddWindowsPrinterConnection "\\hut3\hutright"
WSHNetwork.AddWindowsPrinterConnection "\\grouproom\grouproom"
WSHNetwork.AddWindowsPrinterConnection "\\hallwhiteboard\hall"
'Set default printers based on user name (local room) then computer name (local printer)
Select Case UserString
Case "YearR"
WSHNetwork.SetDefaultPrinter "\\room2pc2\room2left"
Case "Year1"
WSHNetwork.SetDefaultPrinter "\\room2pc2\room2left"
Case "Year2"
WSHNetwork.SetDefaultPrinter "\\room1pc1\room1left"
Case "Year3"
WSHNetwork.SetDefaultPrinter "\\room1pc1\room1left"
Case "Year4"
WSHNetwork.SetDefaultPrinter "\\hut1\hutleft"
Case "Year5"
WSHNetwork.SetDefaultPrinter "\\hut1\hutleft"
Case "Year6"
WSHNetwork.SetDefaultPrinter "\\hut1\hutleft"
End Select
Select Case strComputer
Case "room1pc1"
WSHNetwork.SetDefaultPrinter "\\room1pc1\room1left"
Case "room1pc3"
WSHNetwork.SetDefaultPrinter "\\room1pc3\room1right"
Case "room2pc2"
WSHNetwork.SetDefaultPrinter "\\room2pc2\room2left"
Case "room2pc3"
WSHNetwork.SetDefaultPrinter "\\room2pc3\room2right"
Case "hut1"
WSHNetwork.SetDefaultPrinter "\\hut1\hutleft"
Case "hut2"
WSHNetwork.SetDefaultPrinter "\\hut2\hutmiddle"
Case "hut3"
WSHNetwork.SetDefaultPrinter "\\hut3\hutright"
Case "grouproom"
WSHNetwork.SetDefaultPrinter "\\grouproom\grouproom"
Case "hall"
WSHNetwork.SetDefaultPrinter "\\hallwhiteboard\hall"
Case "hallwhiteboard"
WSHNetwork.SetDefaultPrinter "\\hallwhiteboard\hall"
End Select
'Add On Code goes below this line
'=====================================
' This section of script will prevent the balloon window
' that appears when printing to a network shared printer
' after XP Service Pack 2 is installed.
'=====================================
Path = "HKCU\Printers\Settings\EnableBalloonNotificationsRemote"
WshShell.RegWrite Path, 0 ,"REG_DWORD"
'=====================================
'Add On Code goes above this line
'----------------------------------- Don't run anything above if this is the server -----------------------------------
End If
'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
'Quit the Script
wscript.quit
_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);