Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LogonScript is NOT adding Multiple Netprinters-setting a Default print

Status
Not open for further replies.

TimITFO

MIS
Aug 6, 2008
31
0
0
US
Hi Mark,

Your VBscript is great it's doing almost of everything I WANTED. I've been searching for two months on the web for a clean VB SCRIPT and I found so many but non worked...until I found yours.
Now, I need to do the following......

1. Assign network printers based on group membership
2. Install multiple backup network printers for each group
3. Assign default printers for each group

Also I like yours ADD ON GREETINGS MSG BOX... is it possible to put more than one vbscript in netlogon share or everything has to be in only one script?

Thanks for saving my job!




'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'
'==========================================================================


ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\Server /set /y"

'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "F:"

'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i)
Next

'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300

'Map drives needed by all
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
WSHNetwork.MapNetworkDrive "X:", "\\server\executables",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
'In this example below, ADMIN and WORKERB are groups.
Case "Admin"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
Case "WorkerB"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",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 "\\Server\HP5si"


' This section of script will prevent the baloon 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"

'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
 
The script doesn't block access to DOS applications or any other applications. More than likely it is an environment thing. Verify the path to your application. More than likely the drive letter it uses is getting deleted and needs to be remapped.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 

Mark,

It uses drive M: and even though the script deletes the drive it's remapped when a user logs in.
Is there a way to prevent the script from deleting this particular drive if found and map it if not found??

 
Tim you need to decide on what you want the script to do. The FAQ gives examples on how to remove a specific drive mapping and gives another example of how to remove all drive mappings.

Decide on what method you want to use and use that portion of the code.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 


I want take a minute to thank you for all hard work and knowledge that you've freely given to millions around the world. You make us look good! Thanks again and don't stop giving others what you have. It's good to give.
I just ordered the(Admin Script Pack) book and I didn't need to convience my boss to pay for it. The scrpt sold itself. Thanks!
I'm starting a new post --on How to export users from AD to a spread sheet using a vb script. I hope you get a chance to see it.
 
Thanks Tim, have not seen the order hit my site yet but will look out for it. Glad you have found the script useful.

Regards,

Mark
 

Hi Mark,

I'm trying to CONVERT a batch file script to a VB SCRIPT and I'm a little lost....

Here is the BATCH FILE SCRIPT.

NET USE K: \\Z02APIMCF02\CRISTEST Password1 /User:dc1\CAD

Try to help me on this please.

Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top