ShellExecute and CreateProcess, run a program until it ends, secretly run a program...

Source: Internet
Author: User

How to open an application?

ShellExecute(this->m_hWnd,"open","calc.exe","","", SW_SHOW );

Or

ShellExecute(this->m_hWnd,"open","notepad.exe",    "c://MyLog.log","",SW_SHOW );

As you can see, I have not passed the complete path of the program.
Q: How do I open a file related to the same system program?

ShellExecute(this->m_hWnd,"open",    "c://abc.txt","","",SW_SHOW );

Q: How to open a webpage?

ShellExecute(this->m_hWnd,"open",    "http://www.google.com","","", SW_SHOW );

Q: How to activate related programs and send emails?

ShellExecute(this->m_hWnd,"open",    "mailto:nishinapp@yahoo.com","","", SW_SHOW );

Q: How do I print documents with a system printer?

ShellExecute(this->m_hWnd,"print",    "c://abc.txt","","", SW_HIDE);

Q: How can I use the system search function to find a specified file?

ShellExecute(m_hWnd,"find","d://nish",    NULL,NULL,SW_SHOW);

Q: How do I start a program until it finishes running?

SHELLEXECUTEINFO ShExecInfo = {0};ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;ShExecInfo.hwnd = NULL;ShExecInfo.lpVerb = NULL;ShExecInfo.lpFile = "c://MyProgram.exe";ShExecInfo.lpParameters = "";ShExecInfo.lpDirectory = NULL;ShExecInfo.nShow = SW_SHOW;ShExecInfo.hInstApp = NULL;ShellExecuteEx(&ShExecInfo);WaitForSingleObject(ShExecInfo.hProcess,INFINITE);

Or:

PROCESS_INFORMATION ProcessInfo; STARTUPINFO StartupInfo; //This is an [in] parameterZeroMemory(&StartupInfo, sizeof(StartupInfo));StartupInfo.cb = sizeof StartupInfo ; //Only compulsory fieldif(CreateProcess("c://winnt//notepad.exe", NULL,     NULL,NULL,FALSE,0,NULL,    NULL,&StartupInfo,&ProcessInfo)){     WaitForSingleObject(ProcessInfo.hProcess,INFINITE);    CloseHandle(ProcessInfo.hThread);    CloseHandle(ProcessInfo.hProcess);}  else{    MessageBox("The process could not be started...");}

Q: How do I display attributes of a file or folder?

SHELLEXECUTEINFO ShExecInfo ={0};ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);ShExecInfo.fMask = SEE_MASK_INVOKEIDLIST ;ShExecInfo.hwnd = NULL;ShExecInfo.lpVerb = "properties";ShExecInfo.lpFile = "c://"; //can be a file as wellShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL;ShExecInfo.nShow = SW_SHOW;ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.