Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count files and use that count * .1 to set "sleep" time 1

Status
Not open for further replies.

digimahn

IS-IT--Management
Jul 25, 2002
27
US
Let's start with a copy of the scripts involved here - please don't make fun of my hack job :) I'm just a baby coder here :)
this is run on a W2KPRO workstation

NO_PRINT.VBS
Code:
set WshShell = CreateObject("WScript.Shell")
Set IE = CreateObject("InternetExplorer.Application")
Set shl = CreateObject("Shell.Application")
Set fso = CreateObject("Scripting.FileSystemObject")

 'Create a path and filename to a file in My Documents
	strMyDocPath = WshShell.SpecialFolders("MyDocuments")
	strTempFile = strMyDocPath & "\PrntStat.html"

 'Run IE, load PrntStat.html, and Set the DIV element as an object
	SetupIE(strTempFile)
	Set objDIV = IE.Document.All("MakeMeAnObject")

 'Change the innerHTML of the DIV object
	objDIV.InnerHTML = "Processing Search Script..."
	WScript.Sleep 2000

 'Start Search and set params for search
	shl.FindFiles	
	WScript.Sleep 1000
	WshShell.SendKeys "{TAB 2}"
	WshShell.SendKeys "{DOWN 5}"
	WshShell.SendKeys "C:\WINNT\system32\spool\PRINTERS"
	WshShell.SendKeys "~"

 'Find and Delete all "GAP" invoices
	WshShell.SendKeys "{TAB 10}"
	WshShell.SendKeys "{BS 10}"
	WshShell.SendKeys "{DELETE}"
	WshShell.SendKeys "*.SPL"
	WshShell.SendKeys "{TAB}"
	WshShell.SendKeys "GAP "
	SetupIE(strTempFile)
	Set objDIV = IE.Document.All("MakeMeAnObject")
	objDIV.InnerHTML = &quot;Locating GAP Invoices...<BR><FONT SIZE=1>Next process: Locate and Delete American Eagle's invoices&quot;
	WScript.Sleep 1000
	wshShell.AppActivate &quot;Search Results&quot;
	WshShell.SendKeys &quot;~&quot;
	WScript.Sleep 130000     '2m10s
	wshShell.AppActivate &quot;Search Results&quot;
	WshShell.SendKeys &quot;%ea&quot;
	WshShell.SendKeys &quot;+{DEL}&quot;
	WshShell.SendKeys &quot;~&quot;

 'Find and Delete all &quot;AMER150&quot; invoices
	WshShell.SendKeys &quot;{TAB 4}&quot;
	WScript.Sleep 100
	WshShell.SendKeys &quot;AMER150 &quot;
	SetupIE(strTempFile)
	Set objDIV = IE.Document.All(&quot;MakeMeAnObject&quot;)
	objDIV.InnerHTML = &quot;Locating American Eagle Invoices...<BR><FONT SIZE=1>Next process: Locate and Delete Skin Market's invoices&quot;
	WScript.Sleep 1000
	wshShell.AppActivate &quot;Search Results&quot;
	WshShell.SendKeys &quot;~&quot;
	WScript.Sleep 130000     '2m10s
	wshShell.AppActivate &quot;Search Results&quot;
	WshShell.SendKeys &quot;%ea&quot;
	WshShell.SendKeys &quot;+{DEL}&quot;
	WshShell.SendKeys &quot;~&quot;

 'Find and Delete all &quot;SKIN3910&quot; invoices
	WshShell.SendKeys &quot;{TAB 4}&quot;
	WScript.Sleep 100
	WshShell.SendKeys &quot;SKIN3910&quot;
	SetupIE(strTempFile)
	Set objDIV = IE.Document.All(&quot;MakeMeAnObject&quot;)
	objDIV.InnerHTML = &quot;Locating Skin Market Invoices...<BR><FONT SIZE=1>Next process: Locate and Delete Charlotte Russe[1]'s invoices&quot;
	WScript.Sleep 1000
	wshShell.AppActivate &quot;Search Results&quot;
	WshShell.SendKeys &quot;~&quot;
	WScript.Sleep 130000     '2m10s
	wshShell.AppActivate &quot;Search Results&quot;
	WshShell.SendKeys &quot;%ea&quot;
	WshShell.SendKeys &quot;+{DEL}&quot;
	WshShell.SendKeys &quot;~&quot;

 'Find and Delete all &quot;CHAR4645&quot; invoices
	WshShell.SendKeys &quot;{TAB 4}&quot;
	WScript.Sleep 100
	WshShell.SendKeys &quot;CHAR4645&quot;
	SetupIE(strTempFile)
	Set objDIV = IE.Document.All(&quot;MakeMeAnObject&quot;)
	objDIV.InnerHTML = &quot;Locating Charlotte Russe[1] Invoices...<BR><FONT SIZE=1>Next process: Locate and Delete Charlotte Russe[2]'s invoices&quot;
	WScript.Sleep 1000
	wshShell.AppActivate &quot;Search Results&quot;
	WshShell.SendKeys &quot;~&quot;
	WScript.Sleep 130000     '2m10s
	wshShell.AppActivate &quot;Search Results&quot;
	WshShell.SendKeys &quot;%ea&quot;
	WshShell.SendKeys &quot;+{DEL}&quot;
	WshShell.SendKeys &quot;~&quot;

 'Find and Delete all &quot;CHAR1175&quot; invoices
	WshShell.SendKeys &quot;{TAB 4}&quot;
	WScript.Sleep 100
	WshShell.SendKeys &quot;CHAR1175&quot;
	SetupIE(strTempFile)
	Set objDIV = IE.Document.All(&quot;MakeMeAnObject&quot;)
	objDIV.InnerHTML = &quot;Locating Charlotte Russe[2] Invoices...<BR><FONT SIZE=1>Next process: Initialize and Print Daily Invoices&quot;
	WScript.Sleep 1000
	wshShell.AppActivate &quot;Search Results&quot;
	WshShell.SendKeys &quot;~&quot;
	WScript.Sleep 130000     '2m10s
	wshShell.AppActivate &quot;Search Results&quot;
	WshShell.SendKeys &quot;%ea&quot;
	WshShell.SendKeys &quot;+{DEL}&quot;
	WshShell.SendKeys &quot;~&quot;
	WshShell.SendKeys &quot;%{F4}&quot;

 'Close Search, Stop/Start Print Spooler, switch to Printer, Refresh and un-pause
	WshShell.SendKeys &quot;%{F4}&quot;
	intReturn = WshShell.Run(&quot;C:\TransFlo\rndprint\Stop_svc.bat&quot;, 1, TRUE)
	WshShell.AppActivate &quot;HP LaserJet 4000 Series PCL - Paused&quot;
	WScript.Sleep 500
	WshShell.SendKeys &quot;{F5}&quot;
	WScript.Sleep 2000
	WshShell.SendKeys &quot;%pa&quot;
	SetupIE(strTempFile)
	Set objDIV = IE.Document.All(&quot;MakeMeAnObject&quot;)
	objDIV.InnerHTML = &quot;Printing Invoices...&quot;

