BOOL CVistaCreateProcess::RunElevated(HWND hwnd, LPCSTR pszPath, LPCSTR pszParameters, LPCSTR pszDirectory) { return MyShellExec( hwnd, "runas", pszPath, pszParameters, pszDirectory ); }
int main () { int argc; //TCHAR charBuf[BUFFERSIZE]; LPTSTR KeePassRPCSource; LPTSTR KeePassRPCDest; LPWSTR commandLine = GetCommandLineW(); int bufSize = lstrlen(commandLine); //TODO2: a bit too cautious TCHAR charBuf[4096];// = L""; for (int j=0; j<4096; j++) charBuf[j] = '\0'; LPTSTR cmdParams = (LPTSTR) charBuf; // SecureZeroMemory(&cmdParams, 4096); // extract the command line parameters and check there is the right quantity LPTSTR *argv = ::CommandLineToArgvW(commandLine,&argc); if (argc <= 1) { LocalFree(argv); // printf("a"); return 1; } for (int i=2; i<argc; i++) { if (FAILED(StringCchCat(cmdParams,lstrlen(cmdParams)+lstrlen(argv[i])+1,argv[i]))) { LocalFree(argv); // printf("b"); return 1; } } int result = 0; if (IsVista()) result = MyShellExec( NULL, L"runas", argv[1], cmdParams,L"", TRUE ); else result = MyShellExec( NULL, L"open", argv[1], cmdParams,L"", TRUE ); //printf("c"); LocalFree(argv); return result; //// define 1KB buffers for each file path (should be more than enough ////for any path length for forseeable future and is already longer ////than current MAX_PATH windows constant) // KeePassRPCSource = (LPTSTR) charBuf; //KeePassRPCDest = (LPTSTR) charBuf+(INDIVIDUALBUFFERSIZE); //// populate the string buffers with the directory path to each file we're interested in // if (FAILED(StringCchCopy( // KeePassRPCSource, // INDIVIDUALBUFFERSIZE-(sizeof(TCHAR)*lstrlen(L"\\KeePassRPC.plgx")), // argv[1]))) // { // LocalFree(argv); // return 1; // } //if (FAILED(StringCchCopy( // KeePassRPCDest, // INDIVIDUALBUFFERSIZE-(sizeof(TCHAR)*lstrlen(L"\\KeePassRPC.plgx")), // argv[2]))) // { // LocalFree(argv); // return 1; // } //// create the plugins directory if required //if (!fileExists(argv[2])) // CreateDirectoryW(argv[2],NULL); // //LocalFree(argv); //// append the name of each file so we end up with full paths to the files we need //if (FAILED(StringCchCat(KeePassRPCSource,INDIVIDUALBUFFERSIZE,L"\\KeePassRPC.plgx"))) // return 1; //if (FAILED(StringCchCat(KeePassRPCDest,INDIVIDUALBUFFERSIZE,L"\\KeePassRPC.plgx"))) // return 1; //// copy the file to its new home //if (::CopyFileW (KeePassRPCSource, KeePassRPCDest, false)) // return 0; // everything worked // return 1; // files couldn't be copied (most likely = permission // // denied but we can't be certain about that) }