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
 
just so its known, simple reg commands via cmd can also be used for this purpose very simply....

-Brandon Wilson
MCSE:Security00/03
MCSA:Messaging00
MCSA:Security03
A+

 

Hi ADGod,

that didn't solve my problem. Otherwise, if I knew how to then I won't have posted the question. I'm hoping for Mark D or somebody else with a how to answer.
Thanks,
 
i am talking specifically to what you stated needs added, which can be done easily. you should not be so quick to accept help from only one person with so many people who know what theyre doing from experience on here.
now to the issue...my point is that you can call the shell in your script and use the reg commands to simplify the process...

for removals..
reg delete "HKCU\Printers\Connections\,,DALVCI3,ah8100b" /f

for additions and set as default...
reg add "HKCU\Printers\Connections\,,DALNAS01,ah8100b" /v Server /t REG_SZ /d \\DALNAS01
reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows" /v Device /t REG_SZ /d \\DALNAS01\AH8100B,winspool,Ne07:
reg delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts" /v \\DALNAS01\AH8100B /f



if you enumerate groups and use the shell to do set the values (or delete values), you can cut the script into a simpler model. trackin?

-Brandon Wilson
MCSE:Security00/03
MCSA:Messaging00
MCSA:Security03
A+

 

ADGod:

I don't want to edit the Reg...I was thinking of a vbscript to do it incase I make any mistake. VBscript will do me a lot of good
 
I don't want to edit the Reg
Playing with printers OBVIOUSLY change the registry ...
 
PHV is exactly right

ANY scripting solution merely makes alterations of the registry for changes like this. Doing vbscript to a great extent here is unnecessary, and quite frankly, a huge waste of time if you need a quick and solid solution.

-Brandon Wilson
MCSE:Security00/03
MCSA:Messaging00
MCSA:Security03
A+

 
Wow, you guys are really busting his stones. Tim is posting in the vbscript forum to get a vbscript solution.

Sorry I've not been able to devote the time I like to in the forums lately Tim, been tied up with Microsoft EBS at work.


Tim your three criteria all seem to be really the same to me, so maybe I don't fully understand what you are asking, but if I do then what you ask is really simple to add to the script. You need to do a little cleanup of the script based on your needs.

Within the group section, just add multiple printer lines. Here is an example that maps a drive and installs 3 printers for the ACCOUNTING group with the first printer then being set as the default:


Code:
For Each GroupObj In UserObj.Groups
    Select Case GroupObj.Name
    'Check for group memberships and take needed action
        Case "ACCOUNTING"
              WSHNetwork.MapNetworkDrive "q:", "\\Server\Quickbooks",True
              WSHNetwork.AddWindowsPrinterConnection "\\Server\AcctP1"
              WSHNetwork.SetDefaultPrinter "\\Server\AcctP1"
              WSHNetwork.AddWindowsPrinterConnection "\\Server\AcctP2"
              WSHNetwork.AddWindowsPrinterConnection "\\Server\AcctP3"

 
    End Select
Next

Now as for your question about the netlogon directory, I suggest you not use it. Put the script in a GPO as directed at the bottom of the FAQ. Set security in the GPO as needed. You can add as many scripts as you want to the the GPO. You can minimize the GPO size by removing all Administrative Templates from the GPO provided the GPO is just for login scripts.

Refer to my GPO FAQ for details: faq329-6116.

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 you're the man!!!!!!!!!
I was hoping you see my post and add your input. I'm testing your script and make necessary changes. I'm getting my hands on vbscript and I'm getting better every day. I'll post the results. Please keep your eye on this board man!
 
Hi MarkD<
I tested your script and got an error, I forgot to copy but I hope but looking at this script you might find where i messed up> I don't realy know where I messed up. Please have a look at it.



'==========================================================================
'
' 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 \\dcimcf01 /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