'IE SUBROUTINES
	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(&quot;Microsoft Internet Explorer&quot;)
	End Sub


NO_PRINT.VBS invokes the html page below as a script status updater...

PrntStat.html
<HTML><HEAD><TITLE>Progress Indicator</TITLE>
<SCRIPT>
var timerID = null;
var timerOn = false;
var startDay = new Date();
var startTime = startDay.getTime();

var now = new Date();
var dayMonth = now.getDate(); // day of the month {1-31}
var month = now.getMonth(); // present month {0-11}
var year = now.getYear(); // present year {0-99}
var dayWeek = now.getDay(); // day or the week {0(Sun)-6}

var weekDay = &quot;&quot;;
var yearMonth = &quot;&quot;;

function stopclock(){
if(timerOn) clearTimeout(timerID);
timerOn = false;
}

function startclock(){
stopclock();
showtime();
}

function showtime(){
var now = new Date();

var hour = now.getHours(); // present hour {0-23}
var minute = now.getMinutes(); // present minute {0-59}
var second = now.getSeconds(); // present second {0-59}

var timeOn = now.getTime();
var timeValue = &quot; &quot; + ((hour > 12) ? hour - 12 : hour);
timeValue += ((minute < 10) ? &quot;:0&quot; : &quot;:&quot;) + minute;
timeValue += ((second < 10) ? &quot;:0&quot; : &quot;:&quot;) + second;
timeValue += (hour >= 12) ? &quot; P.M.&quot; : &quot; A.M.&quot;;
document.clock.face.value = timeValue;

var timerTime = (timeOn - startTime)/1000;
var timerTimS = &quot;&quot; + timerTime // convert to a string
timerTimS = &quot; &quot;+timerTimS.substring(0,timerTimS.indexOf(&quot;.&quot;)) + &quot;&quot;;
document.clock.timespent.value = timerTimS;

timerID = setTimeout(&quot;showtime()&quot;,1000);
timerOn = true;
}

