Cannot convert parameter 2 from ' const CHAR[15] ' to ' LPWSTR ';

Source: Internet
Author: User

Used to monitor another process and automatically reboot the process when it is turned off.

Can be implemented using scripting, such as VBS or BAT. The following program uses C + + implementation: To monitor the target program HTServer.exe and run the target program if the target program is not running.

The code is as follows:

[CPP]  View plain copy print?  htservermonitor.cpp : defines the entry point for the console  application.  //      #include  <iostream>   #include  <windows.h>   #include  <stdio.h>   #include  <tchar.h>       using namespace std;   Int _tmain (Int argc, _tchar  *argv[])    {       STARTUPINFO si;          process_information pi; //process information:           zeromemory (&si, sizeof (SI));       si.cb = sizeof (SI);        zeromemory (&pi, sizeof (PI));        do{           //  Create a subprocess to determine whether to execute success    &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF (! CreateProcess ( null, "cmd /c c:\\users\\hk\\desktop\\htversions\\htserver\\ Htservereditversion4.2\\debug\\htserver.exe ", Null,null,false,0,null,null,&si,&pi)             {                cout <<  "Create process failed ..."  << getlasterror ()  << endl;                system ("pause");  //for testing                 return 0;            }           //Process Execution successful, printing process information             cout <<  "The following are child process information:"  << endl;           cout <<  "Process id pi.dwprocessid: "  << pi.dwProcessId  << endl;           cout <<  Thread ID  pi.dwThreadID :  " << pi.dwThreadId << endl;            //  waiting to know the subprocess exits ...            waitforsingleobject ( pi.hprocess, infinite)//detection process stop        The      //waitforsingleobject () function checks the state of the object and waits until timeout if it is indeterminate             //child process Exit            cout  <<  "Subprocess has exited ..."  << endl;            //shutdown process and handle            closehandle (pi.hprocess);    &NBSP;&NBSP;&NBSP;&NBsp;    closehandle (pi.hthread);            //system ("pause")//Wait        }while (true) after completion;//If the process is rolled out, execute the method again        exit (0);       return 0;  }     above code from: http://flylynne.iteye.com/blog/580751

There is no problem with compiling in VC6, but when you use VS08, you will get an error:

Error C2664: ' CREATEPROCESSW ': cannot convert parameter 2 from ' const char[15 ' to ' lpwstr ';

Workaround: Open the property-> the general-> character set to "not set".

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.