Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
did someone used PERL 'Win32::Service' module
for stoping , starting and getting the status of a windows service.
i havent managed to find any article that
give an example on how to do it.
will apreciate your help.

Have you read the module's documentation on cpan? It's not very verbose, but it's enough to show how to use the module.
http://search.cpan.org/~jdb/libwin3...
Can you post your test script?

hi , yes i have looked at the documentation on cpan but as you said its not very verbose and i am not that good at perl.
here is my script ,will appreciate any help.use Win32::Service;
#$wuauserv="C:/WINDOWS/system32/svchost.exe -k netsvcs";
$wuauserv="Automatic Updates";
print "Restarting windows automatic service!\n";
StopService($wuauserv->);
#GetStatus(wuauserv, status);
#StartService(wuauserv);thanks in advanced

The module's subroutines are not exported by default, so you'll need to import them in the use statement.
========================================================================
use Win32::Service qw/StartService StopService GetStatus PauseService ResumeService GetServices/;#$wuauserv="C:/WINDOWS/system32/svchost.exe -k netsvcs";
$wuauserv="Automatic Updates";
print "Restarting windows automatic service!\n";
StopService($wuauserv->);
#GetStatus(wuauserv, status);
#StartService(wuauserv);

I should taken a closer looked at your code before doing the copy/paste. Your call to StopService is not passing the correct paramatures. The first arg needs to be a hostname or an empty string (i.e, '') if it's the localhost and the second is the name of the service.
StopService('', $wuauserv);

thanks for your help but did it worked
for you cause i keep getting an error
" Bad file descriptor" ,
its seems that i cant find the right syntax for the automatic update service or any windows service.
do you know where should i look for it
i searched the internet the services.msc
and i got nothing.

I was not on a Windows system at the time, so I didn't test it before posting. I have just ran a few tests and only GetServices() function is working. I don't know why the others aren't working; that will take some additional testing and research.
You could try sending an email to the author of the module and/or submit a bug report on cpan.
Service.pm
Written by Douglas_Lankshear@ActiveWare.comsubsequently hacked by Gurusamy Sarathy <gsar@activestate.com>

hi ,
i have managed to find it here it is
when you dig and dig and dig you will find gold.#restart autowindowsupdate service.
%status =
(1 => 'STOPPED', 2 => 'START_PENDING',
3 => 'STOP_PENDING', 4 => 'RUNNING',
5 => 'CONTINUE_PENDING',6 => 'PAUSE_PENDING',
7 => 'PAUSED', 8 => 'ERROR');
$ADsPath = "WinNT://$host/wuauserv,service";
$s = Win32::OLE->GetObject($ADsPath)
or die "Unable to retrieve the object for $ADsPath\n";
$s->Stop();
sleep(5);
$s->Start();
$s->Status();print $status{$s->{status}};
print "\n";
}#end of windowsupdate

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |