I have asked before...
I think the subject is a little more "descriptive" this time and I hope I can get the help
It's been quite a few months of on/off research and testing and now another month pretty much dedicated to frustration has passed by.
Object of script:
[ol][li]Pause Default Printer [/li]
[li]Start and run an "invoicing" application [/li]
[li]When app goes Idle - terminate app [/li]
[li]Scan \WINNT\system32\spool\PRINTERS\*.SPL files for specific "data" and delete those .SPL files - allocate a sleep value of .65 - .9 seconds per .SPL for search to complete (with progress display) [/li]
[li]Stop and Start Print Spooler service [/li]
[li]Refresh default printer queue display [/li]
[li]Un-pause default printer (if service is not restarted and queue not refreshed then event log will contain 1 error message for each item missing .SPL - assumes default print server event log options enabled) [/ol][/li]
Now where I get stuck and have been stuck it to be able to tell when this crappy VB application has gone idle (3) and the only way I see doing that is via WMI.
Using WMI I can get at the "Win32_PerfRawData_PerfOS_Processor" raw data performance counter class - specifically "PercentProcessorTime" ... but my question is: is this where the column in taskmanager labled "CPU" is derived from? This is the only value that seems to make sense after reading the WMI SDK for the past week.
I can't seem to figure out how get this info per process...
I used line items so you can easily see each line of code/script
[ol][li]strComputer = "."[/li]
[li]Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
[/li]
[li]Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_process"
[/li]
[li]For Each objProcess in colProcesses[/li]
[li] sngProcessTime = ( CSng(objProcess.KernelModeTime) + CSng(objProcess.UserModeTime)) / 10000000[/li]
[li] Wscript.echo objProcess.name & ": " & Round(sngProcessTime,2) & " Seconds"[/li]
[li]Next[/ol][/li]
I figured out how to get at the time column and convert it to seconds - WHOOPIE! I don't need that...
Then I found this while reading about WMI on MSDN:
[ol][li]Set objService = GetObject("Winmgmts:{impersonationlevel=impersonate}!\Root\Cimv2"
[/li]
[li]For i = 1 to 8[/li]
[li]Set objInstance1 = objService.Get("Win32_PerfRawData_PerfOS_Processor.Name='_Total'"
[/li]
[li]N1 = objInstance1.PercentProcessorTime[/li]
[li]D1 = objInstance1.TimeStamp_Sys100NS[/li]
[li]WScript.Sleep(2000)[/li]
[li]Set perf_instance2 = objService.get("Win32_PerfRawData_PerfOS_Processor.Name='_Total'"
[/li]
[li]N2 = perf_instance2.PercentProcessorTime[/li]
[li]D2 = perf_instance2.TimeStamp_Sys100NS[/li]
[li]PercentProcessorTime = (1 - ((N2 - N1)/(D2-D1)))*100[/li]
[li]WScript.Echo "% Processor Time=" , Round(PercentProcessorTime,2)[/li]
[li]Next[/ol][/li]
This one gets at the data, BUT it's for the TOTAL processor time, I understand the 2 second difference sample and the formula, but no matter what I try in several combinations this is as close as I get.
How can I "echo" this PercentProcessorTime for a specific process? I'm going to go freeeeegin crazy
Can anyone help me?
DigiMahn
P.s.
I know I could use the TGML "CODE" tags but the wrapping was just too crazy looking for my anal retentive self
but here is what I have so far without #3:
I think the subject is a little more "descriptive" this time and I hope I can get the help
Object of script:
[ol][li]Pause Default Printer [/li]
[li]Start and run an "invoicing" application [/li]
[li]When app goes Idle - terminate app [/li]
[li]Scan \WINNT\system32\spool\PRINTERS\*.SPL files for specific "data" and delete those .SPL files - allocate a sleep value of .65 - .9 seconds per .SPL for search to complete (with progress display) [/li]
[li]Stop and Start Print Spooler service [/li]
[li]Refresh default printer queue display [/li]
[li]Un-pause default printer (if service is not restarted and queue not refreshed then event log will contain 1 error message for each item missing .SPL - assumes default print server event log options enabled) [/ol][/li]
Now where I get stuck and have been stuck it to be able to tell when this crappy VB application has gone idle (3) and the only way I see doing that is via WMI.
Using WMI I can get at the "Win32_PerfRawData_PerfOS_Processor" raw data performance counter class - specifically "PercentProcessorTime" ... but my question is: is this where the column in taskmanager labled "CPU" is derived from? This is the only value that seems to make sense after reading the WMI SDK for the past week.
I can't seem to figure out how get this info per process...
I used line items so you can easily see each line of code/script
[ol][li]strComputer = "."[/li]
[li]Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"
[li]Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_process"
[li]For Each objProcess in colProcesses[/li]
[li] sngProcessTime = ( CSng(objProcess.KernelModeTime) + CSng(objProcess.UserModeTime)) / 10000000[/li]
[li] Wscript.echo objProcess.name & ": " & Round(sngProcessTime,2) & " Seconds"[/li]
[li]Next[/ol][/li]
I figured out how to get at the time column and convert it to seconds - WHOOPIE! I don't need that...
Then I found this while reading about WMI on MSDN:
[ol][li]Set objService = GetObject("Winmgmts:{impersonationlevel=impersonate}!\Root\Cimv2"
[li]For i = 1 to 8[/li]
[li]Set objInstance1 = objService.Get("Win32_PerfRawData_PerfOS_Processor.Name='_Total'"
[li]N1 = objInstance1.PercentProcessorTime[/li]
[li]D1 = objInstance1.TimeStamp_Sys100NS[/li]
[li]WScript.Sleep(2000)[/li]
[li]Set perf_instance2 = objService.get("Win32_PerfRawData_PerfOS_Processor.Name='_Total'"
[li]N2 = perf_instance2.PercentProcessorTime[/li]
[li]D2 = perf_instance2.TimeStamp_Sys100NS[/li]
[li]PercentProcessorTime = (1 - ((N2 - N1)/(D2-D1)))*100[/li]
[li]WScript.Echo "% Processor Time=" , Round(PercentProcessorTime,2)[/li]
[li]Next[/ol][/li]
This one gets at the data, BUT it's for the TOTAL processor time, I understand the 2 second difference sample and the formula, but no matter what I try in several combinations this is as close as I get.
How can I "echo" this PercentProcessorTime for a specific process? I'm going to go freeeeegin crazy
Can anyone help me?
DigiMahn
P.s.
I know I could use the TGML "CODE" tags but the wrapping was just too crazy looking for my anal retentive self
Code:
set WshShell = CreateObject("WScript.Shell")
Set IE = CreateObject("InternetExplorer.Application")
Set shl = CreateObject("Shell.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.Namespace("C:\WINNT\system32\spool\PRINTERS\")
nCounter = 0
For Each oFile in oFolder.Items
If lcase(Right(oFile.Name,4))=".spl" Then ncounter = nCounter + 1
Next
strMyDocPath = WshShell.SpecialFolders("MyDocuments")
strTempFile = strMyDocPath & "\RenPStat.html"
SetupIE(strTempFile)
Set objDIV = IE.Document.All("MakeMeAnObject")
objDIV.InnerHTML = "Processing Search Script...<BR><FONT SIZE=1>Next process: Locate and Delete --- ---'s invoices"
WScript.Sleep 2000
shl.FindFiles
WScript.Sleep 1000
WshShell.SendKeys "%M"
WshShell.SendKeys "*.SPL"
WshShell.SendKeys "%L"
WshShell.SendKeys "C:\WINNT\system32\spool\PRINTERS"
WshShell.SendKeys "%C"
WshShell.SendKeys "AMER150 "
SetupIE(strTempFile)
Set objDIV = IE.Document.All("MakeMeAnObject")
objDIV.InnerHTML = "Locating --- --- Invoices...<BR><FONT SIZE=1>Next process: Locate and Delete --- ---'s invoices (in " & (nCounter * .079) & " seconds)"
CommitSearch
WshShell.SendKeys "{TAB 4}"
WshShell.SendKeys "SKIN3910"
CountSPLs
SetupIE(strTempFile)
Set objDIV = IE.Document.All("MakeMeAnObject")
objDIV.InnerHTML = "Locating --- --- Invoices...<BR><FONT SIZE=1>Next process: Locate and Delete --- ---'s invoices (in " & (nCounter * .079) & " seconds)"
CommitSearch
Wscript.Sleep 1000
WshShell.SendKeys "%{F4}"
Wscript.Sleep 500
intReturn = WshShell.Run("C:\TransFlo\rndprint\Stop_svc.bat", 1, TRUE)
WshShell.AppActivate "HP LaserJet 4000 Series PCL - Paused"
WScript.Sleep 500
WshShell.SendKeys "{F5}"
WScript.Sleep 2000
WshShell.SendKeys "%pa"
SetupIE(strTempFile)
Set objDIV = IE.Document.All("MakeMeAnObject")
objDIV.InnerHTML = "Printing Invoices..."
WScript.Quit(1)
Sub SetupIE(File2Load)
IE.Navigate File2Load
IE.ToolBar = False
IE.StatusBar = False
IE.Resizable = False
Do
Loop While IE.Busy
IE.Width = 500
IE.Height = 150
IE.Left = 0
IE.Top = 0
IE.Visible = True
WshShell.AppActivate("Microsoft Internet Explorer")
WshShell.AppActivate("Search Results")
End Sub
Function CountSPLs()
nCounter = 0
For Each oFile in oFolder.Items
If lcase(Right(oFile.Name,4))=".spl" Then ncounter = nCounter + 1
Next
End Function
Sub CommitSearch()
WshShell.SendKeys "~"
WScript.Sleep (79 * nCounter)
WshShell.SendKeys "%ea"
WshShell.SendKeys "+{DEL}"
WshShell.SendKeys "Y"
End Sub