Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

QueryServiceConfig() broken

67 views
Skip to first unread message

Alec Dunn

unread,
Jul 31, 2003, 4:22:06 AM7/31/03
to
Has anybody else found this problem with
QueryServiceConfig()?

I'm querying a service that is known to exist (such as
Eventlog).

On Win 2000 SP4 and Win 2003 server it fails with
GetLastError() returning 1783 (RPC_X_BAD_STUB_DATA, "the
stub received bad data").

Previous versions of Win 2000, and XP work fine.

I've got some very simple sample code that demonstrates
the problem, if anybody at Microsoft wants to try.

Thanks in advance

Alec

Ken Wickes [MSFT]

unread,
Jul 31, 2003, 2:36:48 PM7/31/03
to
Can you post the code?

--

Ken Wickes [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.


"Alec Dunn" <AD...@syssol.com.au> wrote in message
news:0c2901c3573c$d44ac4f0$a101...@phx.gbl...

Alec Dunn

unread,
Aug 3, 2003, 12:55:44 AM8/3/03
to
Here's the code. I can't see how to post a zip file, so
this is just the C++ code. I'm using VS 2003.

// A program to test the QueryServiceConfig() function.
// This fails on Win 2000 SP 4, and on Win 2003 server,
// succeeds everywhere else.
//
// Alec Dunn, July 2003

// We need this to define CoInitializeEx
#define _WIN32_DCOM

#define UNICODE
#define _UNICODE

#include "windows.h"
#include "objbase.h" // for COINIT_MULTITHREADED

// Any service which is reliably present
#define SERVICENAME L"Eventlog"

// Display an error message box

static void msgBox(LPCTSTR caption)
{
TCHAR errString[40];
DWORD errCode = GetLastError();
wsprintf(errString, L"error = 0x%08x", errCode);
MessageBox(NULL, errString, caption, MB_OK);
}

// Simple test program

int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (FAILED(hr))
{
SetLastError(hr);
msgBox(L"CoInitializeEx");
return 0;
}

SC_HANDLE hSCM = OpenSCManager(NULL, NULL,
STANDARD_RIGHTS_READ);
if (hSCM == NULL)
{
msgBox(L"OpenSCManager failed");
return 0;
}
SC_HANDLE hSvc = OpenService(hSCM, SERVICENAME,
SERVICE_QUERY_CONFIG);
if (hSvc == NULL)
msgBox(L"OpenService failed");
else
{
DWORD dw;
BYTE configData[10000];
LPQUERY_SERVICE_CONFIG psc = (LPQUERY_SERVICE_CONFIG)
configData;
if (!QueryServiceConfig(hSvc, psc, sizeof(configData),
&dw))
msgBox(L"QueryServiceConfig failed");
else
MessageBox(NULL, L"QueryServiceConfig succeeded",
L"Test", MB_OK);
CloseServiceHandle(hSvc);
}
CloseServiceHandle(hSCM);
CoUninitialize();
return 0;
}

>.
>

Ken Wickes [MSFT]

unread,
Aug 5, 2003, 3:51:36 PM8/5/03
to
Works fine for me. I wonder if you have a mismatched set of system files.
You might try a "sfc /scannow".

--

Ken Wickes [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.


"Alec Dunn" <ad...@syssol.com.au> wrote in message
news:757101c3597b$7efdfd50$a001...@phx.gbl...

Alec Dunn

unread,
Aug 6, 2003, 4:29:52 AM8/6/03
to
The problem occurs if the buffer size argument to
QueryServiceConfig() is 10K or more. There is no problem
if the buffer size is 5K. So it looks like some sanity
checking inside Win 2003 is causing the problem. My
thanks to Joseph J. Cracchiolo for working this out.

Here is a C function to work around the problem.

QUERY_SERVICE_CONFIG *queryServiceConfig(SC_HANDLE
hService)
{
// Find the required buffer size
DWORD dw;
QueryServiceConfig(hService, NULL, 0, &dw);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return NULL;

// Allocate the buffer and query the service
QUERY_SERVICE_CONFIG *pConfig = (LPQUERY_SERVICE_CONFIG)
LocalAlloc(LMEM_FIXED, dw);
if (pConfig == NULL)
return NULL;
if (!QueryServiceConfig(hService, pConfig, dw, &dw))
{
// Failed, so release the buffer and return NULL
dw = GetLastError();
LocalFree(pConfig);
SetLastError(dw);
return NULL;
}

// Successful
return pConfig;
}

0 new messages