'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 "ADMIN"
WSHNetwork.MapNetworkDrive "r:", "\\mcf01\SCAN",True
WSHNetwork.MapNetworkDrive "m:", "\\mcf01\cristest",True
WSHNetwork.MapNetworkDrive "p:", "\\mcf01\common",True
WSHNetwork.MapNetworkDrive "u:", "\\mcf01\PUBLIC",True
WSHNetwork.AddWindowsPrinterConnection "\\mcf01\Hp ljet4050"
WSHNetwork.SetDefaultPrinter "\\mcf01\Hp ljet4050"
WSHNetwork.AddWindowsPrinterConnection "\\mcf01\XEROX_3035"

'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 "ACCOUNTING"
WSHNetwork.MapNetworkDrive "U:", "\\mcf01\PUBLIC",True
WSHNetwork.MapNetworkDrive "m:", "\\mcf01\cristest",True
WSHNetwork.MapNetworkDrive "p:", "\\mcf01\common",True
WSHNetwork.AddWindowsPrinterConnection "\\mcf01\Hp ljet3035"
WSHNetwork.SetDefaultPrinter "\\mcf01\Hp ljet3035"
WSHNetwork.AddWindowsPrinterConnection "\\mcf01\XEROX_3035"

End Select

'=====================================
Dim tempiepath
tempiepath = "HKCU\Software\Microsoft\Windows\"

WSHShell.RegWrite tempiepath & "ShellNoRoam\MUICache\@inetcplc.dll,-4750","Empty Temporary Internet Files folder when browser is closed","REG_SZ"

WSHShell.RegWrite tempiepath & "CurrentVersion\Internet Settings\Cache\Persistent","0","REG_DWORD"
Set tempiepath = nothing

'=====================================
HKEY_CURRENT_USER = &H80000001
strComputer = WSHNetwork.Computername
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Control Panel\Desktop"
objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
ValueName = "PaintDesktopVersion"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue

'=======================================================
' Determine the appropriate greeting for the time of day.
'=======================================================
Dim HourNow, Greeting
HourNow = Hour(Now)
If HourNow >5 And HourNow <12 Then
Greeting = "Good Morning "
Elseif HourNow =>12 And HourNow <16 Then
Greeting = "Good Afternoon "
Else
Greeting = "Good Evening "
End If
'=======================================================
'Find the Users Name

Dim GreetName
GreetName = SearchGivenName(objDomain,UserString)

' Use the Microsoft Speach API (SAPI)
'=====================================
Dim oVo
Set oVo = Wscript.CreateObject("SAPI.SpVoice")
oVo.speak Greeting & GreetName

'Modify This Function To Change Name Format
Public Function SearchGivenName(oRootDSE, ByVal vSAN)
' Function: SearchGivenName
' Description: Searches the Given Name for a given SamAccountName
' Parameters: RootDSE, ByVal vSAN - The SamAccountName to search
' Returns: First, Last or Full Name
Dim oConnection, oCommand, oRecordSet

Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
">;(&(objectCategory=User)(samAccountName=" & vSAN & "));givenName,sn,name;subtree"
Set oRecordSet = oCommand.Execute
On Error Resume Next
'Decide which name format to return and uncomment out
'that line. Default is first name.
'Return First Name
SearchGivenName = oRecordSet.Fields("givenName")
'Return Last Name
'SearchGivenName = oRecordSet.Fields("sn")
'Return First and Last Name
'SearchGivenName = oRecordSet.Fields("name")
On Error GoTo 0
oConnection.Close
Set oRecordSet = Nothing
Set oCommand = Nothing
Set oConnection = Nothing
Set oRootDSE = Nothing
End Function





Next

'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
 
got an error, I forgot to copy
So, simply rerun the script and post the whole error message.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I'm with PHV, re-run and post the error which should tell you where the problem is.

Off the top of my head I don't like this share name that has the space in it: "\\mcf01\Hp ljet3035"

You would need to test if the space causes errors or rename the share to not have a space.

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.
 
Hi Mark and PHV,

I made the changes you recommended and copied the script on the Lab server. One thing to keep in mind is that ......I can ONLY run the script on the OU level and not the GPO level. Each company manages it's own OU and the enterprise group manages everything else...that by any means is not the reason why the script is not running...
Here is the error msg:

