Click here to Skip to main content
15,899,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i want to get a computer domain sid without using lookupaccountname

problem is it fails if the computer boots up when the domain controller is off.

i want to get the domain sid even when machine disconnected or domain controller is off.

is it stored or cached any where in registry because i am able to login in domain even when computer is off because the user is cached ...so i think domain sid of machine is also cached somewhere.

is there any api which can give me domain sid.

i want it to work on winxp and win7 and above.
Posted
Updated 19-Jul-11 19:17pm
v2

1 solution

ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include <stdio.h>
#include <windows.h>
#include <lm.h>
int wmain(int argc, wchar_t *argv[])
{
DWORD dwLevel = 102;
LPWKSTA_INFO_102 pBuf = NULL;
NET_API_STATUS nStatus;
LPWSTR pszServerName = NULL;
//
// Check command line arguments.
//
if (argc > 2)
{
fwprintf(stderr, L"Usage: %s [\\\\ServerName]\n", argv[0]);
exit(1);
}
// The server is not the default local computer.
//
if (argc == 2)
pszServerName = argv[1];
//
// Call the NetWkstaGetInfo function, specifying level 102.
//
nStatus = NetWkstaGetInfo(pszServerName,
dwLevel,
(LPBYTE *)&pBuf);
//
// If the call is successful,
// print the workstation data.
//
if (nStatus == NERR_Success)
{
printf("\n\tPlatform: %d\n", pBuf->wki102_platform_id);
wprintf(L"\tName: %s\n", pBuf->wki102_computername);
printf("\tVersion: %d.%d\n", pBuf->wki102_ver_major,
pBuf->wki102_ver_minor);
wprintf(L"\tDomain: %s\n", pBuf->wki102_langroup);
wprintf(L"\tLan Root: %s\n", pBuf->wki102_lanroot);
wprintf(L"\t# Logged On Users: %d\n", pBuf->wki102_logged_on_users);
}
//
// Otherwise, indicate the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
return 0;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900