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
 
Yes, it's
Type: Security Group-Global.
*** Some new development. One user is able to login and all the drives are mapped and the printers installed, BUT if I use a different account to login, nothing happens---no drive maps or printers installed.

I'm also using a batch file to call the vbscript and I'm not sure whether that's causing any problems. My company has it's OU and I don't have access to GPO, I'm only allowed to manage my OU.
Here is my current vbscript, with the server name xxxx out.
It's hard to know why it's acting this way. It's working for only one user and others in the same group are not getting anything. The Welcome message and the Greetings too.
Let me know what you think.


'==========================================================================
'
' 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 \\xxx/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 "MCF ADMIN"
WSHNetwork.MapNetworkDrive "r:", "\\xxx\SCAN",True
WSHNetwork.MapNetworkDrive "m:", "\\xxx\cristest",True
WSHNetwork.MapNetworkDrive "p:", "\\xxx\common",True
WSHNetwork.MapNetworkDrive "u:", "\\xxx\PUBLIC",True
WSHNetwork.AddWindowsPrinterConnection "\\xxx\mcf-ADMIN"
WSHNetwork.SetDefaultPrinter "\\xxx\mcf-ADMIN"
WSHNetwork.AddWindowsPrinterConnection "\\xxx\mcf-Xerox"
Case "MCF DISPATCH"
WSHNetwork.MapNetworkDrive "U:", "\\xxx\PUBLIC",True
WSHNetwork.MapNetworkDrive "m:", "\\xxx\cristest",True
WSHNetwork.MapNetworkDrive "p:", "\\xxx\common",True
WSHNetwork.AddWindowsPrinterConnection "\\xxx\mcf-Dispatch"
WSHNetwork.SetDefaultPrinter "\\xxx\mcf-Dispatch"
WSHNetwork.AddWindowsPrinterConnection "\\xxx\mcf-ADMIN"

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