Line: 58
Char: 20
Error: Invalid 'for' loop control variable
Code: 800A0410
Source: MS VBscript Compilation error

Waiting for your input or suggestion.
Thanks.
 
Replace this:
Code:
'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 "ADMIN"
              WSHNetwork.MapNetworkDrive "r:", "\\mcf01\SCAN",True
          WSHNetwork.MapNetworkDrive "m:", "\\mcf01\cristest",True
          WSHNetwork.MapNetworkDrive "p:", "\\mcf01\common",True
          WSHNetwork.MapNetworkDrive "u:", "\\mcf01\PUBLIC",True
              WSHNetwork.AddWindowsPrinterConnection "\\mcf01\Hp ljet4050"
              WSHNetwork.SetDefaultPrinter "\\mcf01\Hp ljet4050"
              WSHNetwork.AddWindowsPrinterConnection "\\mcf01\XEROX_3035"
              
'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 "ACCOUNTING"
              WSHNetwork.MapNetworkDrive "U:", "\\mcf01\PUBLIC",True
          WSHNetwork.MapNetworkDrive "m:", "\\mcf01\cristest",True
          WSHNetwork.MapNetworkDrive "p:", "\\mcf01\common",True
              WSHNetwork.AddWindowsPrinterConnection "\\mcf01\Hp ljet3035"
              WSHNetwork.SetDefaultPrinter "\\mcf01\Hp ljet3035"
              WSHNetwork.AddWindowsPrinterConnection "\\mcf01\XEROX_3035"
              
End Select

With this:
Code:
'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
    Select Case UCase(GroupObj.Name)
'Check for group memberships and take needed action
        Case "ADMIN"
        	WSHNetwork.MapNetworkDrive "r:", "\\mcf01\SCAN",True
          	WSHNetwork.MapNetworkDrive "m:", "\\mcf01\cristest",True
          	WSHNetwork.MapNetworkDrive "p:", "\\mcf01\common",True
          	WSHNetwork.MapNetworkDrive "u:", "\\mcf01\PUBLIC",True
            WSHNetwork.AddWindowsPrinterConnection "\\mcf01\Hp ljet4050"
            WSHNetwork.SetDefaultPrinter "\\mcf01\Hp ljet4050"
            WSHNetwork.AddWindowsPrinterConnection "\\mcf01\XEROX_3035"
        Case "ACCOUNTING"
            WSHNetwork.MapNetworkDrive "U:", "\\mcf01\PUBLIC",True
	        WSHNetwork.MapNetworkDrive "m:", "\\mcf01\cristest",True
            WSHNetwork.MapNetworkDrive "p:", "\\mcf01\common",True
            WSHNetwork.AddWindowsPrinterConnection "\\mcf01\Hp ljet3035"
            WSHNetwork.SetDefaultPrinter "\\mcf01\Hp ljet3035"
            WSHNetwork.AddWindowsPrinterConnection "\\mcf01\XEROX_3035"
	End Select
Next

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.
 


Thanks Mark I'll test it and post the result.
Great help!
 
Hi Mark,

Just finished testing the script and I was jumping up and down when the script called for the (Good Morning) Greetings and also the service pack build showing on the system tray. I was able to logon for the first time without errors, but NO drives were mapped and NO printers were installed.....I guess celebrated too soon! At least we're at a good start, now question is why no drives are mapped and no printers installed.

****This is how I'm running the script...
I'm using a (logon.bat) batch file to call a (logonScript.vbs) vbscript placed on the Netlogon share.
Here is the script that ran without errors:

'==========================================================================
'
' 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 \\dc1/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

