' ********************************************************************* ' ' Name : Check Remote Print job size.vbs ' Author : 3Ds (UK) Limited ' Description : Example VBScript to check that the remote print jobs ' do not exceed a given size. ' ' Arguments : 1 - Server Name. ' 2 - Max. permitted job size (Kb, numeric). ' ' WIZARD:PARAMS=1 = Server Name or . for Local Machine|2 = Max. permitted job size (in Kb) ' WIZARD:PARAMEXAMPLE=MyServer 5000 ' ' Returns : 0 - OK, all print jobs are within limits. ' 1 - Parameter error. ' 2 - WMI error. ' 3 - Job size exceeds limit. ' ' WIZARD:RESULTS=Return code ...||0 = OK|1 = Parameter Error|2 = WMI error or script not supported on O/S|3 = One or more jobs exceeded limit.||Script output also indicates "OK" for success, or "Error" with details of the faults found. ' ' Notes : Requires Windows Scripting Host (for VBScript) & ' WMI installed. ' ' WIZARD:REMOTE ' ' ********************************************************************* ' Enable in-line error handling On Error Resume Next ' ------ Local declarations ------ Dim objArguments ' Command line arguments Dim objWMIService ' WMI object Dim objData ' Data object Dim strServer ' The server on which the shared drive is held Dim strData ' The data name Dim colData ' Data collection Dim blnFoundItem ' True if we found an entry Dim intResult ' Result Dim intMaxSize ' Max. size to check for ' ------ Main Logic ------ ' Default the answer intResult = 0 ' Retrieve Parameters, server name Set objArguments = WScript.Arguments strServer = objArguments.Item(0) If Len (strServer) = 0 Then WScript.Echo "Error. Cannot verify print job size. No server name specified" WScript.Quit (1) End If ' Size intMaxSize = CInt(objArguments.Item(1)) If Err.number <> 0 Then Err.Clear() WScript.Echo "Error. Cannot verify print job size. Max. job size not specified, not numeric or 0" WScript.Quit (1) End If ' Connect to WMI Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServer & "\root\cimv2") If Err.Number <> 0 Then WScript.Echo "Error. Cannot connect to WMI." WScript.Echo Err.Description WScript.Quit (2) End If ' Get the status of each job Set colData = objWMIService.ExecQuery ("Select * from Win32_PrintJob") For Each objData in colData ' Get the size of the print If (objData.Size / 1024) > intMaxSize Then ' Job too big Wscript.Echo "Error. Print job " & objData.Document & ", submitted by " & objData.Owner & " exceeds the permitted size. Job size is " & Round ((objData.Size / 1024), 2) & "Kb" intResult = 3 End If Next If intResult = 0 Then Wscript.Echo "OK. All print job sizes are within permitted limits" End If ' ------ Cleanup & Return ------ Set colData = Nothing Set objData = Nothing Set objWMIService = Nothing WScript.Quit (intResult) ' ------ End of Script ------