Apps DBA Concepts

Just another WordPress.com weblog

Deleting Windows Services using perl

Posted by vasselva on June 2, 2008

Use it at your own risk

serviceDel.pl

print “Deleting Windows Services perl….\n”;
my $cmd =”sc query \”<SERVICE NAME>\” | grep RUNNING | cut -c33-“;
my $ret =`$cmd`;
chomp($ret);
$ret =~ s/^\s+//;
$ret =~ s/\s+$//;

if(“$ret” eq “RUNNING”){
my $cmd = “sc stop \”<SERVICE NAME>\””;
my $rt=system($cmd);
print “Stop service returned $rt…\n”;
}

while(true){
sleep(5);
my $cmd =”sc query \”<SERVICE NAME>\” | grep STOPPED | cut -c33-“;
my $c = `$cmd`;
chomp($c);
$c =~ s/^\s+//;
$c =~ s/\s+$//;
if ( “$c” eq “STOPPED”){print “SERVICE STOPPED \n”;last;}
print “SERVICE iS RUNNING \n”;
}

my $cmd = “sc delete \”<SERVICE NAME>\””;
my $rt  =  system($cmd);
print “Delete Service returned $rt…\n”;

Leave a comment