I just finished writing an application that our LAN Managers use to back up certain data and features from a user's machine. It works quite well (many thanks to those here who helped me to recursively search for files), but one feature that the LMs have requested is to grab a users drive mappings and write them out to the log file I'm using.
My first thought was to see if I could use the WNet functions to access a remote machine, but I couldn't find any documentation that would lead me to pursue that approach. I'm already using the registry on the remote machine to provide me with printer information, so that was my next thought for drive mappings. I knew this could be tricky because in the past, I have written services that load a user's profile, but in this case I won't be executing on the remote machine, only accessing it. So, knowing that the drive info is stored within the HKEY_USERS hive I thought I could leverage that. All the subkeys under that are SID's, and I figured that SID would correspond to the SID I could grab from calling LookupAccountName. So, I made the call, converted the SID to a string, but the SID I receive from the conversion does not match any of the SID subkey names under HKEY_USERS.
Does anyone know an easier way to pull a particular users drive mappings, or barring that, what I'm doing wrong?
Below is my function to lookup the SID and convert it to a string. It is incomplete at this point because I wanted to do a proof of concept to be reasonably sure I was getting a SID string I could then pass to RegOpenKey.
BOOL CFileBackupDlg::getMappings(CString strComputer, CString strUser)
const unsigned int MAX_NAME = 17;
char ch = '\0';
PSID psid = (PSID)SidBuffer;
DWORD cbSidBuff = 1024;
DWORD cbDomainName = sizeof (szDomain);
ch = strUser;
if ((ch == 'b') || (ch == 'B') || (ch == 'd') || (ch == 'D'))
lstrcpy (szDomain, "bell-atl-n");
if ((ch == 'v') || (ch == 'V') || (ch == 'z') || (ch == 'Z'))
lstrcpy (szDomain, "us1");
lstrcpy (szUser, szDomain);
lstrcat (szUser, "\\");
lstrcat (szUser, strUser);
if (!LookupAccountName (strComputer,
wsprintf (lpBuf, "SID lookup failed for user: %s in domain: %s\n", strUser, szDomain);
MessageBox (lpBuf, "Error in LookupAccountName", MB_OK |MB_ICONSTOP);
BOOL bRes = ConvertSidToStringSid (psid, &strSid);
MessageBox (strSid, "User SID", MB_OK);