@SERVICE, unexpected results

May 20, 2008
11,530
102
Syracuse, NY, USA
@SERVICE seems better that it was, but it gives unexpected results.

For info level 3, it always returns 0. I tried about a dozen services, many of which I know can be stopped.

For info level 4, it sometimes gives values that seem rather large (spooler = 69, diskeeper = 65, eventlog = 4).

For info level 5, it always returns 0, which I suppose could be correct. But I know from experience that these operations don't happen instantly. OTOH, if the SCM asks the service for the estimate, the service itself might not bother to give a meaningful one.
 
May 20, 2008
11,530
102
Syracuse, NY, USA
Actually it seems you just have the indices for ControlsAccepted and CheckPoint switched, either in the help or in the code.

For spooler, %SERVICE gives:

Code:
for /L %i in (1,1,5) echo %@service[spooler,%i]
272
4
0
69
0
while,

Code:
wprintf(L"Name\t%s\n"
        L"Type\t%lu\n"
        L"State\t%lu\n"
        L"Control\t%lu\n"
        L"CheckPt\t%lu\n"
        L"Wait\t%lu\n",
        argv[1],
        ssp.dwServiceType,
        ssp.dwCurrentState,
        ssp.dwControlsAccepted,
        ssp.dwCheckPoint,
        ssp.dwWaitHint);
gives:

Code:
Name    spooler
Type    272
State   4
Control 69
CheckPt 0
Wait    0
 
May 20, 2008
11,530
102
Syracuse, NY, USA
I wrote:

Actually it seems you just have the indices for ControlsAccepted and CheckPoint switched, either in the help or in the code.
When looking at the SERVICE_STATUS_PROCESS struct (9 DWORDs) for the first time, I thought ... why not let the user specify any index (0-8) and let @SERVICE act thus:

Code:
    SERVICE_STATUS_PROCESS ssp;

    if ( QueryServiceStatusEx(..., (LPBYTE) &ssp, ...) )

        Sprintf(pszArgs, L"%lu", *((LPDWORD) &ssp + index));
That might simplify the code and provide the user with additional useful info (dwWin32ExitCode, dwServiceSpecificExitCode, dwProcessId, and dwServiceFlags). The help already documents the hard ones. :-)
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
vefatica wrote:

> @SERVICE seems better that it was, but it gives unexpected results.
>
> For info level 3, it always returns 0. I tried about a dozen services, many of which I know can be stopped.
>
> For info level 4, it sometimes gives values that seem rather large (spooler = 69, diskeeper = 65, eventlog = 4).

3 and 4 are reversed in the help; the help has been corrected for the
next build.


> For info level 5, it always returns 0, which I suppose could be correct. But I know from experience that these operations don't happen instantly. OTOH, if the SCM asks the service for the estimate, the service itself might not bother to give a meaningful one.

You'll have to argue with MS on that one; @SERVICES is just returning
what the EnumServicesStatus API says.

Rex Conn
JP Software
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
vefatica wrote:

> When looking at the SERVICE_STATUS_PROCESS struct (9 DWORDs) for the first time, I thought ... why not let the user specify any index (0-8) and let @SERVICE act thus:
> ---------
> SERVICE_STATUS_PROCESS ssp;
>
> if ( QueryServiceStatusEx(..., (LPBYTE) &ssp, ...) )
>
> Sprintf(pszArgs, L"%lu", *((LPDWORD) &ssp + index));
> ---------
> That might simplify the code and provide the user with additional useful info (dwWin32ExitCode, dwServiceSpecificExitCode, dwProcessId, and dwServiceFlags). The help already documents the hard ones. :-)

I've never seen a service that set (or documented) dwWin32ExitCode or
dwServiceSpecificExitCode, so unless you were writing your own service
those would probably be useless.

@SERVICES uses SERVICE_STATUS, not SERVICE_STATUS_PROCESS, so there is
no dwProcessId or dwServiceFlags. (I can't think of a use for them --
why would you care about those values?)

