Archived

This topic is now archived and is closed to further replies.

about CreateProcess()

This topic is 5175 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m getting really tired of looking through these lines of code... all that happens is that QLMonitor- the executable- goes into a loop. WCHAR TargetDirectoryPath[MAX_PATH] = L"C:\\QLProtected"; if(DoesFolderExist(TargetDirectoryPath)) { //if(DoTheseFilesExist(TargetDirectoryPath, "QLMonitor.exe", "QLDriver.sys")) WCHAR CurrentDirectoryPath[MAX_PATH]; GetCurrentDirectoryW(sizeof(CurrentDirectoryPath), CurrentDirectoryPath); if(0 != wcscmp(CurrentDirectoryPath, TargetDirectoryPath)) { CopyFileW(L"QLMonitor.exe", L"C:\\QLProtected\\QLMonitor.exe", FALSE); CopyFileW(L"QLDriver.sys", L"C:\\QLProtected\\QLDriver.sys", FALSE); STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); CreateProcess(NULL, "C:\\QLProtected\\QLMonitor.exe", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); //Reload the ''new'' executable... //WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return TRUE; } } else { CreateDirectoryW(TargetDirectoryPath, NULL); CopyFileW(L"QLMonitor.exe", L"C:\\QLProtected\\QLMonitor.exe", FALSE); CopyFileW(L"QLDriver.sys", L"C:\\QLProtected\\QLDriver.sys", FALSE); STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); CreateProcess(NULL, "C:\\QLProtected\\QLMonitor.exe", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); //Reload the ''new'' executable... //WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return TRUE; }

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Ok.... are you doing this for NT or where you HAVE to use the Unicode? If you for SURE don''t need the unicode take off those W''s..

The infinite loop may be occurring if the executable is a service that loads and runs in the background. If you don''t have to check to see if it terminated, then don''t.

Those CloseHandle() calls aren''t necessary, because the process and thread handles are closed when the executable that you run with CreateProcess terminates... So if that is the only code that runs after the program closes, you don''t even need to use WaitForSingleObject to wait for the process... (In that case you might just use WinExec to run the EXE, since it would be easier coding)

Share this post


Link to post
Share on other sites