Computing.Net > Forums > Programming > PERL 'Win32::Service'

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PERL 'Win32::Service'

Reply to Message Icon

Name: mongar
Date: November 4, 2006 at 08:24:42 Pacific
OS: windows2003
CPU/Ram: 1
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: November 4, 2006 at 18:09:04 Pacific
Reply:

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?


0

Response Number 2
Name: mongar
Date: November 5, 2006 at 10:06:34 Pacific
Reply:

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


0

Response Number 3
Name: FishMonger
Date: November 5, 2006 at 10:20:32 Pacific
Reply:

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);


0

Response Number 4
Name: FishMonger
Date: November 5, 2006 at 10:30:10 Pacific
Reply:

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);


0

Response Number 5
Name: mongar
Date: November 6, 2006 at 12:46:43 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: FishMonger
Date: November 6, 2006 at 15:02:29 Pacific
Reply:

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.com

subsequently hacked by Gurusamy Sarathy <gsar@activestate.com>


0

Response Number 7
Name: mongar
Date: November 7, 2006 at 12:41:01 Pacific
Reply:

again thanks allot i will try sending
them an email hopefully that will
help
thanks


0

Response Number 8
Name: mongar
Date: December 27, 2006 at 13:03:06 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: PERL 'Win32::Service'

Perl Win32::Process::Info www.computing.net/answers/programming/perl-win32processinfo/15268.html

Perl Win32::AD::User www.computing.net/answers/programming/perl-win32aduser/14824.html

Perl - Win32::MsgBox www.computing.net/answers/programming/perl-win32msgbox/8030.html