Rex Conn
JP Software
 
May 20, 2008
11,530
102
Syracuse, NY, USA
On Mon, 18 May 2009 22:47:54 -0500, rconn <> wrote:

|@SERVICES uses SERVICE_STATUS, not SERVICE_STATUS_PROCESS, so there is
|no dwProcessId or dwServiceFlags. (I can't think of a use for them --
|why would you care about those values?)

I can't imagine a use for @SERVICE at all. But I suppose someone has/will. But
I'd think the PID of the process it's running in (not obvious without
"...\system32\tasklist /svc") might be of interest to someone using @SERVICE at
all.

I suppose dwWin32ExitCode is the EXE's exit code (service or svchost) while
dwServiceSpecificExitCode can be set by a service DLL. I write my own; have
used my w32tm.dll as a replacement for w32time.dll for years. It sets
dwServiceSpecificExitCode, to 0 typically, but to non-zero if it can't
initialize.
--
- Vince
 
May 20, 2008
11,530
102
Syracuse, NY, USA
Code:
SERVICE_STATUS_PROCESS ssp;

if ( QueryServiceStatusEx(..., (LPBYTE) &ssp, ...) )

    Sprintf(pszArgs, L"%lu", *((LPDWORD) &ssp + index));
Just in case you wanted to go that route, I made a corresponding f_service.htm. It's attached.

The HTML editor from VS2008 wasn't much fun ... got a recommendation?
 

Attachments

  • f_service.zip
    2.8 KB · Views: 84
Similar threads
Thread starter Title Forum Replies Date
A Installers delete EVerything service if already installed Support 0
CWBillow Everything as a service Support 2
R Everything service locking thumb drives Support 1
Steve Pitts Insufficient system resources exist to complete the requested service Support 1
B What Don't I Understand About @SERVICE Support 9
sully9 How to? Unexpected %DATE% CMD variable format (vs DATE /T format) in CMDebug Support 1
vefatica @FILESIZE[] ... allocated ... unexpected results Support 0
T WAD Strange Unexpected "features" in the Debugger Support 2
Mike Hall Unexpected "Variable loop" in IF condition Support 10
rps How to? dir /s unexpected results Support 10
R Unexpected 'Cancel Batch Job' prompts Support 13
A How to? PhraseExpress autotext/autocompletion printing unexpected characters Support 4
S Unexpected error report Support 7
D Unexpected behavior Support 8
H TPIPE: /FILTER and /OUTPUT unexpected incompatibility Support 6
M How to? Work around an unexpected and very inconvenient behavior of TCC... Support 26
M Unexpected Results from Doing Numeric Comparisons... Support 17
F unexpected %1 while starting ide Support 6
Emilio III Unexpected file deletion Support 30
S RECYCLE /P - unexpected behavior Support 0
I on error[msg] unexpected behaviour Support 0
C blank line in copy ... results Support 9
F strange results Support 9
Joe Caverly DrawVLine results different in TCMD tab and detached TCC Support 11
W pdir returns diff results between tcc and tcmd - one is an error msg Support 5
rps @FILESIZE[....,a] allocated size not matching Dir results Support 8
thorntonpg @eval function, interesting results any explanation? Support 3
Steve Pitts WAD @MD5 returns incorrect results for strings Support 2
J WAD utf8decode string only results in ? chars Support 2
T Associating BTM files with IDE results in DOS box Support 33
M Why does this code produce these results? Support 2
M Why is this function getting these results in these circumstances? Support 6
JohnQSmith WAD Incorrect results from @FILESIZE Support 9
S Trouble accessing results of forum search Support 2
beerns different results between tcmd and cmd Support 2
daniel347x Different results with TCC than with cmd.exe Support 2
vefatica Strange results with CP 1252 Support 12
dcantor LIST /X and TYPE /X give different results Support 20
T Concatenate echoed text with the results of a grep command? Support 2

Similar threads