| |

VerySource

 Forgot password?
 Register
Search
View: 597|Reply: 3

How to run the specified program?

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-21 21:30:02
| Show all posts |Read mode
The requirement is: given a process name, how do I run this given program in the application code?
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-6-29 15:00:01
| Show all posts
For example: there is a program under the directory c:\windows\is setup.exe
How to make this program run in the VC code?
Reply

Use magic Report

0

Threads

14

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-6-29 15:45:02
| Show all posts
Run the executable program at the specified location:

STARTUPINFO StartupInfo;
      PROCESS_INFORMATION ProInfo;
      DWORD ErrorCode;
   
      memset(&StartupInfo,0,sizeof(STARTUPINFO));
      StartupInfo.cb=sizeof(STARTUPINFO);
      StartupInfo.lpReserved=NULL;
      StartupInfo.lpDesktop=NULL;
      StartupInfo.lpTitle=NULL;
      StartupInfo.dwFlags=STARTF_USESHOWWINDOW;
      StartupInfo.cbReserved2=0;
      StartupInfo.lpReserved2=NULL;
      StartupInfo.wShowWindow=SW_SHOWNORMAL;
   
     bool bReturn=CreateProcess(NULL,"c:\\windows\\notepad.exe",NULL,
                                                                NULL, FALSE, 0, NULL, NULL,&StartupInfo,&ProInfo);
ErrorCode=GetLastError();

CloseHandle(ProInfo.hThread);
//Wait for the exit of the child process
WaitForSingleObject(ProInfo.hProcess, INFINITE);
//Get the exit code of the child process
GetExitCodeProcess(ProInfo.hProcess,&ErrorCode);
//Close the child process handle
CloseHandle(ProInfo.hProcess);
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-6-30 13:00:01
| Show all posts
let me try
Thank you first brother upstairs
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list