Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[green]
'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : http://www.thespidersparlor.com
' Copyright (c) 2003-2010
' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
' Maps and disconnects drives and printers
'
'==========================================================================[/green]
ON ERROR RESUME NEXT
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
[green]'Automatically grab the user's domain name[/green]
DomainString = Wshnetwork.UserDomain
[green]'Find the Windows Directory[/green]
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
[green]'Grab the user name[/green]
UserString = WSHNetwork.UserName
[green]'Bind to the user object to get user name and check for group memberships later[/green]
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
[green]'Grab the computer name for use in add-on code later[/green]
strComputer = WSHNetwork.ComputerName
[green]'Disconnect any drive mappings as needed.[/green]
WSHNetwork.RemoveNetworkDrive "F:", True, True
[green]'Disconnect ALL mapped drives[/green]
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next
[green]'Give the PC time to do the disconnect, wait 300 milliseconds[/green]
wscript.sleep 300
[green]'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.[/green][blue]
'Note alternate mapping code in Add-In section that allows
'friendly renaming of drive mappings
WSHNetwork.MapNetworkDrive "H:", "\\server\users\" & UserString,True
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
WSHNetwork.MapNetworkDrive "X:", "\\server\executables",True
'Map a shared drive to a resource that requires separate username and password
WSHNetwork.MapNetworkDrive "Y:", "\\servername\share", "False", "username", "password"
[/blue]
[green]'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.[/green]
For Each GroupObj In UserObj.Groups
[green]'Force upper case comparison of the group names, otherwise this is case sensitive.[/green]
Select Case UCase(GroupObj.Name)[green]
'Check for group memberships and take needed action
'In this example below, ADMIN and WORKERB are groups.
'Note the use of all upper case letters as mentioned above.
'Note also that the groups must be Global Groups.[/green]
Case "ADMIN"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
Case "WORKERB"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True[green]
'Below is an example of how to set the default printer[/green]
WSHNetwork.SetDefaultPrinter "\\ServerName\PrinterName"
End Select
Next
[green]
'Remove ALL old printers
'Enumerate all printers first, after that you can select the printers you want by performing some string checks[/green]
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2[green]
'To remove only networked printers use this If Statement[/green]
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
End If[green]
'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[/green]
Next
[green]
'Remove a specific printer[/green]
WSHNetwork.RemovePrinterConnection "\\ServerOld\HP5si",True,True
[green]
'Install A Printer[/green]
WSHNetwork.AddWindowsPrinterConnection "\\Server\HP5si"
[red]
'Add On Code goes below this line
'=====================================
'=====================================
'Add On Code goes above this line[/red]
[green]
'Clean Up Memory We Used[/green]
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
[green]
'Quit the Script[/green]
wscript.quit
[green]' This code will empty the Temp Internet Files on Exit
'=====================================[/green]
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
[green]'This add on will rename the My Computer icon with the computer name[/green]
MCPath = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
WSHShell.RegWrite MCPath & "\", strComputer, "REG_SZ"
markdmac logged in at computername(192.168.13.13), logon server:SERVER Domain:root.domain.local
OldServer = "OLDSERVER"
NewServer = "NEWSERVER"
[green]
'Uncomment the next line for a standalone version of this script
'Set WSHNetwork = CreateObject("Wscript.Network")
' loop through printer connections[/green]
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
PrinterPath = UCase(WSHPrinters.Item(LOOP_COUNTER +1))[green]
'Check for the old server in the path[/green]
If InStr(3,PrinterPath,UCase(OldServer)) >0 Then[green]
'Replace the text[/green]
NewPrinterPath = Replace(PrinterPath, UCase(OldServer), UCase(NewServer))[green]
'Map the new printer[/green]
WSHNetwork.AddWindowsPrinterConnection NewPrinterPath[green]
'Remove the old printer[/green]
WSHNetwork.RemovePrinterConnection PrinterPath, True, True
End If
Next
[green]
'Call the function to write the username and current date/time
'to our database table called loginRecorder, with the fields
'user_name (VARCHAR) and login_date (DATETIME).[/green]
RecordLogin userString
Function RecordLogin(strUserName)
Dim dbConnection
Set dbConnection = CreateObject("ADODB.Connection")
dbConnection.Open "Provider=SQLOLEDB.1;Data Source=[red]myServerName[/red];Initial Catalog=[red]myDatabaseName[/red]";[red]"myUserName"[/red];[red]"myPassword"[/red]
dbConnection.Execute "INSERT INTO loginRecorder (user_name, login_date) VALUES ('" & strUserName & "'," & Now() &")"
Set dbConnection = Nothing
End Function
[green]
'Call the function to write the username and current date/time
'to our database table called loginRecorder, with the fields
'user_name (VARCHAR), computer_name (VARCHAR) and login_date (DATETIME).[/green]
RecordLogin userString, strComputer
Function RecordLogin(strUserName, strComputerName)
Dim dbConnection
Set dbConnection = CreateObject("ADODB.Connection")
dbConnection.Open "Provider=SQLOLEDB.1;Data Source=[red]myServerName[/red];Initial Catalog=[red]myDatabaseName[/red]";[red]"myUserName"[/red];[red]"myPassword"[/red]
dbConnection.Execute "INSERT INTO loginRecorder (user_name, computer_name, login_date) VALUES ('" & strUserName & "','" & strComputerName & "'," & Now()& ")"
Set dbConnection = Nothing
End Function