Guest User

Untitled

a guest
Jun 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. CreateProcess(NULL, lpszCommandLine, NULL, NULL, FALSE,
  2. CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
  3.  
  4. DWORD RunSilent(char* strFunct, char* strstrParams)
  5. {
  6. STARTUPINFO StartupInfo;
  7. PROCESS_INFORMATION ProcessInfo;
  8. char Args[4096];
  9. char *pEnvCMD = NULL;
  10. char *pDefaultCMD = "CMD.EXE";
  11. ULONG rc;
  12.  
  13. memset(&StartupInfo, 0, sizeof(StartupInfo));
  14. StartupInfo.cb = sizeof(STARTUPINFO);
  15. StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
  16. StartupInfo.wShowWindow = SW_HIDE;
  17.  
  18. Args[0] = 0;
  19.  
  20. pEnvCMD = getenv("COMSPEC");
  21.  
  22. if(pEnvCMD){
  23.  
  24. strcpy(Args, pEnvCMD);
  25. }
  26. else{
  27. strcpy(Args, pDefaultCMD);
  28. }
  29.  
  30. // "/c" option - Do the command then terminate the command window
  31. strcat(Args, " /c ");
  32. //the application you would like to run from the command window
  33. strcat(Args, strFunct);
  34. strcat(Args, " ");
  35. //the parameters passed to the application being run from the command window.
  36. strcat(Args, strstrParams);
  37.  
  38. if (!CreateProcess( NULL, Args, NULL, NULL, FALSE,
  39. CREATE_NEW_CONSOLE,
  40. NULL,
  41. NULL,
  42. &StartupInfo,
  43. &ProcessInfo))
  44. {
  45. return GetLastError();
  46. }
  47.  
  48. WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
  49. if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc))
  50. rc = 0;
  51.  
  52. CloseHandle(ProcessInfo.hThread);
  53. CloseHandle(ProcessInfo.hProcess);
  54.  
  55. return rc;
  56.  
  57. }
Add Comment
Please, Sign In to add comment