Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Logon script won't work as non-admin Please help!

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,48646
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Logon script won't work as non-admin Please help!
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 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

 
 
Post #: 1
 
 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

(in reply to ben20vt)
 
 
Post #: 2
 
 RE: Logon script won't work as non-admin Please help! - 6/22/2007 3:54:35 PM   
  ben20vt

 

Posts: 4
Score: 0
Joined: 6/22/2007
Status: offline
Thanks for that,

The error is as follows, Thanks for your help mate!

Windows script host
Line: 23
Char: 1
Could not create object named "WScript.Network"
Code: 80070005
Source: WScript.CreateObject

Ben.

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Logon script won't work as non-admin Please help! - 6/22/2007 6:14:57 PM   
  dm_4ever


Posts: 2635
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Have you tried re-installing the newest version of WSH?

This thread is similar to the issue you reported and may offer other ideas: http://www.visualbasicscript.com/m_31697/tm.htm

_____________________________

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

(in reply to ben20vt)
 
 
Post #: 4
 
 RE: Logon script won't work as non-admin Please help! - 6/22/2007 10:48:51 PM   
  ben20vt

 

Posts: 4
Score: 0
Joined: 6/22/2007
Status: offline
Fantastic mate! I'v been stressing over that for ages. Never would have thought of a WSH re-install. Well done. Will be back and next time I will spend more time searching.

Ben.

(in reply to dm_4ever)
 
 
Post #: 5
 
 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

(in reply to ben20vt)
 
 
Post #: 6
 
 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

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: Logon script won't work as non-admin Please help! - 6/24/2007 5:55:28 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
You could get rid of all those nasty [oShellApp.NameSpace(vDrive).Self.Name = "Name"! ]
Just use an array



      

or dictionary


      

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 8
 
 RE: Logon script won't work as non-admin Please help! - 6/25/2007 10:36:22 AM   
  ben20vt

 

Posts: 4
Score: 0
Joined: 6/22/2007
Status: offline
Thanks dm_4ever your help is most appriciated!

Script is now running perfectly on users PC's and TS.

Ben.



(in reply to gdewrance)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Logon script won't work as non-admin Please help! Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts