Created
May 26, 2012 07:28
-
-
Save theagreeablecow/2792772 to your computer and use it in GitHub Desktop.
Network Printers App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta http-equiv="Content-Language" content="en-us"> | |
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> | |
<!-- Printer Installation --> | |
<title>Printers App</title> | |
<HTA:APPLICATION ID="PrintHta" | |
BORDER="yes" | |
BORDERSTYLE="complex" | |
CAPTION="Network Printer Setup" | |
CONTEXTMENU="yes" | |
INNERBORDER="no" | |
SCROLL="yes" | |
SYSMENU="yes" | |
SHOWINTASKBAR="yes" /> | |
<style type="text/css"> | |
body { | |
margin="10"; | |
background="FFF"; | |
font-family="Verdana, Arial, Sans"; | |
font-size=0.8em; | |
} | |
p.legend { | |
background:#CBD8E9; | |
color:black; | |
padding:.2em .3em; | |
font-size:1.2em; | |
border:2px outset #CBD8E9; | |
position:relative; | |
margin-bottom:-0.7em; | |
width:11em; | |
margin-left:1em; | |
margin-top:1em | |
} | |
#printers { | |
background-color: #ECECEC; | |
border-color: #7A003B; | |
border-style: dashed; | |
border-width: 1px; | |
padding: 1.1em; | |
width: 100%; | |
} | |
#printers2 { | |
background-color: #ECECEC; | |
border-color: #7A003B; | |
border-style: dashed; | |
border-width: 1px; | |
padding: 1.1em; | |
width: 100%; | |
font-family="Lucida Console"; | |
} | |
#printers label { | |
position:absolute; | |
font-size:90%; | |
padding-top:.2em; | |
left:20px | |
} | |
#printers input { | |
margin-left:3em; | |
line-height:1.4em; | |
margin-bottom:.2em; | |
} | |
#printers select { | |
margin-left:1em; | |
line-height:1.4em; | |
margin-bottom:.2em; | |
font-size:1em; | |
} | |
#addprint input { | |
background:#ECECEC; | |
font-family="Verdana, Arial, Sans"; | |
font-size=1.0em; | |
} | |
#footer { | |
clear: both; | |
display: block; | |
margin: 35px auto auto auto; | |
} | |
#footer p { | |
color: #C2C2C2; | |
font-size: 0.8em; | |
} | |
</style> | |
</head> | |
<!----- START VB Scripting ------> | |
<SCRIPT Language="VBScript"> | |
' Name: PrintersSetup.hta | |
' Description: App to allow easy user management of network printers | |
' Author: TheAgreeableCow | |
On Error Resume Next | |
Dim strComputer, strPrintServer, strDefaultPrinter, intOffice, arrPrinters, strLOG, sResultsFile | |
Dim WshNetwork : Set WshNetwork = CreateObject("WScript.Network") | |
Sub Window_OnLoad | |
PageLoad | |
End Sub | |
'Set the variables to the default values | |
'--------------------------------------- | |
Sub PageLoad | |
on error resume next | |
'resize and center window | |
sizeandcenter | |
'Reset Fields and Checkboxes | |
strComputer = "." | |
strPrintServer = "" | |
strDefaulPrinter = "" | |
reinstall.checked = true | |
clean.checked = false | |
lh.checked = false | |
bw.checked = false | |
colour.checked = false | |
scan.checked = false | |
copier.checked = false | |
lbl.checked = false | |
'Load user info for default printer and location | |
LookupDefaultPrinter | |
AutoPrintServer | |
End Sub | |
' Resize and center HTA window | |
'----------------------------- | |
sub sizeandcenter | |
strComputer = "." | |
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") | |
Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor") | |
For Each objItem in colItems | |
intHorizontal = objItem.ScreenWidth | |
intVertical = objItem.ScreenHeight | |
Next | |
intLeft = (intHorizontal - 800) / 2 | |
intTop = (intVertical - 1020) / 2 | |
window.resizeTo 800,1020 | |
window.moveTo intLeft, intTop | |
end sub | |
' Lookup DC to auto set Print Server | |
'----------------------------------- | |
sub AutoPrintServer | |
on error resume next | |
Set objDomain = GetObject("LDAP://rootDse") | |
objDC = objDomain.Get("dnsHostName") | |
if (InStr(objDC,"Melb")) then | |
printserver.value = "1" | |
OfficeMelb.checked = true | |
SetPrintServer | |
end if | |
if (InStr(objDC,"Syd")) then | |
printserver.value = "2" | |
OfficeSyd.checked = true | |
SetPrintServer | |
end if | |
if (InStr(objDC,"Bris")) then | |
printserver.value = "3" | |
OfficeBris.checked = true | |
SetPrintServer | |
end if | |
if (InStr(objDC,"Perth")) then | |
printserver.value = "4" | |
OfficePerth.checked = true | |
SetPrintServer | |
end if | |
end sub | |
'Load Printers based on selection of Print Server | |
'------------------------------------------------ | |
Sub SetPrintServer | |
on error resume next | |
Dim arrPrinters, strPrintServer, strPrinter, intOffice, strInfo, arrFilters | |
dim objShell, objExecObject, strCommand, strResults, arrResults, arrResults2, strCount, strHTML, FilterArray, FilterOffice | |
Dim colChkElem : Set colChkElem = window.document.getElementsByTagName("input") | |
Dim objChkBox, keyPrinter, keyPrinters, keyString, arrKeywords | |
'Load user selection from form | |
Select Case PrintServer.Value | |
Case "1" | |
intOffice=1 | |
strPrintServer = "print1" | |
Case "2" | |
intOffice=2 | |
strPrintServer = "print2" | |
Case "3" | |
intOffice=3 | |
strPrintServer = "print7" | |
Case "4" | |
intOffice=4 | |
strPrintServer = "print8" | |
End Select | |
'Update some info fields | |
DataAreaR1.InnerHTML = "" | |
if strPrintServer = "melbprint" then | |
DataAreaS2.InnerHTML = "<font color='red'>No status information for " & strPrintServer & "</font>" | |
else | |
DataAreaS2.InnerHTML = "<A href='http://" & strPrintServer & "/printers/'>Show Live status for " & strPrintServer & "</A>" | |
end if | |
'Returns an array of shared items located on print server | |
Set objShell = CreateObject("WScript.Shell") | |
strCommand = "net view \\" & strPrintServer | |
strResults="" | |
Set objExecObject = objShell.Exec(strCommand) | |
Do | |
Loop Until objExecObject.Status <> 0 | |
strResults = objExecObject.StdOut.ReadAll() | |
'Define Office Filters | |
FilterOffice = "" | |
if OfficeMelb.checked = true then | |
FilterOffice = FilterOffice & "MELBOURNE " | |
end if | |
if OfficeSyd.checked = true then | |
FilterOffice = FilterOffice & "SYDNEY " | |
end if | |
if OfficeBris.checked = true then | |
FilterOffice = FilterOffice & "BRISBANE " | |
end if | |
if OfficePerth.checked = true then | |
FilterOffice = FilterOffice & "PERTH " | |
end if | |
FilterOffice = RTrim(FilterOffice) | |
'---- ADD CHECKBOXES FOR AVAILABLE and FILTERED PRINTERS ------ | |
'Parse list for printers | |
arrResults=Split(strResults, vbCrLf) | |
arrResults2=Split(strResults, vbCrLf) | |
strResults="" | |
for i=0 to UBound(arrResults) | |
if Instr(1,arrResults(i),FilterOffice)>0 then strResults=strResults & Trim(Left(arrResults(i), InStr(1,arrResults(i),"Print")-1)) & vbCrLf | |
next | |
strResults=Left(strResults, Len(strResults)-2) | |
arrPrinters=Split(strResults, vbCrLf) | |
'Add count info to status | |
strCount = UBound(arrPrinters)+1 & " printers found on server " & strPrintServer | |
if UBound(arrPrinters) = "0" then | |
DataAreaI1.InnerHTML = "<font color='red'>No Printers found on " & strPrintServer & "</font>" | |
else | |
DataAreaI1.InnerHTML = "<font color='orange'>" & strCount & ". Ready to install...</font>" | |
DataAreaR1.InnerHTML = "<font color='orange'>" & strCount & "</font>" | |
End If | |
'Add checkboxes (with padded monospaced labels) | |
for each strPrinter in arrPrinters | |
padPrinter = strPrinter & Replace(String(20-(Len(strPrinter)),"X"),"X"," ") | |
if strPrintServer = "melbprint" then | |
strHTML = strHTML & "<input type=""checkbox"" name=" & strPrinter & ">" & padPrinter | |
else | |
strHTML = strHTML & "<input type=""checkbox"" name=" & strPrinter & ">" & "<A href='http://" & strPrintServer & "/printers/ipp_0004.asp?view=q&eprinter=" & strPrinter & "'style='text-decoration : none'>" & padPrinter & "</A>" | |
end if | |
next | |
DataAreaP2.InnerHTML = strHTML | |
'---- FILTERING ------ | |
'Find Keyword Matches (criteria to only show checkbox AND keyword matches) | |
if lh.checked = true then | |
keyString = keyString & "#LH " | |
end if | |
if bw.checked = true then | |
keyString = keyString & "#BW " | |
end if | |
if colour.checked = true then | |
keyString = keyString & "#COLOUR " | |
end if | |
if scan.checked = true then | |
keyString = keyString & "#SCAN " | |
end if | |
if copier.checked = true then | |
keyString = keyString & "#COPY " | |
end if | |
if lbl.checked = true then | |
keyString = keyString & "#LABEL " | |
end if | |
'Combine Keywords with Checkbox values to form single array | |
keyString = keyString & keyword.value | |
'Apply upper case, replace any commas, trim and seperate to array | |
KeyString = UCase(KeyString) | |
KeyString = Replace(KeyString,","," ") | |
keyString = RTrim(keyString) | |
arrKeywords=Split(KeyString) | |
'Parse for Matches of each Keyword | |
for a=0 to UBound(arrKeywords) | |
keyPrinters = "" | |
for i=0 to UBound(arrResults2) | |
if not Instr(1,arrResults2(i),arrKeywords(a))>0 then keyPrinters=keyPrinters & Trim(Left(arrResults2(i), InStr(1,arrResults2(i),"Print")-1)) & vbCrLf | |
next | |
keyPrinters=Left(keyPrinters, Len(keyPrinters)-2) | |
keyPrinters=Split(keyPrinters, vbCrLf) | |
'Update info | |
DataAreaR1.InnerHTML = "<font color='green'>Checkboxes are displayed for " & FilterOffice & " printers that match the search '" & keyString & "'</font>" | |
'Show keyword matches | |
for each keyPrinter in keyPrinters | |
For Each objChkBox In colChkElem | |
if objChkBox.name = keyPrinter Then | |
objChkBox.style.visibility="hidden" | |
end if | |
next | |
next | |
next | |
'---- UPDATE REST OF FORM ------ | |
'Enable Check boxes for printers already installed | |
ShowMyPrinters | |
'Add Default printer to dropbox | |
LoadDefaultPrinters strPrintServer,arrPrinters | |
'Info Checks | |
CheckLegacyPrinters | |
CheckFarPrinters | |
CheckOfflinePrinters | |
End Sub | |
'Enable checkboxes for Printers already installed | |
'------------------------------------------------ | |
sub showmyprinters | |
on error resume next | |
Dim objWMIService, objItem, colItems, strComputer, intPrinters | |
Dim colChkElem : Set colChkElem = window.document.getElementsByTagName("input") | |
Dim objChkBox | |
intPrinters = 1 | |
strComputer = "." | |
'Get list of my printers | |
Set objWMIService = GetObject _ | |
("winmgmts:\\" & strComputer & "\root\CIMV2") | |
Set colItems = objWMIService.ExecQuery _ | |
("SELECT * FROM Win32_Printer") | |
'Enable checkboxes if there's a name match | |
For Each objItem In colItems | |
For Each objChkBox In colChkElem | |
If objChkBox.Type = "checkbox" Then | |
if objChkBox.style.visibility <> "hidden" then | |
if (InStr(objItem.name,objChkBox.Name)) then | |
objChkBox.checked = true | |
end if | |
end if | |
end if | |
next | |
next | |
end sub | |
'Load Default Printer | |
'--------------------- | |
sub LoadDefaultPrinters(strPrintServer,arrPrinters) | |
on error resume next | |
dim objOption | |
ClearDefaultPrinters | |
'Load Available Printers from selected Print Server | |
for each strPrinter in arrPrinters | |
Set objOption = Document.createElement("OPTION") | |
objOption.Text = strPrinter | |
objOption.Value = "\\" & strPrintServer & "\" & strPrinter | |
DefaultPrinter.Add(objOption) | |
Next | |
end sub | |
'onClick "Install Now!" | |
'---------------------- | |
Sub Apply | |
on error resume next | |
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network") | |
DataAreaI1.InnerHTML = "<font color='orange'>Update in progress, please wait...</font>" | |
DataAreaI2.innerHTML = "<font color='orange'>Update in progress, please wait...</font>" | |
DataAreaI3.innerHTML = "<font color='orange'>Update in progress, please wait...</font>" | |
DataAreaI4.innerHTML = "<font color='orange'>Update in progress, please wait...</font>" | |
CurrentDefaultPrinter = DefaultPrinter.value | |
'Clean all Network Printers if requested (including these legacy print servers) | |
if clean.checked = true then | |
DataAreaI1.InnerHTML = "<font color='orange'>Installing and cleaning, please wait...</font>" | |
dim xPrintServer, AllPrintServerArray(7) | |
AllPrintServerArray(0) = "\\melbprint\" | |
AllPrintServerArray(1) = "\\sydprint\" | |
AllPrintServerArray(2) = "\\brisprint\" | |
AllPrintServerArray(3) = "\\perthprint\" | |
AllPrintServerArray(4) = "\\print1\" | |
AllPrintServerArray(5) = "\\print2\" | |
AllPrintServerArray(6) = "\\print7\" | |
AllPrintServerArray(7) = "\\print8\" | |
For x = 0 to 7 | |
xPrintServer = AllPrintServerArray(x) | |
DeleteNetworkPrinters xPrintServer | |
next | |
end if | |
'Reinstall Original Default (ignore if local) | |
if (InStr(CurrentDefaultPrinter,"\\")) then | |
objNetwork.AddWindowsPrinterConnection CurrentDefaultPrinter | |
end if | |
'Install Printers | |
setTimeout "InstallPrinters",10 | |
End Sub | |
'Install Printers and write to log file | |
'-------------------------------------- | |
Sub InstallPrinters | |
on error resume next | |
Dim colChkElem : Set colChkElem = window.document.getElementsByTagName("input") | |
Dim objChkBox, strPrintServer | |
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network") | |
'Log File | |
const HKEY_LOCAL_MACHINE = &H80000002 | |
Const HKEY_CURRENT_USER = &H80000001 | |
const forreading = 1, forwriting = 2, forappending = 8 | |
sResultsFile = "\\server1\Printers\" & objNetwork.UserName & ".log" | |
Dim oFileSys, fResults | |
Set oFileSys = CreateObject("Scripting.FileSystemObject") | |
If oFileSys.FileExists(sResultsFile) Then | |
Set fResults = oFileSys.OpenTextFile(sResultsFile, ForAppending) | |
Else | |
Set fResults = oFileSys.CreateTextFile(sResultsFile, True) | |
End If | |
fResults.WriteLine "------------------------------------" | |
fResults.WriteLine Now & " - " & objNetwork.UserName & " - " & objNetwork.ComputerName | |
' Load info from user selection | |
Select Case PrintServer.Value | |
Case "1" | |
intOffice=1 | |
strPrintServer = "\\print1\" | |
Case "2" | |
intOffice=2 | |
strPrintServer = "\\print2\" | |
Case "3" | |
intOffice=3 | |
strPrintServer = "\\print7\" | |
Case "4" | |
intOffice=4 | |
strPrintServer = "\\print8\" | |
End Select | |
'Warn if a Server is not selected | |
If intOffice = "" Then | |
MsgBox "Please select a Print Server", vbExclamation+vbOKOnly, "oops!" | |
DataAreaI1.InnerHTML = "<font color='red'>Waiting for Print Server selection...</font>" | |
Exit Sub | |
End If | |
'Install each checked printer | |
For Each objChkBox In colChkElem | |
If objChkBox.Type = "checkbox" Then | |
If objChkBox.checked Then | |
If reinstall.checked = false Then | |
objNetwork.RemovePrinterConnection strPrintServer & objChkBox.name | |
end if | |
objNetwork.AddWindowsPrinterConnection strPrintServer & objChkBox.name | |
if InStr("reinstall",objChkBox.name) = "0" and InStr("clean",objChkBox.name) = "0" then | |
fResults.WriteLine "Installed: " & strPrintServer & objChkBox.name | |
end if | |
End If | |
end if | |
Next | |
'Set New Default Printer if requested | |
SetDefaultPrinter | |
'Update Info | |
ClearDefaultPrinters | |
CheckLegacyPrinters | |
CheckFarPrinters | |
CheckOfflinePrinters | |
DataAreaI1.InnerHTML = "<font color='green'>Setup complete!</font>" | |
'log | |
fResults.WriteLine "Skip Reinstall = " & reinstall.checked | |
fResults.WriteLine "PC Clean Up = " & clean.checked & vbCrLf | |
fResults.close | |
End Sub | |
' ############## MISC SUB ROUTINES ################# | |
'Update office filter based on user changing print server | |
'-------------------------------------------------------- | |
sub SetOfficeFilter | |
Select Case PrintServer.Value | |
Case "1" | |
OfficeMelb.checked = true | |
OfficeSyd.checked = false | |
OfficeBris.checked = false | |
OfficePerth.checked = false | |
Case "2" | |
OfficeSyd.checked = true | |
OfficeMelb.checked = false | |
OfficeBris.checked = false | |
OfficePerth.checked = false | |
Case "3" | |
OfficeBris.checked = true | |
OfficeSyd.checked = false | |
OfficeMelb.checked = false | |
OfficePerth.checked = false | |
Case "4" | |
OfficePerth.checked = true | |
OfficeSyd.checked = false | |
OfficeBris.checked = false | |
OfficeMelb.checked = false | |
End Select | |
SetPrintServer | |
end sub | |
'Keep office filters unique (would normally use radio buttons, but they can't be dynamically assigned) | |
'----------------------------------------------------------------------------------------------------- | |
sub chkMelb | |
OfficeSyd.checked = false | |
OfficeBris.checked = false | |
OfficePerth.checked = false | |
end sub | |
sub chkSyd | |
OfficeMelb.checked = false | |
OfficeBris.checked = false | |
OfficePerth.checked = false | |
end sub | |
sub chkPerth | |
OfficeSyd.checked = false | |
OfficeBris.checked = false | |
OfficeMelb.checked = false | |
end sub | |
sub chkBris | |
OfficeSyd.checked = false | |
OfficeMelb.checked = false | |
OfficePerth.checked = false | |
end sub | |
'Clear Keyword | |
'------------- | |
sub clearkeyword | |
keyword.style.color="black" | |
keyword.value = "" | |
end sub | |
'Clean PC (delete old network printers) | |
'-------------------------------------- | |
sub DeleteNetworkPrinters(PrintServer) | |
on error resume next | |
dim objNetwork : Set objNetwork = CreateObject("WScript.Network") | |
dim checkPrinters : Set checkPrinters = objNetwork.EnumPrinterConnections | |
dim printer | |
For each Printer in checkPrinters | |
if(InStr(Printer,PrintServer)) then | |
objNetwork.RemovePrinterConnection Printer | |
end if | |
next | |
End sub | |
'Clear Default Printer | |
'--------------------- | |
Sub ClearDefaultPrinters | |
on error resume next | |
'Remove All Items | |
For Each objOption in DefaultPrinter.Options | |
objOption.RemoveNode | |
Next | |
'Add current default back into list | |
LookupDefaultPrinter | |
End Sub | |
'Look up Default Printer | |
'-------------------- | |
sub LookupDefaultPrinter | |
on error resume next | |
'Lookup Default Printer | |
strComputer = "." | |
Set objWMIService = GetObject("winmgmts:" _ | |
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") | |
Set colInstalledPrinters = objWMIService.ExecQuery _ | |
("Select * from Win32_Printer where Default = 'True'") | |
'Add Printer Info | |
For Each objPrinter in colInstalledPrinters | |
'Info Line | |
DataArea2.InnerHTML = "<font color='green'>" & objPrinter.Name & "</font>" | |
'Drop List | |
Set objOption = Document.createElement("OPTION") | |
objOption.Text = objPrinter.Name | |
objOption.Value = objPrinter.Name | |
DefaultPrinter.Add(objOption) | |
Next | |
end sub | |
'Set Default Printer | |
'------------------- | |
sub SetDefaultPrinter | |
on error resume next | |
'Set Default printer | |
NewDefaultPrinter = DefaultPrinter.value | |
WshNetwork.SetDefaultPrinter NewDefaultPrinter | |
'Update Info | |
LoadDefaultPrinters | |
end sub | |
'Open Printer Control Panel | |
'-------------------------- | |
sub myprinters | |
on error resume next | |
Set objShell = CreateObject("WScript.Shell") | |
strCommand = "control printers" | |
objShell.Exec(strCommand) | |
end sub | |
'Check for Legacy Printers | |
'------------------------- | |
sub CheckLegacyPrinters | |
on error resume next | |
dim objNetwork : Set objNetwork = CreateObject("WScript.Network") | |
dim checkPrinters : Set checkPrinters = objNetwork.EnumPrinterConnections | |
dim LegacyAlert, oldPrinter, newPrinter, OldPrintServerArray(3) | |
LegacyAlert = "N" | |
OldPrintServerArray(0) = "\\melbprint\" | |
OldPrintServerArray(1) = "\\sydprint\" | |
OldPrintServerArray(2) = "\\brisprint\" | |
OldPrintServerArray(3) = "\\perthprint\" | |
'Check to see if any install printers are from old servers | |
For x = 0 to 3 | |
OldPrintServer = OldPrintServerArray(x) | |
For each newPrinter in checkPrinters | |
if (InStr(newPrinter,OldPrintServer)) then | |
LegacyAlert = "Y" | |
OldPrinter = OldPrinter & newPrinter & " " | |
end if | |
next | |
next | |
'Update info section | |
if LegacyAlert = "Y" then | |
DataAreaI2.InnerHTML = "<font color='red'>" & OldPrinter & "found. Consider selecting newer printers and tick the 'PC Clean Up' option.</font>" | |
else | |
DataAreaI2.InnerHTML = "<font color='Green'>OK! No old printers found.</font>" | |
end if | |
end sub | |
'Check for Interstate Printers | |
'----------------------------- | |
sub CheckFarPrinters | |
on error resume next | |
dim objNetwork : Set objNetwork = CreateObject("WScript.Network") | |
dim checkPrinters : Set checkPrinters = objNetwork.EnumPrinterConnections | |
dim objDomain : Set objDomain = GetObject("LDAP://rootDse") | |
objDC = objDomain.Get("dnsHostName") | |
dim newPrinter, MelbServer, SydServer, BrisServer, PerthServer, FarAlert, FarPrinter, HostName | |
MelbServer = "\\print1\" | |
SydServer = "\\print2\" | |
BrisServer = "\\print7\" | |
PerthServer = "\\print8\" | |
FarAlert = "N" | |
HostName = objNetwork.ComputerName | |
'Get user location from DC name and look for any interstate Printers (ignore XenRA's) | |
if (InStr(HostName,"XEN")) then | |
FarAlert = "XEN" | |
else | |
if (InStr(objDC,"Melb")) then | |
For each newPrinter in checkPrinters | |
if (InStr(newPrinter,SydServer)) or (InStr(newPrinter,BrisServer)) or (InStr(newPrinter,PerthServer)) then | |
FarAlert = "Y" | |
FarPrinter = FarPrinter & newPrinter & " " | |
end if | |
next | |
end if | |
if (InStr(objDC,"Syd")) then | |
For each newPrinter in checkPrinters | |
if (InStr(newPrinter,MelbServer)) or (InStr(newPrinter,BrisServer)) or (InStr(newPrinter,PerthServer)) then | |
FarAlert = "Y" | |
FarPrinter = FarPrinter & newPrinter & " " | |
end if | |
next | |
end if | |
if (InStr(objDC,"Bris")) then | |
For each newPrinter in checkPrinters | |
if (InStr(newPrinter,SydServer)) or (InStr(newPrinter,MelbServer)) or (InStr(newPrinter,PerthServer)) then | |
FarAlert = "Y" | |
FarPrinter = FarPrinter & newPrinter & " " | |
end if | |
next | |
end if | |
if (InStr(objDC,"Perth")) then | |
For each newPrinter in checkPrinters | |
if (InStr(newPrinter,SydServer)) or (InStr(newPrinter,BrisServer)) or (InStr(newPrinter,MelbServer)) then | |
FarAlert = "Y" | |
FarPrinter = FarPrinter & newPrinter & " " | |
end if | |
next | |
end if | |
end if | |
'Update info section | |
if FarAlert = "XEN" then | |
DataAreaI3.InnerHTML = "<font color='orange'>Not applicable for remote sessions</font>" | |
elseif FarAlert = "Y" then | |
DataAreaI3.InnerHTML = "<font color='red'>" & FarPrinter & "found. Consider selecting the 'PC Clean Up' option.</font>" | |
else | |
DataAreaI3.InnerHTML = "<font color='Green'>OK! No installed printers found from other offices.</font>" | |
end if | |
end sub | |
'Check for Offline Printers | |
'-------------------------- | |
sub CheckOfflinePrinters | |
on error resume next | |
Dim objWMIService, objItem, colItems, strComputer, intPrinters, OfflineAlert, AlertPrinter | |
Dim strPrintServer, MelbServer, SydServer, BrisServer, PerthServer | |
intPrinters = 1 | |
strComputer = "." | |
'Look up printer status | |
Set objWMIService = GetObject _ | |
("winmgmts:\\" & strComputer & "\root\CIMV2") | |
Set colItems = objWMIService.ExecQuery _ | |
("SELECT * FROM Win32_Printer") | |
For Each objItem In colItems | |
if objItem.PrinterStatus <> "3" then | |
OfflineAlert = "Y" | |
AlertPrinter = AlertPrinter & objItem.name & " " | |
end if | |
next | |
'Get print server with issues | |
MelbServer = "print1" | |
SydServer = "print2" | |
BrisServer = "print7" | |
PerthServer = "print8" | |
if (InStr(AlertPrinter,MelbServer)) then | |
strPrintServer = MelbServer | |
elseif (InStr(AlertPrinter,SydServer)) then | |
strPrintServer = SydServer | |
elseif (InStr(AlertPrinter,BrisServer)) then | |
strPrintServer = BrisServer | |
elseif(InStr(AlertPrinter,PerthServer)) then | |
strPrintServer = PerthServer | |
end if | |
'Update info section | |
if OfflineAlert = "Y" then | |
DataAreaI4.InnerHTML = "<font color='red'>" & AlertPrinter & "may have issues. Check </font>" & "<A href='http://" & strPrintServer & "/printers/'>LIVE info for " & strPrintServer & "</A>" | |
else | |
DataAreaI4.InnerHTML = "<font color='Green'>OK! All installed printers are ready.</font>" | |
end if | |
end sub | |
'Help message box for searching | |
'------------------------------ | |
sub SearchHelp | |
msgbox "Tick a feature (eg Colour) and/or a keyword (eg Law or 29)" & VbCr & VbCr & _ | |
"Search results are cumulative. That is, all matches will be show" & VbCr & VbCr & _ | |
"Your nearest print server and office should be selected automatically." & VbCr & VbCr & _ | |
"Only 'Print1' has printers from all other offices. This is the best choice for Remote Access users (where you can then search your selected office.", vbQuestion+vbOKOnly, "Help!" | |
end sub | |
' Get Complete Printer Info | |
'-------------------------- | |
sub AllPrinterInfo | |
on error resume next | |
Dim objWMIService, objItem, colItems, strComputer, intPrinters | |
intPrinters = 1 | |
strComputer = "." | |
Set objWMIService = GetObject _ | |
("winmgmts:\\" & strComputer & "\root\CIMV2") | |
Set colItems = objWMIService.ExecQuery _ | |
("SELECT * FROM Win32_Printer") | |
For Each objItem In colItems | |
msgbox objItem.name & VbCr & _ | |
"====================================" & VbCr & _ | |
"Availability: " & objItem.Availability & VbCr & _ | |
"Description: " & objItem.Description & VbCr & _ | |
"Comments: " & objItem.Comment & VbCr & _ | |
"Printer: " & objItem.DeviceID & VbCr & _ | |
"Driver Name: " & objItem.DriverName & VbCr & _ | |
"Port Name: " & objItem.PortName & VbCr & _ | |
"Printer State: " & objItem.PrinterState & VbCr & _ | |
"Printer Status: " & objItem.PrinterStatus & VbCr & _ | |
"PrintJobDataType: " & objItem.PrintJobDataType & VbCr & _ | |
"Print Processor: " & objItem.PrintProcessor & VbCr & _ | |
"Spool Enabled: " & objItem.SpoolEnabled & VbCr & _ | |
"Separator File: " & objItem.SeparatorFile & VbCr & _ | |
"Queued: " & objItem.Queued & VbCr & _ | |
"Status: " & objItem.Status & VbCr & _ | |
"StatusInfo: " & objItem.StatusInfo & VbCr & _ | |
"Published: " & objItem.Published & VbCr & _ | |
"Shared: " & objItem.Shared & VbCr & _ | |
"ShareName: " & objItem.ShareName & VbCr & _ | |
"Direct: " & objItem.Direct & VbCr & _ | |
"Location: " & objItem.Location & VbCr & _ | |
"Priority: " & objItem.Priority & VbCr & _ | |
"Work Offline: " & objItem.WorkOffline & VbCr & _ | |
"Horizontal Res: " & objItem.HorizontalResolution & VbCr & _ | |
"Vertical Res: " & objItem.VerticalResolution & VbCr & _ | |
"" | |
intPrinters = intPrinters + 1 | |
Next | |
end sub | |
</SCRIPT> | |
<!----- START PAGE BODY ------> | |
<body> | |
<IMG SRC="Printer.jpg" ALT="Printer App" ALIGN=LEFT> | |
<IMG SRC="Header.jpg" ALT="Company Logo" ALIGN=RIGHT><br /> | |
<h3><CENTER><font face="verdana, arial">Setup My Network Printers</font></CENTER></h3><br /><br /> | |
<p class="legend">1. Print Server</p> | |
<div id="printers"> | |
<span id = "DataAreaS1"></span>Your recommended print server is | |
<select size="1" name="PrintServer" style="width:200" onChange="SetOfficeFilter"> | |
<option value="">Print Server...</option> | |
<option value="1">Print1 (Melb/National)</option> | |
<option value="2">Print2 (Sydney)</option> | |
<option value="3">Print7 (Brisbane)</option> | |
<option value="4">Print8 (Perth)</option> | |
<option value="5">MelbPrint (Old)</option> | |
</select> <span id = "DataAreaS2"></span> | |
<p style="font-size:0.9em;"> | |
<IMG SRC="search.gif" ALT="Click for help on searching" ALIGN=Left onClick="SearchHelp"> | |
<input type="checkbox" name="lh" value="1">Letter Head | |
<input type="checkbox" name="bw" value="1">B/W | |
<input type="checkbox" name="colour" value="1">Colour | |
<input type="checkbox" name="scan" value="1">Scan/Email | |
<input type="checkbox" name="copier" value="1">Copier | |
<input type="checkbox" name="lbl" value="1">Labels | |
<br /><br /> | |
<input type="checkbox" name="OfficeMelb" value="1" onClick="chkMelb">Melb | |
<input type="checkbox" name="OfficeSyd" value="1" onClick="chkSyd">Syd | |
<input type="checkbox" name="OfficePerth" value="1" onClick="chkPerth">Perth | |
<input type="checkbox" name="OfficeBris" value="1" onClick="chkBris">Bris | |
<input type="text" name="keyword" size="15" ALT="Keyword eg Law or 29" onClick=clearkeyword> | |
<input id=refresh type="button" value="Search!" name="refresh" onClick="SetPrintServer"> | |
</p> | |
</div> | |
<p class="legend">2. Available Printers</p> | |
<div id="printers2"> | |
<span id = "DataAreaP0"></span><font face="Verdana, Arial, Sans">Tick the printers you want to add (click a name for Live status)</font><br /> | |
<span id = "DataAreaP1"></span><br /> | |
<p style="font-size:0.9em;"> | |
<span id = "DataAreaP2"></span><br /><br /> | |
<font face="Verdana, Arial, Sans"><span id = "DataAreaR1"></font></span> | |
</p> | |
</div> | |
<p class="legend">3. Default Printer</p> | |
<div id="printers"> | |
<span id = "DataAreaD1"></span>Set your default printer | |
<select size="1" name="DefaultPrinter" style="width:200" onChange=""> | |
</select> | |
<p style="font-size:0.9em;"> | |
Current Printer: <span id = "DataArea2"></span> | |
</p> | |
</div> | |
<p class="legend">4. Options</p> | |
<div id="printers"> | |
<span id = "DataAreaO1"></span>Select any additional options | |
<p style="font-size:0.9em;"> | |
<input type="checkbox" name="reinstall" value="1">Skip printer install if I already have it (faster)<br /> | |
<input type="checkbox" name="clean" value="1">PC Clean Up (remove ALL other 'network' printers not selected above)<br /> | |
</p> | |
</div> | |
<div id="addprint"><br /> | |
<p> | |
<input type="button" value="Install Now!" name="AddPrinterButton" onClick=Apply> | |
<input type="button" value="View My Printers" name="MyPrinterButton" onClick=MyPrinters> | |
<input type="RESET" value="Reload Form" name"ResetButton" onClick=Location.Reload(True)> | |
<input type="button" value="Exit" name="ExitButton" onClick=self.close()> | |
</p> | |
<IMG SRC="info.jpg" ALT="Click for full info on each installed printer" ALIGN=LEFT onClick=AllPrinterInfo> | |
<p style="font-size:0.9em;"> | |
My Setup Status: <span id = "DataAreaI1"><font color='orange'>Waiting for selection...</font></span><br /> | |
Legacy Status: <span id = "DataAreaI2"><font color='orange'>Waiting for selection...</font></span><br /> | |
Intra-Office Status: <span id = "DataAreaI3"><font color='orange'>Waiting for selection...</font></span><br /> | |
My Printers' Status: <span id = "DataAreaI4"><font color='orange'>Waiting for selection...</font></span> | |
</p> | |
</div> | |
<div id="footer"> | |
<p>Please contact your Helpdesk via <A Href="mailto:[email protected]">email</A> or <A Href="http://helpdesk">web form</A> if your have any questions or issues.</p> | |
<p>Network Printers App Version 1.7 TheAgreeableCow</p> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment