Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32::Services::GetStatus??

Status
Not open for further replies.

soy4soy

IS-IT--Management
May 22, 2000
100
US
What happened to this method/function? Or is the status of the service returned by the GetServices hash? If so, what is the subkey or whatever to find out?

Whenever I try to use this function, I get an error stating that it is an "Undefined subroutine..."

I have specifically searched via PPM for Win32-Services to try to install the module, but it is not there.

Oh my goal is to find out whether or not a particular service is up and running on NT4/2000. If that helps
 
try perldoc win32-service

Win32::Service is part of the libwin32 bundle.. and it's standard with ActivePerl, although I'm getting the same error on W2K. I'm going to keep playing around with it.. I'll post again if I have any luck.
 
I took a guess, and this did it. hope this helps..

use Win32::Service qw/StopService StartService GetStatus/;

StartService('','service');

StopService('','service');
 
Ok, THANK YOU, chazoid!

That worked like a charm!

The ever-curious me wonders: Can you 'splain to me why?

What's that deal with the qw? I've seen it used before for quoting strings etc, but what is its' purpose following the "use" statement?
 
Here is what I used:

Win32::Service::GetStatus("", "service_name", \%status)

All information about the service is returned in the hash %status

Here is a list of the different values you can find the hash:

CheckPoint
ControlsAccepted
CurrentState
ServiceSpecificExitCode
ServiceType
WaitHint
Win32ExitCode


The key you are interested in is $status{'CurrentState'}

Here is the list of values returned by CurrentState and their meanings:

Win32Constant Value Description
SERVICE_STOPPED 0x01 The service has stopped.
SERVICE_START_PENDING 0x02 The service is starting up.
SERVICE_STOP_PENDING 0x03 The service is in the process of stopping.
SERVICE_RUNNING 0x04 The service has successfully started and is running.
SERVICE_CONTINUE_PENDING 0x05 The service is resuming from a paused state.
SERVICE_PAUSE_PENDING 0x06 The service is entering the paused state.
SERVICE_PAUSED 0x07 The service is pausing.

Knowing the value of the state is important because it then let's you specify events based on what the service is doing.

For example, say you want to install a program, but it requires that a service be stopped before the program can be installed. You can issue a stop command to the service and then use an if statement along with a loop that looks for state 0x01. If it does not find that state, keep looping until the state is encountered.

The reason for this is services sometimes don't stop immediately. There is a period of time when the service is stopping 0x03. If you try to install while the service is in state 0x03, you will get an error.
 
no prob soy.. glad to help! The service module exports those functions.. if you open up the service.pm file (Perl\site\lib\win32\service.pm) you can see the list:

@EXPORT_OK =
qw(
StartService
StopService
GetStatus
PauseService
ResumeService
GetServices
);

racklet's method makes it more clear to me.. I'm still kind of a perl newbie myself. I've just seen the qw// method in documentation for other modules (Date::Calc) The way I see it, you can either import the functions you need up front with qw// or call them directly as racklet did. I don't know if this makes a difference in performance, or if it's just for brevity.. maybe someone else can speak to this.
 
Hmmm, interesting.

I *was* calling it directly, as racket did, and that is how i got that error message. It was not until i applied your method that the error went away. That code now works, so it is impossible for me to say with 100% certainty if i had spelled it correctly, although I believe that i did.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top