2012年9月21日 星期五

[C++] Execute system call in command line.

Example for execute system call for Win32

#include "stdafx.h"
#include "stdlib.h"

int _tmain(int argc, _TCHAR* argv[])
{
    system( "cd c:\\windows\\system32");
    system( "notepad.exe C:\\1.txt");
    return 0;
}

Example for execute system call for WinCE

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    SHELLEXECUTEINFO ExecuteInfo;
    memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));
 
    ExecuteInfo.cbSize       = sizeof(ExecuteInfo);
    ExecuteInfo.fMask        = 0;              
    ExecuteInfo.hwnd         = 0;              
    ExecuteInfo.lpVerb       = _T("open"); // Operation to perform
    ExecuteInfo.lpFile         = _T("\\storage card\\myBrowser.exe"); // Application name
    ExecuteInfo.lpParameters = _T("--shell"); // Additional parameters
    ExecuteInfo.lpDirectory  = 0; // Default directory
    ExecuteInfo.nShow        = SW_SHOW;
    ExecuteInfo.hInstApp     = 0;
 
    ShellExecuteEx(&ExecuteInfo);

    return 0;
}

沒有留言:

張貼留言