Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Since this is Windows, you can use WMI to start,monitor, and kill the process.
use strict; use Win32::OLE qw( in ); use Win32::OLE::Variant; usage if @ARGV < 2; if( my $Pid = RemoteExec( @ARGV ) ) { print "Process created with PID $Pid\n"; } else { print "Process not created\n"; } exit; ##################################################################### sub RemoteExec { my $Machine = shift; my $CommandLine = join " ", @_; my($CLASS, $WMI, $Process, $vPid); $Machine =~ s|^[\\/]+||; $CLASS = "WinMgmts:{impersonationLevel=impersonate}!//$Machine"; print "Trying to launch @_ on $Machine\n\n"; $WMI = Win32::OLE->GetObject( $CLASS ) or die "Unable to connect to \\\\$Machine :" . Win32::OLE->Las +tError(); $Process = $WMI->Get( "Win32_Process" ) or die "Unable to get a Win32_Process :" . Win32::OLE->LastErr +or(); $vPid = Variant( VT_I4 | VT_BYREF, 0 ); # $vPid (out) PID o +f the created Process if( 0 == $Process->Create( $CommandLine, undef, undef, $vPid ) ) { return $vPid; } else { return undef; } } ##################################################################### sub usage { my($ScriptName) = $0 =~ m/.*\\(.*)$/; print<<"USAGE"; Usage : $ScriptName [\\\\]COMPUTERNAME CommandLine Parameters example :$ScriptName COMPUTER1 NOTEPAD C:\\FooBar.txt USAGE exit; }
Original node (89593)

To kill the process use kill($Pid);


In reply to Re: How can I close a Windows program called from a my Perl script? by bcarroll
in thread How can I close a Windows program called from a my Perl script? by danren924

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-26 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found