Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums

Go Back   Vista Forums > Vista technology newsgroups > PowerShell

script stops when computer is locked

Reply
 
Thread Tools Display Modes
Old 04-10-2008   #1
Ben Christian
Guest
 
Posts: n/a

script stops when computer is locked

basically the idea is to check a folder for pdf files every x seconds and
print them...I was thinking that the send-keys is failing since it can't get
the window while it's locked, but it actually looks like it won't even open
up the next file (when locking the computer, it appears that the current
'foreach' loop completes, then it stops. It does not appear to go on to the
next filename). Any suggestions?

here's the script...

########= Loading Plugin =#########=
add-pssnapin WindowsAutomation

########= Setting Variables =#########=
$searchpath = "c:\autoprint-test"
$printedpath = "c:\autoprint-test\completed"
$sleeping = 30

########= Opening endless loop =#########=
$loopy = 0
while ($loopy -eq 0) {

########= Searching for pdf files =#########=
$files = @(get-childitem $searchpath | ? {$_.extension -match "pdf"})

########= Printing Files =#########=
foreach ($document in $files) {
write-host $searchpath\$document
invoke-expression $searchpath\$document
start-sleep 5
select-window acrord32 | send-keys "%(fp){Enter}"
start-sleep 20
taskkill /im acrord32.exe
start-sleep 1
move-item "$searchpath\$document" $printedpath
}
write-host "Checking for new files in $sleeping seconds"
start-sleep $sleeping
}
  Reply With Quote

Old 04-10-2008   #2
Ben Christian
Guest
 
Posts: n/a

RE: script stops when computer is locked

OK...so the problem was in fact with the send-keys...i don't think it can
grab the window while the workstation is locked...to fix it I removed the
send-keys line and replaced the invoke-expression line as follows:

& $acrobatpath /t $document.fullname

this works well for the printing

the next enhancement i'd like is that i'd really like to get rid of the
sleep right after that line...i have it there so that there is enough time to
allow spooling to get done before killing the process. is there a way to do
something like the following?

....
while (acrobat.spooling) { start-sleep 2 }
killtask /IM acrord32.exe
....

some of the docs take 10 secs to spool, others may only take 1-2...also, i
don't want to accidentaly kill acrord32 while a document is still spooling
should a larger than normal document come in...

Thanks!

"Ben Christian" wrote:
Quote:

> basically the idea is to check a folder for pdf files every x seconds and
> print them...I was thinking that the send-keys is failing since it can't get
> the window while it's locked, but it actually looks like it won't even open
> up the next file (when locking the computer, it appears that the current
> 'foreach' loop completes, then it stops. It does not appear to go on to the
> next filename). Any suggestions?
>
> here's the script...
>
> ########= Loading Plugin =#########=
> add-pssnapin WindowsAutomation
>
> ########= Setting Variables =#########=
> $searchpath = "c:\autoprint-test"
> $printedpath = "c:\autoprint-test\completed"
> $sleeping = 30
>
> ########= Opening endless loop =#########=
> $loopy = 0
> while ($loopy -eq 0) {
>
> ########= Searching for pdf files =#########=
> $files = @(get-childitem $searchpath | ? {$_.extension -match "pdf"})
>
> ########= Printing Files =#########=
> foreach ($document in $files) {
> write-host $searchpath\$document
> invoke-expression $searchpath\$document
> start-sleep 5
> select-window acrord32 | send-keys "%(fp){Enter}"
> start-sleep 20
> taskkill /im acrord32.exe
> start-sleep 1
> move-item "$searchpath\$document" $printedpath
> }
> write-host "Checking for new files in $sleeping seconds"
> start-sleep $sleeping
> }
  Reply With Quote
Old 04-10-2008   #3
Marco Shaw [MVP]
Guest
 
Posts: n/a

Re: script stops when computer is locked

> the next enhancement i'd like is that i'd really like to get rid of the
Quote:

> sleep right after that line...i have it there so that there is enough time to
> allow spooling to get done before killing the process. is there a way to do
> something like the following?
>
> ...
> while (acrobat.spooling) { start-sleep 2 }
> killtask /IM acrord32.exe
> ...
>
> some of the docs take 10 secs to spool, others may only take 1-2...also, i
> don't want to accidentaly kill acrord32 while a document is still spooling
> should a larger than normal document come in...
There doesn't seem to be any kind of interface that PowerShell can use
to talk directly to the reader.

My only suggestion might be to run a session while using something like
ProcessMonitor (www.sysinternals.com) to see if you can figure out what
the app does when the spooling is done.

If it is a locally attached printer, you might be able to keep an eye on
the printer spool. If you see it in the printer spool, then it has
"left" the reader app.

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
  Reply With Quote
 
Reply

Thread Tools
Display Modes









Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48