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.
'****************************************************
'* Script by: John Fuhrman
'* Date: 2007, Nov 6
'*
'* Description:
'* This script connects to printers based on a users
'* branch number using a dictionary object. The
'* script also will not reconnect to an already
'* connected printer.
'*
'* The [red][b]strPrnServer[/b][/red] value will need to be set to
'* whatever your printer servers name or IP is.
'****************************************************
Option Explicit
Dim WSHShell: Set WSHShell = CreateObject("WScript.Shell")
Dim WSHNetwork: Set WSHNetwork = CreateObject("WScript.Network")
Dim fso: Set fso = CreateObject("scripting.filesystemobject")
'Grab the user name
Dim UserString: UserString = WSHNetwork.UserName
'strUser = objUser.Name
Dim strBranch: strBranch = (Left(UserString,3)) ' Grab the first 3 characters of the username
' If the user does not have a branch number prefix prompt for
' the user the the branch number.
If IsNumeric(strBranch) = False Then
Call UserPrompt() ' function sets the user bank#
Else
End If
Dim objDictPrnts: Set objDictPrnts = CreateObject("Scripting.Dictionary")
objDictPrnts.CompareMode = vbTextCompare
Dim strPrnServer: [red][b]strPrnServer[/b][/red] = "lxolcdprn01"
Dim objWMIService: Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strPrnServer & "\root\cimv2")
Dim colInstalledPrinters: Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
Dim objPrinter
For Each objPrinter in colInstalledPrinters
' create a dictionary to store our printer paths
Dim strBKtemp: strBKtemp = UCase(Mid(objPrinter.Name,1,3))
objDictPrnts.Add "\\" & strPrnServer & "\" & objPrinter.Name, UCase(Mid(objPrinter.Name,1,3))
Next
' loop through the path's that were not found and add them
Dim PrinterPath
For Each PrinterPath In objDictPrnts.Keys
Dim strBkPrinter: strBkPrinter = UCase(PrinterPath)
If objDictPrnts.Item(strBkPrinter) = strBranch Then
WSHNetwork.AddWindowsPrinterConnection PrinterPath
End If
Next
'*******************************************************
Function UserPrompt()
UserPrompt = InputBox("User's numeric prefix not identified." &_
vbcrlf & vbcrlf & "Enter the User's Branch Number.")
If UserPrompt = False Then Call UserError(1)
If UserPrompt = "" Then Call UserError(2)
strBranch = UserPrompt
End Function
'*******************************************************
Sub UserError(Error)
If Error = "1" Then MsgBox("Canceled")
If Error = "2" Then MsgBox("User's Branch Number not entered.")
WScript.Quit
End Sub
'*******************************************************