</SCRIPT></HEAD>
<BODY SCROLL='NO' onLoad=&quot;startclock()&quot;>
<CENTER>
<FORM NAME=&quot;clock&quot; onSubmit=&quot;0&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;face&quot; SIZE=1 VALUE =&quot;&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;timespent&quot; SIZE=1 VALUE =&quot;&quot;></FORM>
<FONT FACE='arial'><FONT SIZE=2><HR COLOR='BLACK'><B><DIV id='MakeMeAnObject'></B></DIV>
<HR COLOR='BLACK'></FONT></CENTER>
</BODY></HTML>
[/code]



Now what I have been unable to do is:
1) Count only the .SPL files in C:\WINNT\system32\spool\PRINTERS and multiply the result by 0.1

2) Use that SPL's * 0.1 result and set each &quot;WScript.Sleep 130000&quot; in NO_PRINTS.VBS dynamically per search set.

3) Watch the &quot;SPOOLSV.EXE&quot; (Print Spooler) service's CPU or CPU TIME activity to determine when all print jobs are complete and then pause the active printer and go delete the left over .SHD files from C:\WINNT\system32\spool\PRINTERS (each .SPL file has a corresponding .SHD file associated with it).

Once I figure this out I can also watch the ivoicing application's process to determine when to fire off the searches...

If I can't watch the service persay then maybe I could catalog the \spool\PRINTERS directory and poll it every so often to see if all the originally cataloged .SPL files are gone

I'm really stuck on this one and just can not figure it out. I would appreciate some help if possible.

I also know that I could break each search into its own script and call the next &quot;phase&quot; from within each script, but right now I modify the sleep time by hand (I multiply the # of documents showing in the print queue * 0.1, round UP to the nearest second).

Thanks to anyone that even took the time to peek in here :)
DigiMahn
 
Since you're already integrating the Shell, For 1 & 2,
Code:
Set oShell = CreateObject(&quot;Shell.Application&quot;)
Set oFolder = oShell.Namespace(&quot;C:\yourpath&quot;)
nCounter = 0
For Each oFile in oFolder.Items
  If lcase(Right(oFile.Name,4))=&quot;.spl&quot; Then ncounter = nCounter + 1
Next
WScript.Sleep (1000 * nCounter)
MsgBox nCounter

For 3 - if you really want to monitor the process activity, head over to the MSDN and check out a few of the sample scripts using WMI. If you would rather directly interface with the print queue, you can use ADSI to pause,purse,etc...Head over to the MSDN and download the ADSI SDK - I believe there's an example.

Jon Hawkins
 
Thank you jonscott8!
I tried that already but, I forgot to declare a &quot;unique&quot; Set Shell (I was trying to use the same one - doh!).

The WMI samples I saw at MSDN that may work for me were for XP or .NET only - bummer! I am perusing the ADSI SDK right now - thank you again!

For anyone else that cares in &quot;NO_PRINT.VBS&quot; I replaced each instance of:
Code:
    WshShell.SendKeys &quot;~&quot;
    WScript.Sleep 130000     '2m10s

with

Code:
    WshShell.SendKeys &quot;~&quot;
    Set oShell = CreateObject(&quot;Shell.Application&quot;)
    Set oFolder = oShell.Namespace(&quot;C:\WINNT\system32\spool\PRINTERS\&quot;)
     nCounter = 0
      For Each oFile in oFolder.Items
       If lcase(Right(oFile.Name,4))=&quot;.spl&quot; Then ncounter = nCounter + 1
     Next
    WScript.Sleep (100 * nCounter)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top