'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case UCase(GroupObj.Name)
'Check for group memberships and take needed action
Case "ADMIN"
WSHNetwork.MapNetworkDrive "r:", "\\dc1\SCAN",True
WSHNetwork.MapNetworkDrive "m:", "\\dc1\cristest",True
WSHNetwork.MapNetworkDrive "p:", "\\dc1\common",True
WSHNetwork.MapNetworkDrive "u:", "\\dc1\PUBLIC",True
WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf_Hp4050"
WSHNetwork.SetDefaultPrinter "\\dc1\mcf_Hp4050"
WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf_Xerox3035"
Case "DISPATCH"
WSHNetwork.MapNetworkDrive "U:", "\\dc1\PUBLIC",True
WSHNetwork.MapNetworkDrive "m:", "\\dc1\cristest",True
WSHNetwork.MapNetworkDrive "p:", "\\dc1\common",True
WSHNetwork.AddWindowsPrinterConnection "\\z02apimcf01\mcf_Hp3035"
WSHNetwork.SetDefaultPrinter "\\dc1\mcf_Hp3035"
WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf_Hp4050"

End Select

Next

'=====================================
Dim tempiepath
tempiepath = "HKCU\Software\Microsoft\Windows\"

WSHShell.RegWrite tempiepath & "ShellNoRoam\MUICache\@inetcplc.dll,-4750","Empty Temporary Internet Files folder when browser is closed","REG_SZ"

WSHShell.RegWrite tempiepath & "CurrentVersion\Internet Settings\Cache\Persistent","0","REG_DWORD"
Set tempiepath = nothing

'=====================================
HKEY_CURRENT_USER = &H80000001
strComputer = WSHNetwork.Computername
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Control Panel\Desktop"
objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
ValueName = "PaintDesktopVersion"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue

'=======================================================
' Determine the appropriate greeting for the time of day.
'=======================================================
Dim HourNow, Greeting
HourNow = Hour(Now)
If HourNow >5 And HourNow <12 Then
Greeting = "Good Morning "
Elseif HourNow =>12 And HourNow <16 Then
Greeting = "Good Afternoon "
Else
Greeting = "Good Evening "
End If
'=======================================================
'Find the Users Name

Dim GreetName
GreetName = SearchGivenName(objDomain,UserString)

' Use the Microsoft Speach API (SAPI)
'=====================================
Dim oVo
Set oVo = Wscript.CreateObject("SAPI.SpVoice")
oVo.speak Greeting & GreetName

'Modify This Function To Change Name Format
Public Function SearchGivenName(oRootDSE, ByVal vSAN)
' Function: SearchGivenName
' Description: Searches the Given Name for a given SamAccountName
' Parameters: RootDSE, ByVal vSAN - The SamAccountName to search
' Returns: First, Last or Full Name
Dim oConnection, oCommand, oRecordSet

Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
">;(&(objectCategory=User)(samAccountName=" & vSAN & "));givenName,sn,name;subtree"
Set oRecordSet = oCommand.Execute
On Error Resume Next
'Decide which name format to return and uncomment out
'that line. Default is first name.
'Return First Name
SearchGivenName = oRecordSet.Fields("givenName")
'Return Last Name
'SearchGivenName = oRecordSet.Fields("sn")
'Return First and Last Name
'SearchGivenName = oRecordSet.Fields("name")
On Error GoTo 0
oConnection.Close
Set oRecordSet = Nothing
Set oCommand = Nothing
Set oConnection = Nothing
Set oRootDSE = Nothing
End Function

'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

Please advise!
 
If no drivers or printers were mapped it means that the group names in the SELECT CASE statement don't match what the user is a member of.

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,

I'll retest again tomorrow morning and post the results.
 
Markdmac,

I just finished testing the script but I'm getting the same results.

What is NOT happening:..
1. NO Errors are generated,
2. NO network drives mapped,
3. NO printers installed

What is happening:..
1. I now can see on the system tray "service pack2 build displayed,
2. A blank html page is displayed--even thought a share pointing to the page is placed on the server.
3. Greetings: Morning/Evening comes on.
I was hoping to see an error msg but none is coming....what I'm doing wrong!
I created only two groups and two users accounts just for testing. That's ADMIN has one dedicated user account and same with ACCOUNTING. This way all doubts of NOT belonging to particular group are eliminated.
Here is screen shot vbscript


'===========================================================
'
' 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 \\dc1/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

