Groups > Microsoft > Windows PowerShell > Re: script stops when computer is locked




script stops when computer is locked

script stops when computer is locked
Thu, 10 Apr 2008 11:23:02 -070
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)"
    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
Post Reply
RE: script stops when computer is locked
Thu, 10 Apr 2008 14:57:01 -070
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:

> 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)"
>     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
Post Reply
Re: script stops when computer is locked
Thu, 10 Apr 2008 22:38:14 -030
> 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...

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:
Post Reply
about | contact