HINSTANCE handle = ::LoadLibrary(_T("Advapi32.dll"));
if (handle == NULL)
return;
pConvertSidToStringSid = (tConvertSidToStringSid) ::GetProcAddress(handle, "ConvertSidToStringSidA");
if (pConvertSidToStringSid)
{
/// call the fucntion with your parameter
pConvertSidToStringSid(&userSID, chSID);
}
::FreeLibrary(handle);
Cheers
NoHero
December 7th, 2005, 03:43 PM
Msdn says:
Client: Requires Windows XP or Windows 2000 Professional.
Server: Requires Windows Server 2003 or Windows 2000 Server.
Thus you need to redefine some macros before you can use this functions:
#define WIN32_WINNT 0x0501
#define WINVER 0x0501 // both combied stand for Windows XP
#include <sddl.h>
Not your program will fail when run under Win2k and lower. So golansahar's solution with proper error handling might be the better choice.
ProgMaster
December 7th, 2005, 05:54 PM
****...
The memory could not be "read"
That what i receive. How to solve this problem ??? Here is my code:
HINSTANCE handle = ::LoadLibrary("Advapi32.dll");
if (handle == NULL) return;
MessageBox(NULL, "step 3", "step 3", MB_OK);
pConvertSidToStringSid = (tConvertSidToStringSid) ::GetProcAddress(handle, "ConvertSidToStringSidA");
if (pConvertSidToStringSid)
{
/// call the fucntion with your parameter
pConvertSidToStringSid(&userSID, &chSID);
}
::FreeLibrary(handle);
MessageBox(NULL, chSID, "SID", MB_OK);
LocalFree((HLOCAL)chSID);
I've tested this and what i found. Message "step 1" i receive, but second message i dont receive. Thats means that it crashes at:
if(!LookupAccountName(NULL, chCurrentUser, &userSID, &dwSID, NULL, NULL, NULL))
But i cant understand why ???? What im doing wrong ?
golanshahar
December 9th, 2005, 04:42 AM
I've tested this and what i found. Message "step 1" i receive, but second message i dont receive. Thats means that it crashes at:
But i cant understand why ???? What im doing wrong ?
Applied all you tip me. But error didnt dissappear :(. Repeating: i receive exception with message:
the memory cound bot be "read"
This error appears on line after first MessageBox (Step 1), i mean here:
if(!LookupAccountName(NULL, chCurrentUser, &userSID, &dwSID, szRef, &cbRef, NULL))
before step 2.
Here is once more UPDATED code:
// Retrieving currently logged user name
DWORD dwUserBuf = 256;
char chCurrentUser[256] = {0};
HINSTANCE handle = ::LoadLibrary("Advapi32.dll");
if (handle == NULL) return;
MessageBox(NULL, "step 3", "step 3", MB_OK);
pConvertSidToStringSid = (tConvertSidToStringSid) ::GetProcAddress(handle, "ConvertSidToStringSidA");
if (pConvertSidToStringSid)
{
/// call the fucntion with your parameter
pConvertSidToStringSid(&userSID, &chSID);
}
::FreeLibrary(handle);
HINSTANCE handle = ::LoadLibrary("Advapi32.dll");
if (handle == NULL)
return;
pConvertSidToStringSid = (tConvertSidToStringSid) ::GetProcAddress(handle, "ConvertSidToStringSidA");
if (pConvertSidToStringSid)
{
/// call the fucntion with your parameter
pConvertSidToStringSid(&userSID, chSID);
}
::FreeLibrary(handle);
MessageBox(NULL, chSID, "SID", MB_OK);
LocalFree((HLOCAL)chSID);
But now there is ANOTHER PROBLEM !!! Because im service, GetUserName returns me "SYSTEM" :(. How can i now to know what is REAL CURRENT LY LOGGED USER name ?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.