'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case UCase(GroupObj.Name)
'Check for group memberships and take needed action
Case "ADMIN"
WSHNetwork.MapNetworkDrive "r:", "\\dc1\SCAN",True
WSHNetwork.MapNetworkDrive "m:", "\\dc1\cristest",True
WSHNetwork.MapNetworkDrive "p:", "\\dc1\common",True
WSHNetwork.MapNetworkDrive "u:", "\\dc1\PUBLIC",True
WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf_Hp4050"
WSHNetwork.SetDefaultPrinter "\\dc1\mcf_Hp4050"
WSHNetwork.AddWindowsPrinterConnection "\\dc1\Mcf_XeroxColor"
Case "ACCOUNTING"
WSHNetwork.MapNetworkDrive "U:", "\\dc1\PUBLIC",True
WSHNetwork.MapNetworkDrive "m:", "\\dc1\cristest",True
WSHNetwork.MapNetworkDrive "p:", "\\dc1\common",True
WSHNetwork.AddWindowsPrinterConnection "\\dc1\Mcf_Hp3035"
WSHNetwork.SetDefaultPrinter "\\dc1\Mcf_Hp3035"
WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf_Hp4050"

End Select

Next

'=====================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("\\DC1\welcome\Test.txt") Then
strText = objFSO.OpenTextFile("\\DC1\welcome\Test.txt", 1).ReadAll
Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate2 "about:blank" : objIE.width = 350 : objIE.height = 480 : objIE.toolbar = false : objIE.menubar = false : objIE.statusbar = false : objIE.visible = True
objIE.document.write "<font color=blue>"
objIE.document.write "<h1>Important Announcement</h1>"
objIE.document.write strText
objIE.document.write "</font>"
End If

'=====================================
Dim tempiepath
tempiepath = "HKCU\Software\Microsoft\Windows\"

WSHShell.RegWrite tempiepath & "ShellNoRoam\MUICache\@inetcplc.dll,-4750","Empty Temporary Internet Files folder when browser is closed","REG_SZ"

WSHShell.RegWrite tempiepath & "CurrentVersion\Internet Settings\Cache\Persistent","0","REG_DWORD"
Set tempiepath = nothing

'=====================================
HKEY_CURRENT_USER = &H80000001
strComputer = WSHNetwork.Computername
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Control Panel\Desktop"
objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
ValueName = "PaintDesktopVersion"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue

'=======================================================
' Determine the appropriate greeting for the time of day.
'=======================================================
Dim HourNow, Greeting
HourNow = Hour(Now)
If HourNow >5 And HourNow <12 Then
Greeting = "Good Morning "
Elseif HourNow =>12 And HourNow <16 Then
Greeting = "Good Afternoon "
Else
Greeting = "Good Evening "
End If
'=======================================================
'Find the Users Name

Dim GreetName
GreetName = SearchGivenName(objDomain,UserString)

' Use the Microsoft Speach API (SAPI)
'=====================================
Dim oVo
Set oVo = Wscript.CreateObject("SAPI.SpVoice")
oVo.speak Greeting & GreetName

'Modify This Function To Change Name Format
Public Function SearchGivenName(oRootDSE, ByVal vSAN)
' Function: SearchGivenName
' Description: Searches the Given Name for a given SamAccountName
' Parameters: RootDSE, ByVal vSAN - The SamAccountName to search
' Returns: First, Last or Full Name
Dim oConnection, oCommand, oRecordSet

Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
">;(&(objectCategory=User)(samAccountName=" & vSAN & "));givenName,sn,name;subtree"
Set oRecordSet = oCommand.Execute
On Error Resume Next
'Decide which name format to return and uncomment out
'that line. Default is first name.
'Return First Name
SearchGivenName = oRecordSet.Fields("givenName")
'Return Last Name
'SearchGivenName = oRecordSet.Fields("sn")
'Return First and Last Name
'SearchGivenName = oRecordSet.Fields("name")
On Error GoTo 0
oConnection.Close
Set oRecordSet = Nothing
Set oCommand = Nothing
Set oConnection = Nothing
Set oRootDSE = Nothing
End Function

'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
 
Are your groups GLOBAL GROUPS?

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top