I've been trying to use the SetupDiGetClassDevsEx() function in the
win32 API to retreive a list of installed devices on a remote system
with little success.
This function accepts several paramaters, one of which is PCTSTR
MachineName. If I pass NULL to this argument, then it works fine and I
get a list of devices on my local system. If I put a server name in
though, it fails and returns INVALID_HANDLE_VALUE.
Then, I call GetLastError() which returns -536870368. Which makes no
sense whatsoever. I tried using FormatMessage() on this result to no
avail. FormatMessage just returns:
ŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚ
ŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚ
ŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚ
ŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚŚ+EB
I have created an account with administrative privledges on the remote
machine with the same ID and password as the account I'm logged into on
my local machine.
If anyone has an idea of what's wrong, I'd appreciate it much. The
complete source code is attached below.
Thanks,
Shawn
// devlistproto.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <windows.h>
#include <string.h>
#include <Setupapi.h>
int _tmain(int argc, _TCHAR* argv[])
{
HDEVINFO hDevInfo;
//HDEVINFO hDevInfoJunk;
//hDevInfoJunk = SetupDiCreateDeviceInfoList(NULL, NULL);
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;
// Change the line below to PCTSTR RemoteSystem = ""; and it works...
for the local system
PCTSTR RemoteSystem = "\\arkadian8";
// Create a HDEVINFO with all present devices.
hDevInfo = SetupDiGetClassDevsEx(NULL,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_ALLCLASSES,
0,
RemoteSystem,
0);
if (hDevInfo == INVALID_HANDLE_VALUE)
{
// Insert error handling here.
char buffer[255];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buffer,
255,
NULL );
printf("GetLastError: %S", buffer);
return 1;
}
// Enumerate through all devices in Set.
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,
&DeviceInfoData);i++)
{
DWORD DataT;
LPTSTR buffer = NULL;
DWORD buffersize = 0;
//
// Call function with null to begin with,
// then use the returned buffer size
// to Alloc the buffer. Keep calling until
// success or an unknown failure.
//
while (!SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
SPDRP_DEVICEDESC,
&DataT,
(PBYTE)buffer,
buffersize,
&buffersize))
{
if (GetLastError() ==
ERROR_INSUFFICIENT_BUFFER)
{
// Change the buffer size.
if (buffer) LocalFree(buffer);
buffer = (LPTSTR)LocalAlloc(LPTR,buffersize);
}
else
{
// Insert error handling here.
break;
}
}
printf("Result:[%s]\n",buffer);
if (buffer) LocalFree(buffer);
}
if ( GetLastError()!=NO_ERROR &&
GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return 1;
}
// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
}
specifically, this error is:
SPAPI_E_INVALID_MACHINENAME
The specified machine name does not conform to UNC naming conventions.
make sure the server name you specify is in UNC format
(i.e. that the machine name is prefixed by "\\").
hope this helps,
jim.
"Shawn" <rigg...@surewest.net> wrote in message news:3DF78501...@surewest.net...