Fellow Monks --
The OS is: the 'wonderful' Windows XP Professional
The quest is to forcibly stop then restart a program.
I am logged in with admin privledges, so, in theory this should not be an issue. The code is below:
#!/usr/bin/perl -w
use strict;
use Win32;
use Win32::Process;
use Win32::Process::Info;
my $execID2find="prog2stopnstart32.exe";
my $pi = Win32::Process::Info->new;
my @info = $pi->GetProcInfo();
my @procsOfInterest = grep{ $_->{Name} eq $execID2find } @info;
if( @procsOfInterest ) {
print "KILL $_->{ProcessId}\n",
kill 9, $_->{ProcessId},
for @procsOfInterest;
} else {
print "No process with the name $execID2find was found\n";
}
# Create the process object.
my $ProcessObj;
Win32::Process::Create($ProcessObj,
"C:\\Program Files\\programs\\prog2sto
+pnstart32.exe",
"prog2stopnstart32",
0,
NORMAL_PRIORITY_CLASS,
".")|| die ErrorReport();
$ProcessObj->Suspend();
$ProcessObj->Resume();
# $ProcessObj->Wait(INFINITE);
sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
}
When I run the script the PID is identified it attempts to kill the program, indicated by a delay, then returns 0, indicating that the program has not been killed. I cannot restart the program without killing it first.
I believe that what I need is to be able to override whatever is stopping me from killing the program, then kill it.
I am certianly open to more than one way to do this....A combination of Windows Scripting and Perl perhaps?
As always your wisdom and help are greatly appreciated in advance.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.