[THIN] Re: WSH Logon Scripts

  • From: "Braebaum, Neil" <Neil.Braebaum@xxxxxxxxxxxxxxxxx>
  • To: <thin@xxxxxxxxxxxxx>
  • Date: Thu, 30 Sep 2004 16:59:12 +0100

Brian

Hot tip - don't use opendsobject with the WinNT provider - devils be there.

That and the other thing...

Neil

PS: oh, and don't cross the red and blue wires...

> -----Original Message-----
> From: thin-bounce@xxxxxxxxxxxxx 
> [mailto:thin-bounce@xxxxxxxxxxxxx] On Behalf Of Brian Smyth
> Sent: 30 September 2004 16:45
> To: thin@xxxxxxxxxxxxx
> Subject: [THIN] WSH Logon Scripts
> 
> 
> Attached is a sample of the logon scripts I use. Hope this 
> helps someone. You can ignore the first and last section and 
> customise everything in the middle. 
> 
> Brian Smyth
> 
> 
> 
> 
> 
> On Error Resume Next
> 
> '#############################################################
> ############################################################
> ' Define Variables and Constants 
> '#############################################################
> ############################################################
> 
> Dim objFileSys
> Dim objIntExplorer
> Dim objWshNetwork
> Dim objWshShell
> Dim strDesktop
> Dim strDomain           'Domain of the user
> Dim strHomePage         'Homepage to be set for user
> Dim strLogonPath        'Path to location from where the 
> script is running
> Dim strOSProdType       'OS Product type (WinNT, LanmanNT, ServerNT)
> Dim strWorkstation      'Local Computer Name
> Dim strUserGroups       'List of groups the user is a member of
> Dim intCounter          'General counter
> 
> Const UseNTServer = 0   'Sets whether this script runs when 
> logging on locally
>                        'to Windows Servers.
>                        'Values are: 1 (Yes) OR 0 (No)
> 
> 'Initialize common scripting objects
> Set objFileSys    = CreateObject( "Scripting.FileSystemObject" )
> Set objWshNetwork = CreateObject( "WScript.Network" )
> Set objWshShell   = CreateObject( "WScript.Shell" )
> 
> strDesktop = objWshShell.SpecialFolders("Desktop")
> strStartMenu = objWshShell.SpecialFolders("StartMenu")
> 
> strUser = ""
> intCounter = 0
> Do
>   strUserID = objWshNetwork.Username
>   intCounter = intCounter + 1
>   WScript.Sleep 500
> Loop Until strUserID <> "" OR intCounter > 20
> 
> 'Check for error getting username
> If strUserID = "" Then
>  objWshShell.Popup "Logon script failed - Contact the 
> Helpdesk @ x 345", , "Logon script", 48  Call Cleanup End If
> 
> 'Setup IE for use as a status message window
> Call SetupIE
> 
> 'Display welcome message
> Call UserPrompt ("Welcome <B>" & strUserID & "</B>")
> Call UserPromptLine
> 
> 'Gather some basic system info
> Call GetSystemInfo
> 
> Call UserPrompt ("You are currently logging into the <B> "& 
> strDomain & " </B> domain from workstation <B>" & 
> strWorkstation & "</B>") Call UserPrompt ("Please wait while 
> you settings are configured.....")
> 
> 'Get group memberships
> strUserGroups = ""
> Call GetGlobalGroupMembership
> 
> 'Display details in the Script Processor
> Call UserPromptLine
> Call UserPrompt ("You are a member of the follwing Security 
> Groups:") Call UserPrompt ("<B>" & strUserGroups & "</B>") 
> Call UserPromptLine Call UserPromptNewLine
> 
> 'Highlight the Logon Script processor results in blue
> Call UserPrompt ("<FONT COLOR=#0066FF><B>")
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> '###############################################################
> ' Modifiying the profile depending on group membership 
> '###############################################################
> 
> Call UserPrompt ("Setting your Locale to Irish.....") 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\iCalendarType", "1" objWshShell.RegWrite 
> "HKCU\Control Panel\International\iCountry", "353" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\iCurrDigits", "2" objWshShell.RegWrite 
> "HKCU\Control Panel\International\iCurrency", "0" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\iDate", "1" objWshShell.RegWrite 
> "HKCU\Control Panel\International\iDigits", "2" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\iFirstDayOfWeek", "0" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\iFirstWeekOfYear", "0" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\iLZero", "1" objWshShell.RegWrite 
> "HKCU\Control Panel\International\iMeasure", "0" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\iNegCurr", "1" objWshShell.RegWrite 
> "HKCU\Control Panel\International\iNegNumber", "1" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\iTime", "1" objWshShell.RegWrite 
> "HKCU\Control Panel\International\iTimePrefix", "0" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\iTLZero", "1" objWshShell.RegWrite 
> "HKCU\Control Panel\International\Locale", "00001809" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\NumShape", "1" objWshShell.RegWrite 
> "HKCU\Control Panel\International\s1159", "AM" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\s2359", "PM" objWshShell.RegWrite 
> "HKCU\Control Panel\International\sCountry", "Ireland" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\sCurrency", "€" objWshShell.RegWrite 
> "HKCU\Control Panel\International\sDate", "/" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\sDecimal", "." objWshShell.RegWrite 
> "HKCU\Control Panel\International\sGrouping", "3;0" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\sLanguage", "ENI" objWshShell.RegWrite 
> "HKCU\Control Panel\International\sList", "," 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\sLongDate", "dd MMMM yyyy" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\sMonDecimalSep", "." objWshShell.RegWrite 
> "HKCU\Control Panel\International\sMonGrouping", "3;0" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\sMonThousandSep", "," 
> objWshShell.RegWrite "HKCU\Control Panel\International\sNativeDigits",
> "0123456789"
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\sNegativeSign", "-" objWshShell.RegWrite 
> "HKCU\Control Panel\International\sPositiveSign", "" 'Line 
> 100 objWshShell.RegWrite "HKCU\Control 
> Panel\International\sShortDate", "dd/MM/yyyy" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\sThousand", "," objWshShell.RegWrite 
> "HKCU\Control Panel\International\sTime", ":" 
> objWshShell.RegWrite "HKCU\Control 
> Panel\International\sTimeFormat", "h:mm:ss tt"
> 
> 
> '###############################################################
> ' Creating Drive Mappings depending on group membership 
> '###############################################################
> 
> If InGroup("Domain Users") Then
>   Call UserPrompt ("Mapping Drive for Domain Users Users.....")
>   call MapDrive( "L:", "FileServer", "ShareName$", "Name of 
> drive") End IF
> 
> 
> '###############################################################
> ' Creating shortcuts depending on group membership 
> '###############################################################
> 
> 'Clear out the Start Menu
> objFileSys.DeleteFile strStartMenu & "\*.*" 
> objFileSys.DeleteFile strStartMenu & "\Programs\*.*" 
> objFileSys.DeleteFile strStartMenu & 
> "\Programs\Administrative Tools*.*"
> 
> If InGroup("CTXAccess") Then
>   Call UserPrompt ("Adding icons for MS Access Users.....")
>   Call subCreateShortcut (strStartmenu & "\MS Access.lnk", 
> "D:\Apps\Microsoft Office\Office10\MSACCESS.EXE", , "D:\Apps\Microsoft
> Office\Office10")
> End If
> 
> If InGroup("CTXWord") Then
>   Call UserPrompt ("Adding icons for MS Word Users.....")
>   Call subCreateShortcut (strStartmenu & "\MS Word.lnk", 
> "D:\Apps\Microsoft Office\Office10\WINWORD.EXE", , "D:\Apps\Microsoft
> Office\Office10")
> End If
> 
> 
> 'Highlight the Logon Script processor results in black
> Call UserPrompt ("<FONT COLOR=#000000></B>")
> 
> Call UserPromptNewLine
> Call UserPromptLine
> Call UserPrompt ("The Logon Scripter has Completed. Thank You!")
> 
> Wscript.Sleep (3000)
> objIntExplorer.Quit( )
> 
> Call Cleanup
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> '#############################################################
> ############################################################
> '        FUNCTIONS AND SUB-ROUTINES
> '#############################################################
> ############################################################
> 
> '#############################################################
> #############################
> ' Maps network drives. Call MapDrive ("X:", "Server", 
> "share", "Friendly name for share") 
> '#############################################################
> #############################
> 
> Private Sub MapDrive( strDrive, strServer, strShare, strDriveName )
> 
>  On Error Resume Next
> 
>  Set oShell = CreateObject("Shell.Application")
>  Dim strPath       'Full path to printer share
>  Dim blnError      'True / False error condition
> 
>  blnError = False
> 
>  'Disconnect Drive if drive letter is already mapped.
>  'This assures everyone has the same drive mappings
> 
>  If objFileSys.DriveExists(strDrive) = True Then
>    objWshNetwork.RemoveNetworkDrive strDrive,True , True
>  End If
> 
>  'Build path to share
>  strPath = "\\" & strServer & "\" & strShare
> 
>    ' The following line maps the drive to the remote share
>    objWshNetwork.MapNetworkDrive strDrive, strPath
>    ' Renames the Drive Letter to make it look more user friendly
>    oShell.nameSpace(strDrive & "\").Self.name = strDriveName
> 
>  'Check error condition and output appropriate user message
>  If Err.Number <> 0 OR blnError = True Then
>    'Display message box informing user that the connection failed
>    strMsg = "Unable to connect to network share. " & vbCrLf & _
>             "Please contact the Helpdesk @ ext 345 and ask them " & _
>             "to check the " & strServer & " server." & vbCrLf & _
>             "Let them know that you are unable to connect to the " & _
>             "'" & strPath & "' share"
>    objWshShell.Popup strMsg,, "Logon Error !", 48
>  Else
>    Call UserPrompt ("Successfully added mapped drive 
> connection to " & strPath)  End If End Sub
> 
> '#############################################################
> #############################
> ' Populates strUserGroup with a list of the Groups which the 
> user is a member of to be parsed by the Ingroup Function 
> '#############################################################
> #############################
> Private Sub GetGlobalGroupMembership
> 
>  On Error Resume Next
> 
>  Dim objNameSpace
>  Dim objUser
> 
>  Const ADS_READONLY_SERVER = 4
> 
>  Set objNameSpace = GetObject( "WinNT:" )
>  'Use the OpenDSObject method with the ADS_READONLY_SERVER  
> 'value to grab the "closest" domain controller
> 
>  'Connect to user object in the domain
>  Set objUser = objNameSpace.OpenDSObject("WinNT://" & 
> strDomain & "/" & strUserID, "", "", ADS_READONLY_SERVER)  
> 'Process each group  For Each objGroup In objUser.Groups
>    'Add group name to list
>    strUserGroups = strUserGroups & objGroup.Name & ","
>  Next
>  Set objNameSpace = Nothing
> 
> End Sub
> 
> '#############################################################
> #############################
> 'Checks the list populated from GetGlobalGroupMembership to 
> see if user is a member of a group 
> '#############################################################
> #############################
> Private Function InGroup(strGroup)
> 
>  On Error Resume Next
> 
>  InGroup = False
>  'Search strUserGroups for strGroup
>  If Instr( 1, LCase( strUserGroups ), LCase( strGroup ), 1) 
> Then InGroup = True
> 
> End Function
> 
> '#############################################################
> #############################
> '   Gathers basic information about the current session and the OS
> '   Output:   strDomain, strOSProdType, strWorkstation, strLogonPath
> '#############################################################
> #############################
> Private Sub GetSystemInfo
> 
>  On Error Resume Next
> 
>  'Get domain name
>  If objWshShell.ExpandEnvironmentStrings( "%OS%" ) = "Windows_NT" Then
>    strDomain = objWshNetwork.UserDomain
>  Else
>    strDomain = objWshShell.RegRead( 
> "HKLM\System\CurrentControlSet\" & 
> "Services\MSNP32\NetWorkProvider\AuthenticatingAgent" )  End If
> 
>  'Get Product Type from Registry (WinNT, LanmanNT, ServerNT)  
> strOSProdType =
> objWshShell.RegRead("HKLM\System\CurrentControlSet\Control\Pro
> ductOptions\ProductType")
> 
>  'Get computer name
>  If IsTerminalServerSession = True Then
>    'Set strWorkstation to the real name and not the name of the server
>    strWorkstation = objWshShell.ExpandEnvironmentStrings( 
> "%CLIENTNAME%" )  Else
>    strWorkstation = objWshNetwork.ComputerName
>  End If
> 
>  'Get the path to the location from where the script is 
> running  strLogonPath = Left( Wscript.ScriptFullName, ( 
> InstrRev( Wscript.ScriptFullName, "\") -1))
> 
> End Sub
> 
> '#############################################################
> #############################
> '   Set up Internet Explorer for use as a status message window
> '#############################################################
> #############################
> Private Sub SetupIE
> 
>  On Error Resume Next
> 
>  Dim strTitle    'Title of IE window
>  Dim intCount    'Counter used during AppActivate
> 
>  strTitle = "Script Processor"
> 
>  'Create reference to objIntExplorer
>  'This will be used for the user messages. Also set IE 
> display attributes  Set objIntExplorer = 
> Wscript.CreateObject("InternetExplorer.Application")
>  With objIntExplorer
>    .Navigate "about:blank"
>    .ToolBar   = 0
>    .Menubar   = 0
>    .StatusBar = 0
>    .Width     = 600
>    .Height    = 550
>    .Left      = 100
>    .Top       = 100
>  End With
> 
>  'Set some formating
>  With objIntExplorer.Document
>    .WriteLn ("<!doctype html public>")
>    .WriteLn   ("<head>")
>    .WriteLn    ("<title>" & strTitle & "</title>")
>    .WriteLn     ("<style type=""text/css"">")
>    .WriteLn      ("body {text-align: left; font-family: arial;
> font-size: 10pt}")
>    .WriteLn     ("</style>")
>    .WriteLn   ("</head>")
>  End With
> 
>  'Wait for IE to finish
>  Do While (objIntExplorer.Busy)
>    Wscript.Sleep 200
>  Loop
> 
>  'Show IE
>  objIntExplorer.Visible = 1
> 
>  'Make IE the active window
>  For intCount = 1 To 100
>    If objWshShell.AppActivate(strTitle) Then Exit For
>    WScript.Sleep 50
>  Next
> 
> End Sub
> 
> '#############################################################
> #############################
> '   UserPrompt: Add a line of text to the Script processor Windows
> '   UserPromptLine: Add a horizontal line to the Script 
> processor Windows
> '   UserPromptNewLine: Add a new line to the Script processor Windows
> '#############################################################
> #############################
> Private Sub UserPrompt( strPrompt )
> 
>  On Error Resume Next
> 
>  objIntExplorer.Document.WriteLn (strPrompt & "<br />")
> 
> End Sub
> 
> Private Sub UserPromptLine
> 
>  On Error Resume Next
> 
>  objIntExplorer.Document.WriteLn ("<hr style=""width:100%""></hr>")
> 
> End Sub
> 
> Private Sub UserPromptNewLine
> 
>  On Error Resume Next
> 
>  objIntExplorer.Document.WriteLn ("<P>&nbsp;</P>")
> 
> End Sub
> 
> '#############################################################
> #############################
> '   Creates a new shortut for the user
> '#############################################################
> #############################
> Private Sub subCreateShortcut(strLocation, strTargetPath, 
> strIconLocation, strWorkingDirectory)
> 
>  On Error Resume Next
>  set oShellLink = objWshShell.CreateShortcut(strLocation)
>  oShellLink.TargetPath = strTargetPath
>  oShellLink.WindowStyle = 3                '1 is normal, 2 is
> minimised, 3 is maximised
>  oShellLink.HotKey = ""
>  oShellLink.IconLocation = strIconLocation  
> oShellLink.Description = ""  oShellLink.WorkingDirectory = 
> strWorkingDirectory  oShellLink.Save
> 
> End Sub
> 
> '#############################################################
> #############################
> '   Empties all the variables of data
> '#############################################################
> #############################
> Sub Cleanup'
> 
>  On Error Resume Next
> 
>  Set objFileSys     = Nothing
>  Set objWshNetwork  = Nothing
>  Set objWshShell    = Nothing
>  Set objIntExplorer = Nothing
> 
>  'Exit script
>  Wscript.Quit( )
> 
> End Sub
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> Regards,
> Brian Smyth
> SBC Consultant
> Intertech Ireland Ltd
> Tel: 0876062257
> 
> ********************************************************
> This Weeks Sponsor RTO Software
> Do you know which applications are abusing your CPU and memory?
> Would you like to learn? --   Free for a limited time!
> Get the RTO Performance Analyzer to quickly learn the 
> applications, users, and time of day possible problems exist. 
> http://www.rtosoft.com/enter.asp?id20
> ********************************************************** 
> Useful Thin Client Computing Links are available at: 
> http://thin.net/links.cfm
> ***********************************************************
> For Archives, to Unsubscribe, Subscribe or 
> set Digest or Vacation mode use the below link: 
> http://thin.net/citrixlist.cfm
> 

***********************************************
This e-mail and its attachments are confidential
and are intended for the above named recipient
only. If this has come to you in error, please 
notify the sender immediately and delete this 
e-mail from your system.
You must take no action based on this, nor must 
you copy or disclose it or any part of its contents 
to any person or organisation.
Statements and opinions contained in this email may 
not necessarily represent those of Littlewoods.
Please note that e-mail communications may be monitored.
The registered office of Littlewoods Limited and its
subsidiaries is 100 Old Hall Street, Liverpool, L70 1AB.
Registered number of Littlewoods Limited is 262152.
************************************************

********************************************************
This Weeks Sponsor RTO Software
Do you know which applications are abusing your CPU and memory?
Would you like to learn? --   Free for a limited time!
Get the RTO Performance Analyzer to quickly learn the applications, users,
and time of day possible problems exist.
http://www.rtosoft.com/enter.asp?id20
**********************************************************
Useful Thin Client Computing Links are available at:
http://thin.net/links.cfm
***********************************************************
For Archives, to Unsubscribe, Subscribe or
set Digest or Vacation mode use the below link:
http://thin.net/citrixlist.cfm

Other related posts: