1、system()函数
例如:system("del c:\\jk.txt");
system()函数中可以直接运行dos命令,执行相应操作。
2、WinExec()函数
EX1: WinExec("Notepad.exe c:\\autoexec.bat",SW_SHOW); //執行 notepad.exe 打开目录下批处理文件,並正常显示
EX2: WinExec("Notepad.exe",SW_SHOWMINIMIZED); //執行 notepad.exe 但最小化
EX3: WinExec("Command.com /c dir c:\\",SW_SHOW); //執行 dir C:\ ,完成後關閉 MSDOS 視窗
EX4: WinExec("Command.com /k dir c:\\",SW_SHOW); //執行 dir C:\ ,完成後不關閉 MSDOS 視窗
EX5: if (WinExec(“notepad readme.txt”,SH_SHOW) <32)
MessagBox(NULL,”Can’t WinExec”,NULL,MB_OK);
UINT WinExec ( LPCSTR lpCmdLine , // address of command line
UINT uCmdShow // window style for new application
);
Header File : winbase.h
3、ShellExecute()函数
if (ShellExecute (NULL,”open”,”readme.txt”,NULL,NULL,SW_SHOW) <(HANDLE) 32)
MessagBox(NULL,”Can’t ShellExecute\n”,NULL,MB_OK);
ShellExecute(HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);
Head File : ShellApi.h