Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.93 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <chrono>
  4. #include <ctime>
  5.  
  6. void main( int argc, TCHAR *argv[] )
  7. {
  8.     STARTUPINFO si;
  9.     PROCESS_INFORMATION pi;
  10.  
  11.     ZeroMemory( &si, sizeof(si) );
  12.     si.cb = sizeof(si);
  13.     ZeroMemory( &pi, sizeof(pi) );
  14.  
  15.     if( argc != 2 )
  16.     {
  17.         printf("Usage: %s [cmdline]\n", argv[0]);
  18.         return;
  19.     }
  20.     auto parent_time = std::chrono::system_clock::now();
  21.     auto time_t_parent = std::chrono::system_clock::to_time_t(parent_time);
  22.     std::cout << "Parent: time: " << std::ctime(&time_t_parent);
  23.     Sleep(2000);
  24.     // Start the child process.
  25.     if( !CreateProcess( NULL,   // No module name (use command line)
  26.         argv[1],        // Command line
  27.         NULL,           // Process handle not inheritable
  28.         NULL,           // Thread handle not inheritable
  29.         FALSE,          // Set handle inheritance to FALSE
  30.         CREATE_NEW_CONSOLE,              // No creation flags
  31.         NULL,           // Use parent's environment block
  32.         NULL,           // Use parent's starting directory
  33.         &si,            // Pointer to STARTUPINFO structure
  34.         &pi )           // Pointer to PROCESS_INFORMATION structure
  35.     )
  36.     {
  37.         printf( "CreateProcess failed (%d).\n", GetLastError() );
  38.         return;
  39.     }
  40.    
  41.     // Wait until child process exits.
  42.     WaitForSingleObject( pi.hProcess, INFINITE );
  43.    
  44.     // Close process and thread handles.
  45.     CloseHandle( pi.hProcess );
  46.     CloseHandle( pi.hThread );
  47. }
  48. // void main(int argc, TCHAR *argv[]){
  49. //     STARTUPINFO si;
  50. //     PROCESS_INFORMATION pi;
  51.  
  52. //     // ZeroMemory( &si, sizeof(si) );
  53. //     // si.cb = sizeof(si);
  54. //     // ZeroMemory( &pi, sizeof(pi) );
  55.  
  56. //     // if( argc != 2 )
  57. //     // {
  58. //     //     printf("Usage: %s [cmdline]\n", argv[0]);
  59. //     //     return;
  60. //     // }
  61. //     TCHAR commandLine[] = TEXT("laba1Win64child_run.exe");
  62. //     // Start the child process.
  63. //     if( !CreateProcess( NULL,   // No module name (use command line)
  64. //         commandLine,        // Command line
  65. //         NULL,           // Process handle not inheritable
  66. //         NULL,           // Thread handle not inheritable
  67. //         FALSE,          // Set handle inheritance to FALSE
  68. //         CREATE_NEW_CONSOLE,              // No creation flags
  69. //         NULL,           // Use parent's environment block
  70. //         NULL,           // Use parent's starting directory
  71. //         &si,            // Pointer to STARTUPINFO structure
  72. //         &pi )           // Pointer to PROCESS_INFORMATION structure
  73. //     )
  74. //     {
  75. //         printf( "CreateProcess failed (%d).\n", GetLastError());
  76. //         return;
  77. //     }
  78.  
  79. //     // // Wait until child process exits.
  80. //     // WaitForSingleObject( pi.hProcess, INFINITE );
  81.  
  82. //     // // Close process and thread handles.
  83. //     // CloseHandle( pi.hProcess );
  84. //     // CloseHandle( pi.hThread );
  85. //   return ;
  86. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement