-
February 2nd, 2005, 05:11 PM
#11
Junior Member
Ok, here you go. I didn't clean it up much, and this is a long post. You will be most interested in the sub SetupIE. This is where the basic IE window is set up. There is a line that places the logo in the window. The sub UserPrompt is what actually writes information to the IE window. I think I've stripped out company specific data from the script, so feel free to hack it apart and use the pieces you want.
Begin script->
'**************************************************************************************************
'*
'* File: Logon.vbs
'*
'**************************************************************************************************
On Error Resume Next
'**************************************************************************************************
'* Define Variables and Constants
'**************************************************************************************************
Dim strTest
Dim objFileSys
Dim objIntExplorer
Dim objWshNetwork
Dim objWshShell
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" )
'**************************************************************************************************
'* Pause script until user is fully logged on (applicable only to Win 9x or ME)
'* This will timeout after 10 seconds
'**************************************************************************************************
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 666", , "Logon script", 48
Call Cleanup
End If
'**************************************************************************************************
'* Setup IE for use as a status message window
'**************************************************************************************************
Call SetupIE
'**************************************************************************************************
'* Display welcome message
'**************************************************************************************************
Call UserPrompt ("Welcome " & strUserID)
'**************************************************************************************************
'* Add horizontal line as a 'break'
'**************************************************************************************************
objIntExplorer.Document.WriteLn("<hr style=""width:100%""></hr>")
'**************************************************************************************************
'* Gather some basic system info
'**************************************************************************************************
Call GetSystemInfo
If IsTerminalServerSession <> True Then
'* Exit if we are logging on locally to a server and the script is set to NOT run on servers
IF UseNTServer = 0 AND (strOSProdType = "LanmanNT" OR strOSProdType = "ServerNT") Then
objWshShell.Popup "Windows Server - Exiting Logon Script!", 10, "Logon to " & strDomain, 16
Call CleanUp
End if
End If
'**************************************************************************************************
'* Get group memberships
'**************************************************************************************************
strUserGroups = ""
Call GetLocalGroupMembership
Call GetGlobalGroupMembership
'**************************************************************************************************
'* Launch BGInfo to add system information to the desktop
'**************************************************************************************************
RETURN = objWshShell.Run (strLogonPath & "\" & strExec & strLogonPath & "\" & strArg, 0, true)
'**************************************************************************************************
'* Map standard drives
'**************************************************************************************************
Call MapDrive ("F:", "ServerName", "ShareName") '* Replace ServerName and ShareName with your own info
'**************************************************************************************************
'* Add horizontal line as a 'break'
'**************************************************************************************************
objIntExplorer.Document.WriteLn("<hr style=""width:100%""></hr>")
'**************************************************************************************************
'* Inform user that logon process is done
'**************************************************************************************************
Call UserPrompt ("Finished network logon processes")
'**************************************************************************************************
'* Wait 5 seconds
'**************************************************************************************************
Wscript.Sleep (5000)
'**************************************************************************************************
'* Close Internet Explorer
'**************************************************************************************************
objIntExplorer.Quit()
Call Cleanup
'**************************************************************************************************
'*
'* Sub: AddPrinter
'*
'* Purpose: Connect to shared network printer
'*
'* Input:
'* strPrtServerDomain Domain in which print server is a member
'* strPrtServer Name of print server
'* strPrtShare Share name of printer
'*
'* Output:
'*
'* Usage:
'* Call AddPrinter ("Mydomain2", "MyPrtSvr2", "Bld1Rm101-HP4050")
'*
'**************************************************************************************************
Private Sub AddPrinter(strPrtServerDomain, strPrtServer, strPrtShare)
On Error Resume Next
Dim strPrtPath 'Full path to printer share
Dim objPrinter 'Object reference to printer
Dim strMsg 'Message output to user
Dim blnError 'True / False error condition
blnError = False
'* Build path to printer share
strPrtPath = "\\" & strPrtServer & "\" & strPrtShare
'* Test to see if shared printer exists.
'* Proceed if yes, set error condition msg if no.
Set objPrinter = GetObject ("WinNT://" & strPrtServerDomain & "/" & strPrtServer & "/" & strPrtShare)
If IsObject( objPrinter ) AND (objPrinter.Name <> "" AND objPrinter.Class = "PrintQueue") Then
'* Different mapping techniques depending on OS version
If objWshShell.ExpandEnvironmentStrings( "%OS%" ) = "Windows_NT" Then
Err.Clear
'* Map printer
objWshNetwork.AddWindowsPrinterConnection strPrtPath
Else
'* Mapping printers for Win9x & ME is a pain and unreliable.
End If
Else
blnError = True
End IF
'* Check error condition and output appropriate user message
If Err <> 0 OR blnError = True Then
strMsg = "Unable to connect to network printer. " & vbCrLf & "Please contact the Helpdesk @ ext 345" & vbCrLf & "and ask them to check the " & strPrtServer & " server." & vbCrLf & vbCrLf & "Let them know that you are unable to connect to the '" & strPrtShare & "' printer"
objWshShell.Popup strMsg,, "Logon Error !", 48
Else
Call UserPrompt ("Successfully added printer connection to " & strPrtPath)
End If
Set objPrinter = Nothing
End Sub
'**************************************************************************************************
'*
'* Sub: MapDrive
'*
'* Purpose: Map a drive to a shared folder
'*
'* Input:
'* strDrive Drive letter to which share is mapped
'* strServer Name of server that hosts the share
'* strShare Share name
'*
'* Output:
'*
'* Usage:
'* Call MapDrive ("X:", "StaffSvr1", "StaffShare1")
'*
'**************************************************************************************************
Private Sub MapDrive( strDrive, strServer, strShare )
On Error Resume Next
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
End If
'* Build path to share
strPath = "\\" & strServer & "\" & strShare
'* Test to see if share exists. Proceed if yes, set error condition if no.
If objFileSys.DriveExists(strPath) = True Then
Err.Clear
objWshNetwork.MapNetworkDrive strDrive, strPath
Else
blnError = True
End If
'* 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
'**************************************************************************************************
'*
'* Sub: GetLocalGroupMembership
'*
'* Purpose: Gather all local groups the current user belongs to
'*
'* Input:
'*
'* Output: Local group names are added to strUserGroups
'*
'* Usage: Call GetLocalGroupMembership
'*
'**************************************************************************************************
Private Sub GetLocalGroupMembership
On Error Resume Next
Dim colGroups '* Collection of groups on the local system
Dim objGroup '* Object reference to individual groups
Dim objUser '* Object reference to individual group member
'* Verify system is not Windows 9x or ME
If objWshShell.ExpandEnvironmentStrings( "%OS%" ) = "Windows_NT" Then
'* Connect to local system
Set colGroups = GetObject( "WinNT://" & strWorkstation )
colGroups.Filter = Array( "group" )
'* Process each group
For Each objGroup In colGroups
'* Process each user in group
For Each objUser in objGroup.Members
'* Check if current user belongs to group being processed
If LCase( objUser.Name ) = LCase( strUserID ) Then
'* Add group name to list
strUserGroups = strUserGroups & objGroup.Name & ","
End If
Next
Next
Set colGroups = Nothing
End If
End Sub
'**************************************************************************************************
'*
'* Sub: GetGlobalGroupMembership
'*
'* Purpose: Gather all global groups the current user belongs to
'*
'* Input:
'*
'* Output: Global group names are added to strUserGroups
'*
'* Usage: Call GetGlobalGroupMembership
'*
'* Notes: Use WinNT connection method to be backwards
'* compatible with NT 4 domains
'*
'**************************************************************************************************
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
'**************************************************************************************************
'*
'* Function: InGroup
'*
'* Purpose: Determine if user belongs to specified group
'*
'* Input: Name of group to test for membership
'*
'* Output: True or False
'*
'* Usage: If InGroup("Domain Admins") Then <do something>
'*
'* Requirements:
'* strUserGroups must have been previously populated via
'* GetLocalGroupMembership and/or GetGlobalGroupMembership
'*
'**************************************************************************************************
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
'**************************************************************************************************
'*
'* Sub: GetSystemInfo
'*
'* Purpose: Gather basic info about local system
'*
'* Input:
'*
'* Output: strDomain, strOSProdType, strWorkstation, strLogonPath
'*
'* Usage: Call GetSystemInfo
'*
'**************************************************************************************************
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\ProductOptions\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
'**************************************************************************************************
'*
'* Function: IsTerminalServer
'*
'* Purpose: Determine if the script is running in a terminal server session
'*
'* Input:
'*
'* Output:
'* True if running in a terminal server session
'* False if not running in a terminal server session
'* Usage:
'* If IsTerminalServerSession = True Then <Do Something>
'*
'**************************************************************************************************
Private Function IsTerminalServerSession
On Error Resume Next
Dim strName
'* Detect if this is a terminal server session
'* If it is, set some names to the terminal server client name
strName = objWshShell.ExpandEnvironmentStrings( "%CLIENTNAME%" )
If strName <> "%CLIENTNAME%" AND strName <> "" Then IsTerminalServerSession = True
End Function
'**************************************************************************************************
'*
'* Sub: SetupIE
'*
'* Purpose: Setup Internet Explorer for use as a status message window
'*
'* Input:
'*
'* Output:
'*
'* Usage: Call SetupIE
'*
'**************************************************************************************************
Private Sub SetupIE
On Error Resume Next
Dim strTitle '* Title of IE window
Dim intCount '* Counter used during AppActivate
strTitle = "Logon script status"
'* 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 = 350
.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 ("<img src=" & strLogonPath & "\logo.gif>")
.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
'**************************************************************************************************
'*
'* Sub: UserPrompt
'*
'* Purpose: Use Internet Explorer as a status message window
'*
'* Input: strPrompt
'*
'* Output: Output is sent to the open Internet Explorer window
'*
'* Usage:
'*
'**************************************************************************************************
Private Sub UserPrompt( strPrompt )
On Error Resume Next
objIntExplorer.Document.WriteLn (strPrompt & "<br />")
End Sub
'**************************************************************************************************
'*
'* Sub: Cleanup
'*
'* Purpose: Release common objects and exit script
'*
'* Input:
'*
'* Output:
'*
'* Usage: Call Cleanup
'*
'**************************************************************************************************
Sub Cleanup
On Error Resume Next
Set objFileSys = Nothing
Set objWshNetwork = Nothing
Set objWshShell = Nothing
Set objIntExplorer = Nothing
'* Exit script
Wscript.Quit()
End Sub
'**************************************************************************************************
-
February 2nd, 2005, 05:15 PM
#12
Junior Member
I understand the need to make this appear prior to login, but I thought you might still find it helpful. We attempted to implement the type of message you are suggesting a couple of years ago, but it was shot down by our Vice President. I guess our internal Legal Council decided that our employee handbook already covers this stuff and that this message was not necessary. (I've been unable to find any such wording in the handbook.)
-
February 2nd, 2005, 05:18 PM
#13
Member
I got the wording part down...I just need to get the messege to appear b4 they log in.
-
February 2nd, 2005, 05:29 PM
#14
Member
Thank you very much.
I don't mean to appear dumb I am sorry I don't know much about VB or any type of scripting for that matter. But can you tell me if it appears before or after you login and can the password be encrypted? Or perhaps the script itself? Does the script run on the desktop or does it force AD changes to the desktop?
-
February 2nd, 2005, 06:16 PM
#15
Junior Member
Originally posted here by earthbound4u
Thank you very much.
I don't mean to appear dumb I am sorry I don't know much about VB or any type of scripting for that matter. But can you tell me if it appears before or after you login and can the password be encrypted? Or perhaps the script itself? Does the script run on the desktop or does it force AD changes to the desktop?
The window created by this login script would appear after login. What password are you wanting to encrypt? The windows domain authentication would be encrypted already. There are utilities available to encrypt vbscript files, though I have not personally used one. This script executes as a background process. The only visible indication that the script is running is the IE message window. It does not change anything on the desktop.
-
February 2nd, 2005, 10:44 PM
#16
Brentlea:
You use that as a login script.... Any clue what would happen if you ran it as a startup script....
I'm guessing you could spawn an instance if IE without statusbar etc. with a warning and a closewindow button and it would appear at startup. It should then sit there until the closewindow button is pressed which would allow the Press CTRL-ALT-DEL screen.... Or am I missing something here?
Don\'t SYN us.... We\'ll SYN you.....
\"A nation that draws too broad a difference between its scholars and its warriors will have its thinking done by cowards, and its fighting done by fools.\" - Thucydides
-
February 2nd, 2005, 11:05 PM
#17
Junior Member
Sounds reasonable to me. I've not worked with the start up scripts before, so I can't say for certain. It does appear, though that you could take the IE message window part of the script and use it as proposed. I'd be interested in knowing if anyone tries this and it works. I'll try it if I have the opportunity.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|