Search Results

Search found 2 results on 1 pages for 'kampi'.

Page 1/1 | 1 

  • How to read registry correctly for multiple values in c?

    - by kampi
    Hi! I created a .dll which should work like the RunAs command. The only difference is, that it should read from registry. My problem is, that i need to reed 3 values from the registry, but i can't. It reads the first, than it fails at the second one (Password) with error code 2, which means "The system cannot find the file specified". If i query only for domain and username then it is ok, if i query only for password then it it still succeeds, but if i want to query all three then it fails. Can someone tell me, what i am doing wrong? Heres my code: HKEY hKey = 0; DWORD dwType = REG_SZ; DWORD dwBufSize = sizeof(buf); TCHAR szMsg [MAX_PATH + 32]; HANDLE handle; LPVOID lpMsgBuf; if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("SOFTWARE\\Kampi Corporation\\RunAs!"), 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS ) { if( RegQueryValueEx( hKey, TEXT("Username"), 0, &dwType, (LPBYTE)buf, &dwBufSize ) == ERROR_SUCCESS ) { memset( szMsg, 0, sizeof( szMsg ) ); wsprintf ( szMsg, _T("%s"), buf ); mbstowcs( wuser, szMsg, 255 ); RegCloseKey( hKey ); } else { MessageBox ( pCmdInfo->hwnd, "Can not query for Username key value!", _T("RunAs!"), MB_ICONERROR ); RegCloseKey( hKey ); return -1; } } else { CSimpleShlExt::showerror( GetLastError(), pCmdInfo->hwnd, "RegOpenKeyEx failed for Username with error code :: " ); return -1; } if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("SOFTWARE\\Kampi Corporation\\RunAs!"), 0, KEY_QUERY_VALUE ,&hKey ) == ERROR_SUCCESS ) { if( RegQueryValueEx( hKey, TEXT("Password"), 0, &dwType, (LPBYTE)buf, &dwBufSize ) == ERROR_SUCCESS ) { memset( szMsg, 0, sizeof( szMsg ) ); wsprintf ( szMsg, _T("%s"), buf ); mbstowcs( wpass, szMsg, 255 ); RegCloseKey( hKey ); } else { char test[200]; sprintf(test,"Can not query for Password key value! EC: %d",GetLastError() ); MessageBox ( pCmdInfo->hwnd, test, _T("RunAs!"), MB_ICONERROR ); RegCloseKey( hKey ); return -1; } } else { CSimpleShlExt::showerror( GetLastError(), pCmdInfo->hwnd, "RegOpenKeyEx failed for Password with error code :: " ); return -1; } if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("SOFTWARE\\Kampi Corporation\\RunAs!"), 0, KEY_QUERY_VALUE ,&hKey ) == ERROR_SUCCESS ) { if( RegQueryValueEx( hKey, TEXT("Domain"), 0, &dwType, (LPBYTE)buf, &dwBufSize ) == ERROR_SUCCESS ) { memset( szMsg, 0, sizeof( szMsg ) ); wsprintf ( szMsg, _T("%s"), buf ); mbstowcs( wdomain, szMsg, 255 ); RegCloseKey( hKey ); } else { char test[200]; sprintf(test,"Can not query for Password key value! EC: %d",GetLastError() ); MessageBox ( pCmdInfo->hwnd, test, _T("RunAs!"), MB_ICONERROR ); RegCloseKey( hKey ); return -1; } } else { CSimpleShlExt::showerror( GetLastError(), pCmdInfo->hwnd, "RegOpenKeyEx failed for Domain with error code :: " ); return -1; }

    Read the article

  • CreateProcessAsUser error 1314

    - by kampi
    Hi! I want create a process under another user. So I use LogonUser and CreateProcessAsUser. But my problem is, that CreatePtocessAsUser always returns the errorcode 1314, which means "A required privilige is not held by the client". So my question is, what I am doing wrong? Or how can i give the priviliges to the handle? (I think the handle should have the privileges, or I am wrong?) Sorry for my english mistakes, but my english knowledge isn't the best :) Plesase help if anyone knows how to correct my application. This a part of my code. STARTUPINFO StartInfo; PROCESS_INFORMATION ProcInfo; TOKEN_PRIVILEGES tp; memset(&ProcInfo, 0, sizeof(ProcInfo)); memset(&StartInfo, 0 , sizeof(StartInfo)); StartInfo.cb = sizeof(StartInfo); HANDLE handle = NULL; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &handle)) printf("\nOpenProcessError"); if (!LookupPrivilegeValue(NULL,SE_TCB_NAME, //SE_TCB_NAME, &tp.Privileges[0].Luid)) { printf("\nLookupPriv error"); } tp.PrivilegeCount = 1; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;//SE_PRIVILEGE_ENABLED; if (!AdjustTokenPrivileges(handle, FALSE, &tp, 0, NULL, 0)) { printf("\nAdjustToken error"); } i = LogonUser(user, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &handle); printf("\nLogonUser return : %d",i); i = GetLastError(); printf("\nLogonUser getlast : %d",i); if (! ImpersonateLoggedOnUser(handle) ) printf("\nImpLoggedOnUser!"); i = CreateProcessAsUser(handle, "c:\\windows\\system32\\notepad.exe",NULL, NULL, NULL, true, CREATE_UNICODE_ENVIRONMENT |NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, NULL, &StartInfo, &ProcInfo); printf("\nCreateProcessAsUser return : %d",i); i = GetLastError(); printf("\nCreateProcessAsUser getlast : %d",i); CloseHandle(handle); CloseHandle(ProcInfo.hProcess); CloseHandle(ProcInfo.hThread); Thanks in advance!

    Read the article

1