Login | |
|
 |
Logon script won't work as non-admin Please help! - 6/22/2007 12:45:36 PM
|
|
 |
|
| |
ben20vt
Posts: 4
Score: 0
Joined: 6/22/2007
Status: offline
|
Hello all, I recently inherited a 40 user network which is in a right mess! I want to automate network shares and printers and I've come up with the following script. Problem is I cant get it to work as non-admin user. Fails at Set WshNetwork = WScript.CreateObject("WScript.Network") just can't understand why? I'm new to VB so please don't judge my script to harshly. Any advice would be greatly appriciated. please find below. thanks. 'Main Office script '------------------------------------------------------------------------------- ' Define Variables and Objects '------------------------------------------------------------------------------- Const strDomain = "domain.com" Const UseLogonScreen = "yes" Const LogPath = "\\domain.com\NetLogon" Dim OS Dim Gateway Dim IPAddress Dim SubnetMask Dim WshNetwork Dim WshShell Dim WshSysEnv Dim FileSysObj Dim FileObject Set WshNetwork = WScript.CreateObject("WScript.Network") Set WshShell = WScript.CreateObject("WScript.Shell") Set WshSysEnv = WshShell.Environment("Process") ' Get the User Name '------------------------------------------------------------------------------- Dim strUserID Dim strWorkstation Do On Error Resume Next strUserID = UCASE(WshNetwork.UserName) strWorkstation = UCASE(WshNetWork.ComputerName) Loop Until strUserID <> "" ' Get the Group Memberships '------------------------------------------------------------------------------- Dim UserObj Dim GroupObj Dim UserGroups Set UserObj = GetObject("WinNT://" & strDomain & "/" & strUserID) For Each GroupObj In UserObj.Groups UserGroups=UCASE(UserGroups & "[" & GroupObj.Name & "]") Next ' ****************************************** ' *** Remove current Network Connections *** ' ****************************************** Dim oDrives Set oDrives = WshNetwork.EnumNetworkDrives IF oDrives.Count > 1 Then ' WScript.Echo "REMOVING NETWORK DRIVES" For i = 0 To oDrives.Count -1 Step 2 WshNetwork.RemoveNetworkDrive oDrives(i) Next End If '------------------------------------------------------------------------------- 'Removes network printers, leaves local printers and special printers '------------------------------------------------------------------------------- Dim oPrinters Dim DefaultPrinter, DefaultPrinterName Dim bDefaultSet Dim key Set WshNetwork = WScript.CreateObject("WScript.Network") Set oPrinters = WshNetwork.EnumPrinterConnections 'Just incase their are no printers and therefore no default printer set 'this will prevent the script from erroring out. On Error Resume Next key = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device" DefaultPrinter = LCase(WshShell.RegRead (key)) 'Analyse the printers to find the default printer If Err.Number <> 0 Then DefaultPrinterName = "" else If ((InStr(DefaultPrinter, "LPT1") > 0) Or (InStr(DefaultPrinter, "Acrobat") = 0) ) Or (InStr(DefaultPrinter, "Print2PDF") > 0) Or (InStr(DefaultPrinter, "USB") > 0) Then ' If (InStr(DefaultPrinter , "IP_") = 0) AND (InStr(DefaultPrinter , "\\") = 0) Then bDefaultSet = true ' Default printer was a local printer else bDefaultSet = False ' Default printer was a network printer end if end if 'Now remove all the network printers If oPrinters.Count > 1 Then For i = 0 To oPrinters.Count -1 Step 2 If (InStr(oPrinters(i), "IP_") = 1) AND (InStr(oPrinters(i+1), "\\") = 1) Then WshNetwork.RemovePrinterConnection oPrinters(i+1), True End If Next End If '------------------------------------------------------------------------------- ' Map Department Network Drives '------------------------------------------------------------------------------- If InGroup("ADMIN") Then MapDrive "L:","\\SBSERVER\Shares\LLC" MapDrive "J:"," \\SBSERVER\Shares\Admin" End If If InGroup("QUICKBOOKS") Then MapDrive "Q:","\\SBSERVER\Shares\Quickbooks" End If If InGroup("RAFFLES") Then MapDrive "R:","\\SBSERVER\Shares\Raffles" End If If InGroup("RAFFLESADMIN") Then MapDrive "P:","\\SBSERVER\Shares\RafflesAdmin" End If If InGroup("LL_C") Then MapDrive "L:","\\SBSERVER\Shares\LLC" End If If InGroup("PAY_ROLL") Then MapDrive "K:","\\SBSERVER\Shares\Payroll" End If If InGroup("FINANCIALS") Then MapDrive "T:","\\SBSERVER\Shares\Financials" End If ' Map Location Based Print Resources '------------------------------------------------------------------------------- If InGroup("DOWNSTAIRS") Then WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\ColourLaser" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\ColourLaser_PS" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\DownstairsMain" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\MainCopier" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\MainCopier_PS" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\Drafting1" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\UpstairsFAX" ' If bDefaultSet = False Then WshNetwork.SetDefaultPrinter "\\SBSERVER\DownstairsMain" ' End If End If If InGroup("UPSTAIRS") Then WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\ColourLaser" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\ColourLaser_PS" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\DownstairsMain" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\MainCopier" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\MainCopier_PS" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\Drafting1" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\UpstairsFAX" ' If bDefaultSet = False Then WshNetwork.SetDefaultPrinter "\\SBSERVER\MainCopier" ' End If End If ' Map User Specific Network Resources '------------------------------------------------------------------------------- If strUserID = "KYLE" Then MapDrive "W:","\\SBSERVER\Web" End If If strUserID = "JIM" Then ' WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions\MaxAllowedZone","1" WshNetwork.AddWindowsPrinterConnection "\\Purchasing01\HPLaserJ" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\ColourLaser" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\ColourLaser_PS" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\DownstairsMain" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\MainCopier" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\MainCopier_PS" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\Drafting1" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\UpstairsFAX" WshNetwork.SetDefaultPrinter "\\Purchasing01\HPLaserJ" End If If strUserID = "JOE" Then ' WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions\MaxAllowedZone","1" WshNetwork.AddWindowsPrinterConnection "\\cabinet\brothermfd" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\ColourLaser" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\ColourLaser_PS" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\DownstairsMain" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\MainCopier" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\MainCopier_PS" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\Drafting1" WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\UpstairsFAX" WshNetwork.SetDefaultPrinter "\\cabinet\brothermfd" End If 'If (strUserID = "JIM") AND (strWorkstation = "PURCHASING01") Then ' WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions\MaxAllowedZone","1" ' WshNetwork.AddWindowsPrinterConnection "\\Purchasing01\HPLaserJ" ' WshNetwork.SetDefaultPrinter "\\Purchasing01\HPLaserJ" 'End If ' Map Common Network Drives with drive labelling '------------------------------------------------------------------------------- MapDrive "N:","\\SBSERVER\Shares" mDrive = "N:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Data" MapDrive "G:","\\TSERVER\Databuild" mDrive = "G:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Databuild" mDrive = "J:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Admin" mDrive = "K:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Payroll" mDrive = "L:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "LLC" mDrive = "P:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Raffles Admin" mDrive = "Q:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Quickbooks" mDrive = "R:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Raffles" MapDrive "S:","\\SBSERVER\Shares\Shared" mDrive = "S:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Software" mDrive = "H:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Home" mDrive = "T:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Financials" MapDrive "U:","\\SBSERVER\Shares\Temp" mDrive = "U:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "Temporary Files" ' Map Common Network Print Devices '------------------------------------------------------------------------------- ' Upstairs Magicolor 3300 PostScript WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\ColourLaser" ' Downstairs Brother MFC-8840D WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\DownstairsMain" ' Xerox Copier 235 PCL Driver WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\MainCopier" ' FX DocuWide 2050 Plotter WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\Drafting1" ' FX FAX WshNetwork.AddWindowsPrinterConnection "\\SBSERVER\UpstairsFAX" ' Function InGroup '------------------------------------------------------------------------------- Function InGroup(strGroup) InGroup = False If InStr(UserGroups,"[" & strGroup & "]") Then InGroup=True End If End Function ' Sub Disconnects Network Drives '------------------------------------------------------------------------------- Sub KillDrive(strDrive) On Error Resume Next If FileSysObj.DriveExists(strDrive) = True Then WshNetwork.RemoveNetworkDrive strDrive End If End Sub ' Sub Drive Mapping Routine '------------------------------------------------------------------------------- Sub MapDrive(strDrive, strShare) On Error Resume Next WshNetwork.MapNetworkDrive strDrive, strShare, 0 End Sub
|
|
| |
|
|
|
 |
RE: Logon script won't work as non-admin Please help! - 6/22/2007 2:45:56 PM
|
|
 |
|
| |
dm_4ever
Posts: 2635
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
What error are you getting? This loop is unnecessary Do On Error Resume Next ' Remove this line until you are done troubleshooting strUserID = UCASE(WshNetwork.UserName) strWorkstation = UCASE(WshNetWork.ComputerName) Loop Until strUserID <> ""
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Logon script won't work as non-admin Please help! - 6/23/2007 3:08:34 AM
|
|
 |
|
| |
dm_4ever
Posts: 2635
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
Fantastic!....one more things....you only need to create Shell.Applicaiton once and use it as many times as you need. Set oShell = CreateObject("Shell.Application")
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Logon script won't work as non-admin Please help! - 6/24/2007 3:03:12 PM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1181
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
Whoa. This is the first I ever heard of oShellApp.NameSpace(vDrive).Self.Name = "Name"! That kicks a$$! Thanks, ben20vt, I', already incorporating that into my mapdrives functions.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
|
|