Three methods for creating a process

Source: Internet
Author: User

Http://hi.baidu.com/magicfuzzx/item/284b1dd7c3087c0a20e2500e

Shellapi is characteristic of defining a struct and then calling a function. The parameter of this function is usually the pointer of this struct, such as the shellexecuteinfo struct in this example.

Void cprocessdlg: onbnclickedbuttonshell ()

{

// Todo: add the control notification handler code here

Shellexecuteinfoshexecinfo = {0 };

Shexecinfo. cbsize = sizeof (shellexecuteinfo );

Shexecinfo. fmask = see_mask_nocloseprocess;

Shexecinfo. hwnd = NULL;

Shexecinfo. lpverb = NULL;

Shexecinfo. lpfile = _ T ("C: \ ProgramFiles \ Internet Explorer \ ipolice.exe ");

Shexecinfo. lpparameters = _ T ("www.google.com.hk ");

Shexecinfo. lpdirectory = NULL;

Shexecinfo. nshow = sw_show;

Shexecinfo. hinstapp = NULL;

Shellexecuteex (& shexecinfo );

}

 

Beginners may think that the createprocee function will be a little complicated. It is actually a path, a startup parameter, and two struct structures.

Void cprocessdlg: onbnclickedbuttoncreate ()

{

// Todo: add the control notification handler code here

Startupinfosi;

Zeromemory (& Si, sizeof (SI ));

Si. cb = sizeof (SI );

Process_informationpi;

Zeromemory (& Pi, sizeof (PI ));

Lpctstrlppath = _ T ("C: \ ProgramFiles \ Internet Explorer \ ipolice.exe ");

Lptstrlpcmdline = _ T ("http://www.google.com.hk"); // Add a space before the URL

CreateProcess (lppath, lpcmdline, null, null, false, 0, null, null, & Si, & PI );

}

 

The winexec function should only support multiple bytes, so there will be problems in Unicode.

Void cprocessdlg: onbnclickedbuttonwinexec ()

{

// Todo: add the control notification handler code here

Tcharszpath [max_path] = _ T ("C: \ Program Files \ internetexplorer \ ipolice.exe ");

Tcharszcmdline [] = _ T ("http://www.google.com.hk ");

_ Tcscat_s (szpath, max_path, szcmdline );

Winexec (szpath, sw_normal );

}

 

Better reading performance: http://blog.csdn.net/MagicFuzzX/archive/2011/06/09/6533045.aspx

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.