Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9012565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:02:04+00:00 2026-06-16T03:02:04+00:00

I have been trying to write a Perl script that would check the service

  • 0

I have been trying to write a Perl script that would check the service status of Remote Servers. I am using the Win32::Service module to accomplish my goal.

I find that the for some services value returned by Win32::Service::GetStatus CurrentStatus is not exactly the same as observed from services.msc applet.

Here is the piece of script I am using along with both outputs from script and servics.msc.

use Data::Dumper;
use Win32;
use Win32::Service;
use strict;
use warnings;

my %statcodeHash = (     '1' => 'stopped.',
                     '2' => 'start pending.',
                     '3' => 'stop pending.',
                     '4' => 'running.',
                     '5' => 'continue pending.',
                     '6' => 'pause pending.',
                     '7' => 'paused.'            );


my @serviceNames = qw(NNMAction RpcEptMapper smstsmgr SNMPTRAP);

foreach my $serv (@serviceNames)
{   my %status;
    my $ret = Win32::Service::GetStatus('nnmi.hclt.corp.hcl.in', $serv, \%status);
    if ($ret)
    {   print "success\t$statcodeHash{$status{CurrentState}}\t$serv\n";
    }
    else
    {       print Win32::FormatMessage(Win32::GetLastError()), "\n";
    }
}

OUTPUT from Script

D:\AVI MEHENWAL\PERL\SCRIPTS\PROJECTS\Serve Management>perl -w perl_RemoteServiceStatus.pl
success stopped.        NNMAction
success running.        RpcEptMapper
success stopped.        smstsmgr
success stopped.        SNMPTRAP

OUTPUT from Services.msc

Name       Descrition   Status   StartupType  LogOnAs
NNMAction  bla bla bla  Started  Manual       LocalSystem

Can anyone suggest me what approach should I follow to achieve my goal, Is my method wrong or there is something I am missing from Perl module point of view?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:02:06+00:00Added an answer on June 16, 2026 at 3:02 am

    Updated

    I noticed that nnmi.hclt.corp.hcl.in seems to be a domain name rather than a Windows style machine name. First, find out the IP address corresponding to nnmi.hclt.corp.hcl.in. Let’s say it is x.x.x.x.

    Now, run nbtstat -A x.x.x.x. That should tell you the name of the machine. Let’s say it is NNMI. Then, you should specify that in the my $remote line below, replacing MYREMOTE with NNMI, and try again.

    I am assuming you have the correct privileges etc. If you get an authorization related error, I am afraid I cannot help you, but you can ask on ServerFault to find out what you need to do so as to be able to query services on a remote machine in the domain.

    use strict;
    use warnings;
    use Data::Dumper;
    use Win32;
    use Win32::Service;
    
    my %status_codes = reverse (
        SERVICE_STOPPED          => 0x00000001,
        SERVICE_START_PENDING    => 0x00000002,
        SERVICE_STOP_PENDING     => 0x00000003,
        SERVICE_RUNNING          => 0x00000004,
        SERVICE_CONTINUE_PENDING => 0x00000005,
        SERVICE_PAUSE_PENDING    => 0x00000006,
        SERVICE_PAUSED           => 0x00000007,
    );
    
    my $remote = '\\\\MYREMOTE';
    
    my @services = qw(Fax ClipSrv AcrSch2Svc);
    
    foreach my $svc (@services) {
        my %status;
        my $ret = Win32::Service::GetStatus($remote, $svc, \%status);
    
        if ($ret) {
            printf(
                "success\t%s\t%s\n",
                $status_codes{ $status{CurrentState} },
                $svc
            );
        }
        else
        {
            warn sprintf(
                "failed to get '%s' status: %s\n",
                $svc,
                Win32::FormatMessage(Win32::GetLastError())
            );
        }
    }
    

    For reference, the SERVICE_STATUS structure is documented here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to write a bare-bones ping scanner using Perl for internal
I have been trying to write a script that may help me to comment
I have been trying to write a code that will check if the given
I have been trying to write a perl script to get all of the
I have been trying to write an image on a layer using Quartz but
I have been trying to write my own diff3 wrap script for SVN and
I have been trying to write a regex that will remove whitespace following a
I have been trying to write my first user script for Google Chrome. It
I have been trying to write a set of htaccess rules that will do
I have been trying to write an app that periodically parses the contents of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.