Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

automation on windows

by morgon (Priest)
on Nov 01, 2014 at 17:14 UTC ( [id://1105800]=perlquestion: print w/replies, xml ) Need Help??

morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have a virtual machine (using kvm) running windows xp on which I would like to automate some tasks and having little windows-knowledge myself I wonder which direction to go.

One of the tasks I want to do in an automated way is to start acrobat reader, make it open a file residing on a samba-share and print it (my use case is for drm-protected pdfs that I cannot open on my host-system, it gets printed to a cups-printer on my host-system that creates again a pdf - but without the drm).

What would be the best way to initiate such a task from my host-system?

Would I need a tool such as autoit or can I do it with only Perl?

Many thanks!

Replies are listed 'Best First'.
Re: automation on windows
by Corion (Patriarch) on Nov 01, 2014 at 19:54 UTC

    Personally, I would just use Perl and write a small Perl program that monitors the SMB share for new files:

    #!perl -w use strict; require Win32::ChangeNotify; my($dir)= @ARGV; while(1) { $notify = Win32::ChangeNotify->new($dir,0,'FILE_NAME'); $notify->wait or warn "Something failed: $! / $^E\n"; sleep 10; # give the process writing the file some time for my $pdf (glob "$dir/*.pdf" ) { ; # we process all files here, +because I'm lazy system(1, qq{"C:\\Program Files (x86)\\Adobe\\Reader 10.0\\Rea +der\\AcroRd32.exe" /t $pdf}); }; $notify->reset(); }
      Cool, thanks for pointing out "/t".

      But assuming I do not want this script to run all the time, how would I start it from the host? Would I install an ssh-server on the XP-machine and use that to start it or is there a better way on windows?

      And how would I automate things that I cannot handle with a command-line switch?

      I mean what are the proper tools on Windows when you have to synthesize keyboard or mouse-events? On X I can use e.g. xdotool but I have no idea what to use on Windows - autoit maybe?

        If you want to send keystrokes or mouse events, you want to use Win32::GuiTest.

        This usually conflicts with processes started through a service though, becuase Windows permissions disallow sending events from processes started through a service to the desktop (or so I think).

        If you want to launch a process from the outside, either have an SSH daemon running on the target machine or use WMI (if you are Administrator in your domain) or write a small HTTP server that then launches the target process.

        If you want a quick solution, I'd advise to use the perl script in Corion's first post and autoit for the other stuff. You save yourself the hassle of compiling the package. In autoit you'd have to write just a small script that when acroread windows pop up prints the contents and then closes the acreoreads. A few lines, simple like BASIC. If time is a concern I'd really suggest that heretic, quick and dirty solution..."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1105800]
Approved by boftx
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-16 06:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found