|
Prev: Playback mouse input (or key strokes) using SendInput
Next: Can't find tsshutdn.exe on longhorn.
From: tsgd84 on 7 Jul 2008 09:47 Hi Everyone, I am writing a small application to spawn a particular app with different user credentials, I have attached my code snippet here, I am getting the error "The system cannot find the file specified." from the GetUserProfileDirectory method, DWORD dwSize; HANDLE hToken; LPVOID lpvEnv; PROCESS_INFORMATION pi = {0}; STARTUPINFO si = {0}; WCHAR szUserProfile[1024] = L""; si.cb = sizeof(STARTUPINFO); if( OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken) ) { LUID_AND_ATTRIBUTES la; if( LookupPrivilegeValue(NULL, SE_TCB_NAME, &la.Luid) ) { la.Attributes = SE_PRIVILEGE_ENABLED; TOKEN_PRIVILEGES tp; tp.PrivilegeCount = 1; tp.Privileges->Attributes = la.Attributes; tp.Privileges->Luid = la.Luid; if(!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) { string errorMsg = DisplayError(L"AdjustTokenPrivileges Failed"); this->LogMessage(errorMsg); return false; } } else { string errorMsg = DisplayError(L"LookupPrivilegeValue Failed"); this->LogMessage(errorMsg); return false; } } else { string errorMsg = DisplayError(L"OpenProcessToken Failed"); this->LogMessage(errorMsg); return false; } if( !LogonUser(wUserName, wRemoteDomainName, wpassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken) ) { string errorMsg = DisplayError(L"LogonUser Failed"); this->LogMessage(errorMsg); return false; } if (!CreateEnvironmentBlock(&lpvEnv, hToken, TRUE)) { string errorMsg = DisplayError(L"CreateEnvironmentBlock Failed"); this->LogMessage(errorMsg); } dwSize = sizeof(szUserProfile)/sizeof(WCHAR); if (!GetUserProfileDirectory(hToken, szUserProfile, &dwSize)) { string errorMsg = DisplayError(L"GetUserProfileDirectory Failed"); this->LogMessage(errorMsg); } if (!CreateProcessWithLogonW(wUserName, wRemoteDomainName, wpassword, LOGON_NETCREDENTIALS_ONLY, NULL, L"C:\\WINNT\\NOTEPAD.EXE", CREATE_UNICODE_ENVIRONMENT, lpvEnv, szUserProfile, &si, &pi)) { wprintf(L"szUserProfile value is :: %s", szUserProfile); string errorMsg = DisplayError(L"CreateProcessWithLogonW Failed"); this->LogMessage(errorMsg); return false; } if (!DestroyEnvironmentBlock(lpvEnv)) DisplayError(L"DestroyEnvironmentBlock"); CloseHandle(hToken); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); Any thouhths on this will be highly appreciated. Thanks in advance, Deenad
From: Kellie Fitton on 7 Jul 2008 14:59 On Jul 7, 6:47 am, tsgd84 <tsg...(a)gmail.com> wrote: > Hi Everyone, > > I am writing a small application to spawn a particular app with > different user credentials, > > I have attached my code snippet here, I am getting the error "The > system cannot find the file specified." from the > GetUserProfileDirectory method, > > DWORD dwSize; > HANDLE hToken; > LPVOID lpvEnv; > PROCESS_INFORMATION pi = {0}; > STARTUPINFO si = {0}; > WCHAR szUserProfile[1024] = L""; > > si.cb = sizeof(STARTUPINFO); > > if( OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | > TOKEN_QUERY, &hToken) ) > { > LUID_AND_ATTRIBUTES la; > if( LookupPrivilegeValue(NULL, SE_TCB_NAME, &la.Luid) ) > { > la.Attributes = SE_PRIVILEGE_ENABLED; > > TOKEN_PRIVILEGES tp; > tp.PrivilegeCount = 1; > tp.Privileges->Attributes = la.Attributes; > tp.Privileges->Luid = la.Luid; > if(!AdjustTokenPrivileges(hToken, FALSE, &tp, > sizeof(TOKEN_PRIVILEGES), NULL, NULL)) > { > string errorMsg = DisplayError(L"AdjustTokenPrivileges Failed"); > this->LogMessage(errorMsg); > return false; > } > } > else > { > string errorMsg = DisplayError(L"LookupPrivilegeValue Failed"); > this->LogMessage(errorMsg); > return false; > } > } > else > { > string errorMsg = DisplayError(L"OpenProcessToken Failed"); > this->LogMessage(errorMsg); > return false; > } > > if( !LogonUser(wUserName, wRemoteDomainName, wpassword, > LOGON32_LOGON_INTERACTIVE, > LOGON32_PROVIDER_DEFAULT, &hToken) ) { > string errorMsg = DisplayError(L"LogonUser Failed"); > this->LogMessage(errorMsg); > return false; > } > > if (!CreateEnvironmentBlock(&lpvEnv, hToken, TRUE)) { > string errorMsg = DisplayError(L"CreateEnvironmentBlock Failed"); > this->LogMessage(errorMsg); > } > > dwSize = sizeof(szUserProfile)/sizeof(WCHAR); > > if (!GetUserProfileDirectory(hToken, szUserProfile, &dwSize)) > { > string errorMsg = DisplayError(L"GetUserProfileDirectory Failed"); > this->LogMessage(errorMsg); > } > > if (!CreateProcessWithLogonW(wUserName, wRemoteDomainName, wpassword, > LOGON_NETCREDENTIALS_ONLY, NULL, L"C:\\WINNT\\NOTEPAD.EXE", > CREATE_UNICODE_ENVIRONMENT, lpvEnv, szUserProfile, > &si, &pi)) > { > wprintf(L"szUserProfile value is :: %s", szUserProfile); > string errorMsg = DisplayError(L"CreateProcessWithLogonW Failed"); > this->LogMessage(errorMsg); > return false; > } > > if (!DestroyEnvironmentBlock(lpvEnv)) > DisplayError(L"DestroyEnvironmentBlock"); > > CloseHandle(hToken); > CloseHandle(pi.hProcess); > CloseHandle(pi.hThread); > > Any thouhths on this will be highly appreciated. > > Thanks in advance, > > Deenad Hi, What happens when you use the following API to let the calling thread impersonate the user: LogonUser() ImpersonateLoggedOnUser() Also, if you do not want to enable the privilege SE_TCB_NAME, then you can use the API CreateProcessWithLogonW(), otherwise you should use the API CreateProcessAsUser(). http://msdn.microsoft.com/en-us/library/aa378612(VS.85).aspx Kellie.
From: tsgd84 on 8 Jul 2008 06:03 Hi, Thanks for the reply. In some of the win 2000 machines LogonUser fails with the error ERROR_PRIVILEGE_NOT_HELD [1314] But i have given the required privilege SE_TCB_NAME to the process using AdjustTokenPrivilege method before calling the LogonUser method Any suggestions? Thanks in advance, Deenad On Jul 7, 11:59 pm, Kellie Fitton <KELLIEFIT...(a)yahoo.com> wrote: > On Jul 7, 6:47 am, tsgd84 <tsg...(a)gmail.com> wrote: > > > > > Hi Everyone, > > > I am writing a small application to spawn a particular app with > > different user credentials, > > > I have attached my code snippet here, I am getting the error "The > > system cannot find the file specified." from the > > GetUserProfileDirectory method, > > > DWORD dwSize; > > HANDLE hToken; > > LPVOID lpvEnv; > > PROCESS_INFORMATION pi = {0}; > > STARTUPINFO si = {0}; > > WCHAR szUserProfile[1024] = L""; > > > si.cb = sizeof(STARTUPINFO); > > > if( OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | > > TOKEN_QUERY, &hToken) ) > > { > > LUID_AND_ATTRIBUTES la; > > if( LookupPrivilegeValue(NULL, SE_TCB_NAME, &la.Luid) ) > > { > > la.Attributes = SE_PRIVILEGE_ENABLED; > > > TOKEN_PRIVILEGES tp; > > tp.PrivilegeCount = 1; > > tp.Privileges->Attributes = la.Attributes; > > tp.Privileges->Luid = la.Luid; > > if(!AdjustTokenPrivileges(hToken, FALSE, &tp, > > sizeof(TOKEN_PRIVILEGES), NULL, NULL)) > > { > > string errorMsg = DisplayError(L"AdjustTokenPrivileges Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > } > > else > > { > > string errorMsg = DisplayError(L"LookupPrivilegeValue Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > } > > else > > { > > string errorMsg = DisplayError(L"OpenProcessToken Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > > if( !LogonUser(wUserName, wRemoteDomainName, wpassword, > > LOGON32_LOGON_INTERACTIVE, > > LOGON32_PROVIDER_DEFAULT, &hToken) ) { > > string errorMsg = DisplayError(L"LogonUser Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > > if (!CreateEnvironmentBlock(&lpvEnv, hToken, TRUE)) { > > string errorMsg = DisplayError(L"CreateEnvironmentBlock Failed"); > > this->LogMessage(errorMsg); > > } > > > dwSize = sizeof(szUserProfile)/sizeof(WCHAR); > > > if (!GetUserProfileDirectory(hToken, szUserProfile, &dwSize)) > > { > > string errorMsg = DisplayError(L"GetUserProfileDirectory Failed"); > > this->LogMessage(errorMsg); > > } > > > if (!CreateProcessWithLogonW(wUserName, wRemoteDomainName, wpassword, > > LOGON_NETCREDENTIALS_ONLY, NULL, L"C:\\WINNT\\NOTEPAD.EXE", > > CREATE_UNICODE_ENVIRONMENT, lpvEnv, szUserProfile, > > &si, &pi)) > > { > > wprintf(L"szUserProfile value is :: %s", szUserProfile); > > string errorMsg = DisplayError(L"CreateProcessWithLogonW Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > > if (!DestroyEnvironmentBlock(lpvEnv)) > > DisplayError(L"DestroyEnvironmentBlock"); > > > CloseHandle(hToken); > > CloseHandle(pi.hProcess); > > CloseHandle(pi.hThread); > > > Any thouhths on this will be highly appreciated. > > > Thanks in advance, > > > Deenad > > Hi, > > What happens when you use the following API to let the > calling thread impersonate the user: > > LogonUser() > > ImpersonateLoggedOnUser() > > Also, if you do not want to enable the privilege SE_TCB_NAME, > then you can use the API CreateProcessWithLogonW(), otherwise > you should use the API CreateProcessAsUser(). > > http://msdn.microsoft.com/en-us/library/aa378612(VS.85).aspx > > Kellie.
From: tsgd84 on 8 Jul 2008 07:05 Hi, In some win2k machines, LogonUser function is getting failed with the error ERROR_PRIVILEGE_NOT_HELD [1314]. Any suggestions.... Thanks On Jul 7, 11:59 pm, Kellie Fitton <KELLIEFIT...(a)yahoo.com> wrote: > On Jul 7, 6:47 am, tsgd84 <tsg...(a)gmail.com> wrote: > > > > > Hi Everyone, > > > I am writing a small application to spawn a particular app with > > different user credentials, > > > I have attached my code snippet here, I am getting the error "The > > system cannot find the file specified." from the > > GetUserProfileDirectory method, > > > DWORD dwSize; > > HANDLE hToken; > > LPVOID lpvEnv; > > PROCESS_INFORMATION pi = {0}; > > STARTUPINFO si = {0}; > > WCHAR szUserProfile[1024] = L""; > > > si.cb = sizeof(STARTUPINFO); > > > if( OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | > > TOKEN_QUERY, &hToken) ) > > { > > LUID_AND_ATTRIBUTES la; > > if( LookupPrivilegeValue(NULL, SE_TCB_NAME, &la.Luid) ) > > { > > la.Attributes = SE_PRIVILEGE_ENABLED; > > > TOKEN_PRIVILEGES tp; > > tp.PrivilegeCount = 1; > > tp.Privileges->Attributes = la.Attributes; > > tp.Privileges->Luid = la.Luid; > > if(!AdjustTokenPrivileges(hToken, FALSE, &tp, > > sizeof(TOKEN_PRIVILEGES), NULL, NULL)) > > { > > string errorMsg = DisplayError(L"AdjustTokenPrivileges Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > } > > else > > { > > string errorMsg = DisplayError(L"LookupPrivilegeValue Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > } > > else > > { > > string errorMsg = DisplayError(L"OpenProcessToken Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > > if( !LogonUser(wUserName, wRemoteDomainName, wpassword, > > LOGON32_LOGON_INTERACTIVE, > > LOGON32_PROVIDER_DEFAULT, &hToken) ) { > > string errorMsg = DisplayError(L"LogonUser Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > > if (!CreateEnvironmentBlock(&lpvEnv, hToken, TRUE)) { > > string errorMsg = DisplayError(L"CreateEnvironmentBlock Failed"); > > this->LogMessage(errorMsg); > > } > > > dwSize = sizeof(szUserProfile)/sizeof(WCHAR); > > > if (!GetUserProfileDirectory(hToken, szUserProfile, &dwSize)) > > { > > string errorMsg = DisplayError(L"GetUserProfileDirectory Failed"); > > this->LogMessage(errorMsg); > > } > > > if (!CreateProcessWithLogonW(wUserName, wRemoteDomainName, wpassword, > > LOGON_NETCREDENTIALS_ONLY, NULL, L"C:\\WINNT\\NOTEPAD.EXE", > > CREATE_UNICODE_ENVIRONMENT, lpvEnv, szUserProfile, > > &si, &pi)) > > { > > wprintf(L"szUserProfile value is :: %s", szUserProfile); > > string errorMsg = DisplayError(L"CreateProcessWithLogonW Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > > if (!DestroyEnvironmentBlock(lpvEnv)) > > DisplayError(L"DestroyEnvironmentBlock"); > > > CloseHandle(hToken); > > CloseHandle(pi.hProcess); > > CloseHandle(pi.hThread); > > > Any thouhths on this will be highly appreciated. > > > Thanks in advance, > > > Deenad > > Hi, > > What happens when you use the following API to let the > calling thread impersonate the user: > > LogonUser() > > ImpersonateLoggedOnUser() > > Also, if you do not want to enable the privilege SE_TCB_NAME, > then you can use the API CreateProcessWithLogonW(), otherwise > you should use the API CreateProcessAsUser(). > > http://msdn.microsoft.com/en-us/library/aa378612(VS.85).aspx > > Kellie.
From: tsgd84 on 8 Jul 2008 08:21 On Jul 7, 11:59 pm, Kellie Fitton <KELLIEFIT...(a)yahoo.com> wrote: > On Jul 7, 6:47 am, tsgd84 <tsg...(a)gmail.com> wrote: > > > > > Hi Everyone, > > > I am writing a small application to spawn a particular app with > > different user credentials, > > > I have attached my code snippet here, I am getting the error "The > > system cannot find the file specified." from the > > GetUserProfileDirectory method, > > > DWORD dwSize; > > HANDLE hToken; > > LPVOID lpvEnv; > > PROCESS_INFORMATION pi = {0}; > > STARTUPINFO si = {0}; > > WCHAR szUserProfile[1024] = L""; > > > si.cb = sizeof(STARTUPINFO); > > > if( OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | > > TOKEN_QUERY, &hToken) ) > > { > > LUID_AND_ATTRIBUTES la; > > if( LookupPrivilegeValue(NULL, SE_TCB_NAME, &la.Luid) ) > > { > > la.Attributes = SE_PRIVILEGE_ENABLED; > > > TOKEN_PRIVILEGES tp; > > tp.PrivilegeCount = 1; > > tp.Privileges->Attributes = la.Attributes; > > tp.Privileges->Luid = la.Luid; > > if(!AdjustTokenPrivileges(hToken, FALSE, &tp, > > sizeof(TOKEN_PRIVILEGES), NULL, NULL)) > > { > > string errorMsg = DisplayError(L"AdjustTokenPrivileges Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > } > > else > > { > > string errorMsg = DisplayError(L"LookupPrivilegeValue Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > } > > else > > { > > string errorMsg = DisplayError(L"OpenProcessToken Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > > if( !LogonUser(wUserName, wRemoteDomainName, wpassword, > > LOGON32_LOGON_INTERACTIVE, > > LOGON32_PROVIDER_DEFAULT, &hToken) ) { > > string errorMsg = DisplayError(L"LogonUser Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > > if (!CreateEnvironmentBlock(&lpvEnv, hToken, TRUE)) { > > string errorMsg = DisplayError(L"CreateEnvironmentBlock Failed"); > > this->LogMessage(errorMsg); > > } > > > dwSize = sizeof(szUserProfile)/sizeof(WCHAR); > > > if (!GetUserProfileDirectory(hToken, szUserProfile, &dwSize)) > > { > > string errorMsg = DisplayError(L"GetUserProfileDirectory Failed"); > > this->LogMessage(errorMsg); > > } > > > if (!CreateProcessWithLogonW(wUserName, wRemoteDomainName, wpassword, > > LOGON_NETCREDENTIALS_ONLY, NULL, L"C:\\WINNT\\NOTEPAD.EXE", > > CREATE_UNICODE_ENVIRONMENT, lpvEnv, szUserProfile, > > &si, &pi)) > > { > > wprintf(L"szUserProfile value is :: %s", szUserProfile); > > string errorMsg = DisplayError(L"CreateProcessWithLogonW Failed"); > > this->LogMessage(errorMsg); > > return false; > > } > > > if (!DestroyEnvironmentBlock(lpvEnv)) > > DisplayError(L"DestroyEnvironmentBlock"); > > > CloseHandle(hToken); > > CloseHandle(pi.hProcess); > > CloseHandle(pi.hThread); > > > Any thouhths on this will be highly appreciated. > > > Thanks in advance, > > > Deenad > > Hi, > > What happens when you use the following API to let the > calling thread impersonate the user: > > LogonUser() > > ImpersonateLoggedOnUser() > > Also, if you do not want to enable the privilege SE_TCB_NAME, > then you can use the API CreateProcessWithLogonW(), otherwise > you should use the API CreateProcessAsUser(). > > http://msdn.microsoft.com/en-us/library/aa378612(VS.85).aspx > > Kellie. Hi, In some win2k machines, LogonUser function is getting failed with the error ERROR_PRIVILEGE_NOT_HELD [1314]. Any suggestions.... Thanks
|
Next
|
Last
Pages: 1 2 3 Prev: Playback mouse input (or key strokes) using SendInput Next: Can't find tsshutdn.exe on longhorn. |