Next
'=====================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("\\server\Welcome\message.txt") Then
strText = objFSO.OpenTextFile("\\xxx\Welcome\Message.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

'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
 
Too many unknowns to deal with. If you have control of your OU then you should have the ability to attach a login script to that OU as well. That way you know it is applying to all users in that OU and below.

I noticed you have the NEXT for the group enumeration way down in the script. Use this instead.

Code:
==========================================================================
'
' NAME: LogonScript.vbs
'
' 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.
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
'==========================================================================

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 "MCF 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-ADMIN"
            WSHNetwork.SetDefaultPrinter "\\dc1\mcf-ADMIN"
            WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf-Xerox"
        Case "MCF DISPATCH"
            WSHNetwork.MapNetworkDrive "U:", "\\dc1\PUBLIC",True
            WSHNetwork.MapNetworkDrive "m:", "\\dc1\cristest",True
            WSHNetwork.MapNetworkDrive "p:", "\\dc1\common",True
            WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf-Dispatch"
            WSHNetwork.SetDefaultPrinter "\\dc1\mcf-Dispatch"
            WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf-ADMIN"
    
    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
'=====================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("\\dc1\Welcome\message.txt") Then
    strText = objFSO.OpenTextFile("\\dc1\Welcome\Message.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

'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

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.
 

Here is the error msg:

Line: 43 WSHNetwork.RemoveNetworkDrive "F:"
Source: WSHNetworkRemoveNetworkdrive
Code: 800708CA

I'm almost there but still having problems.
Any suggestions well appreciated.

Thanks,
 
Hi All,

Update: I've been working on this all day now and it seems like it's paying of now.
I tested the script on two user accounts and I noticed that if that same user log on and then logsoff, the network drives are still mapped, and an error being generated.
What can I add to the script to refresh or delete previously mapped network drives and remap the same drives during logon.
I need the html massge window to close after 30 seconds ????
What do I need to add to the script to close this window??
A m almost there, slow but sure!
Here is error Msg:
Line 66
Char: 12
Error: The local drive name is already in use
Source: WSHNetwork.MapNetworkDrive
Code: 80070055

Thanks guys!
 
Remove what I have outlined in red.
The part in blue disconnects all mapped drives at login.

Code:
[red]
'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "F:"[/red]
[blue]
'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
    WSHNetwork.RemoveNetworkDrive clDrives.Item(i)
Next
[/blue]

I have seen instances where a manually mapped drive won't disconnect via script. You may need to manually force that once.

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, the script is working like charm..
Now I need the popup window to close in 20 or 30 seconds. I've tried almost all kinds of codes but still the user has to manually close the window. I would like the popup window to close itself after 20 or 30 sec.
One more problem, even though a share folder is pointing to the server, the message is not been read>>>
\\dc1\Welcome\message.txt",

only the objIE.document.write "<h1>Welcome</h1>" html welcome page.

Any ideas what I need to add?
Thanks for all your help,


'=====================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("\\dc1\Welcome\message.txt") Then
strText = objFSO.OpenTextFile("\\dc1\Welcome\Message.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>Welcome</h1>"
objIE.document.write strText
objIE.document.write "</font>" Quit
End If
 
Unless you are willing to kill all IE windows on the user then you won't be able to close out that Window. You could do it if you are willing to take the risk of closing all Windows and potentially making users angry with you if they have configured IE to autostart.

To do what you are asking add the following after you display the message:
Code:
Wscript.Sleep 30000
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'iexplore.exe'")

For Each objProcess in colProcessList
    objProcess.Terminate()
Next

For the problem with the message, verify both share and NTFS permissions. All users need to be able to read the file.

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'm still have some problems on connected drives.
If a user happens to login and then logoff, an error is generated stating that
1. " The local device name is already in use" If I uncomment out this line: 'WSHNetwork.RemoveNetworkDrive "F:" the script generates an error.

2. Dim GreetName.. This will give my users a little smile when they seen their names displayed on the screen. No name displayed..whether it's commnented out or not. I prefer First name ..

3.Greetings: is working fine morning or evening.

All the lines COMMENTED OUT were causing the script to error out.

Any help is greatly appreciated.
Please see the the exact script below>>>>>>>

Thanks,


'==========================================================================
'
' 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_Hp4050"
' Case "DISPATCH"
WSHNetwork.MapNetworkDrive "U:", "\\dc1\PUBLIC",True
WSHNetwork.MapNetworkDrive "m:", "\\dc1\cristest",True
WSHNetwork.MapNetworkDrive "p:", "\\dc1\common",True
WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf_Hp4050"
WSHNetwork.SetDefaultPrinter "\\dc1\mcf_Hp4050"
WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf_Hp4050"

' 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

'=======================================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("\\dc1\Welcome\Have a nice day") Then
strText = objFSO.OpenTextFile("\\dc1\Welcome\Have a nice day", 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>Have a nice day</h1>"
objIE.document.write strText
objIE.document.write "</font>"
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
 
Refer to my post of August 13th. Seems you have missed or ignored that feedback.

Ensure that your AD is populated with first names. What is your DNS name? I have seen problems with the SearchGivenName function when the name is three parts such as

DC=company,DC=corp,DC=local
instead of something like
DC=company,DC=local

You can hard code domain information into the function if that is the case to overcome the issue.


Make sure that all manually mapped drives have been removed before you implement the script in production.

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.
 


Sorry,

I got your August 13th response but I got carried away by other problems. I've time now to devote to vb scripting and a good reason to justify the study guide expense.
My DNS Name is Medstarcorp.com
I would like to hard code domain information into the function to overcome this problem...But where do I put it
in the script?
 
Replace
Code:
oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
With
Code:
oCommand.CommandText = "<LDAP://DC=medstarcorp,DC=com" & _

Just want to verify you gave me the INTERNAL DNS name, not just your external DNS name.


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.
 
This is our Lab DNS name.
oCommand.CommandText = "<LDAP://DC=dc1,DC=local" & _

I'll add the code,test it and post the results back here.

Many thanks,

 
Hi Mark,

Sorry it took so long to come back and post the results.
The script is working great and my users are loving me more and more, especially when their names are mentioned "good morning/evening and so on. The only part I'd like to edit in the html popup window. I would like this message to appear in the very beginning of the script so, that users will not interrupt the script. When the popup window comes users are willing to wait as long as the the message tells them what is happening.
How can I place the html popup message box at the very top of the script, so that the " Login script in progress.....Please wait" window comes before drive mappings starts??? otherwise everything else works fine and l'm loving it and my boss is very happy!

Here is my excat script:


'==========================================================================
'
' 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_Hp4050"
' Case "ACCOUNTING"
WSHNetwork.MapNetworkDrive "U:", "\\dc1\PUBLIC",True
WSHNetwork.MapNetworkDrive "m:", "\\dc1\cristest",True
WSHNetwork.MapNetworkDrive "p:", "\\dc1\common",True
WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf_Hp4050"
WSHNetwork.SetDefaultPrinter "\\dc1\mcf_Hp4050"
WSHNetwork.AddWindowsPrinterConnection "\\dc1\mcf_Hp4050"

' 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
'=====================================
' First we get the current screen resolution so we can place
' our progress window in the centre
' See:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
("Select PelsWidth,PelsHeight From Win32_DisplayConfiguration")

For Each objItem in colItems
intScreenWidth = objItem.PelsWidth
intScreenHeight = objItem.PelsHeight
Next

' Now create our display window and position it in the centre
intWidth = 600
intHeight = 90
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
objIE.Toolbar = 0
objIE.StatusBar = 0
objIE.AddressBar = 0
objIE.MenuBar = 0
objIE.Resizable = 0
While objIE.ReadyState <> 4


Wend
objIE.Left = (intScreenWidth /8) - (intWidth / 8)
objIE.Top = (intScreenHeight / 8) - (intHeight / 8)
objIE.Visible = True

' Now run your normal code and you can use
' objIE.document.WriteLn "This is my message"
' anywhere in the code to update progress

objIE.Document.WriteLn "Login script in progress.. Please wait....... " & "<BR>"
WScript.Sleep 6000 ' Wait 40 seconds
objIE.Quit ' Close IE
'=======================================================
'=======================================================
'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
 
I'm not sure I understand your question. Are you asking what code to move around? Your users should not be able to interrupt the script. They should not even see it executing if you have set it up in a GPO.

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,

My script is not in a GPO yet and it's unlikely it will be put there. Our org has many others OU's and for me to manage the script it's best not to have the script placed in a GPO... reasons being if I need to change anything, I have to call enterprise group for that, ... in a Netlogon share and I can make changes any time if need be without involving others and opening a tickets.
Or what I wanted to have HTML window message box be the first one to execute followed by the rest of the script.
Yes, I'm asking what codes to move around so html browser comes first.
 
Put it in a GPO and have your network people assign you rights to the GPO folder so you can have direct disk access to where the GPO stores the login script. Then you can update as needed without having to modify the GPO (which they should be able to delegate to you anyway by giving you a custom MMC view).

GPO is really the best and proper way to do it. Anything else just becomes a problematic installation.

If your network guys don't know how to find that folder just do the following. Have them add the login script to the GPO. They can then hit Show Files in the window where you set the login script. That will open up an explorer window showing the login script. The Address Bar will show them the folder on the server (within the sysvol) where the files exist. They can grant you NTFS permissions like they gave you to Netlogon so you can directly access the login script directory.

The better solution though is for them to delegate control of your OU to you. That will allow you to use GPMC to manage your OU and the policies that affect it.


You can use the delegation of control wizard to delegate administrative control of active directory objects, such as organizational units. By using the wizard, you can delegate common administrative tasks, such as creating, deleting, and managing user accounts.

To delegate common administrative tasks for an organizational unit, perform the following steps:

Start the delegation of control wizard by performing the following steps:
Open Active Directory Users and Computers.
In the console tree, double click the domain node.
In the details menu, right click the organizational unit, click delegate control, and click 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.
 


In the meantime, while waiting to get access to the GPO..how I can code this script to open the welcome message window in the beginning of the script? The script is not visible to end users as such.. it's running in a min/window on the system tray, but even though it's minimized users tend to click on icons before the script closes.
 
Move the following code up in the script.

Code:
'=====================================
' First we get the current screen resolution so we can place
' our progress window in the centre
' See: [URL unfurl="true"]http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul05/hey0721.mspx[/URL]
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colItems = objWMIService.ExecQuery _
        ("Select PelsWidth,PelsHeight From Win32_DisplayConfiguration")
 
For Each objItem in colItems
        intScreenWidth = objItem.PelsWidth
        intScreenHeight = objItem.PelsHeight
Next
 
' Now create our display window and position it in the centre
intWidth = 600
intHeight = 90
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
objIE.Toolbar = 0
objIE.StatusBar = 0
objIE.AddressBar = 0
objIE.MenuBar = 0
objIE.Resizable = 0
While objIE.ReadyState <> 4

        
Wend
objIE.Left = (intScreenWidth /8) - (intWidth / 8)
objIE.Top = (intScreenHeight / 8) - (intHeight / 8)
objIE.Visible = True
 
' Now run your normal code and you can use
' objIE.document.WriteLn "This is my message"
' anywhere in the code to update progress
 
objIE.Document.WriteLn "Login script in progress.. Please wait....... " & "<BR>"
WScript.Sleep 6000 ' Wait 40 seconds
objIE.Quit ' Close IE

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 call the Enterprise group tommorrow and request access to the GPO.
I'll let you know.

Thanks for all your help.
 


Hi Mark,


I've an old NT 4.0 server running an old DOS based application. For some reason users cannot run it after launching the script. Is there any part of the script to edit to allow the app to run as usual. When users click on the apps desktop icon, you get a quick flash and then it closes. But, other than that everything else is perfect! Any ideas ??

Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top