程式中執行其他可執行檔案

2021-06-17 17:41:42 字數 1264 閱讀 1518

例如:system("del c:\\jk.txt");

system()函式中可以直接執行dos命令,執行相應操作。

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

); header file : winbase.h

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

linux 執行可執行檔案

1 首先,需要了解一下a.out這個目標檔案。a.out在linux下是elf executable linkable format 檔案格式,該目標檔案由乙個檔案頭 段 資料段 已初始化 從定位資訊區 符號表及符號名字字串構成,如下左圖所示,經過鏈結後生成執行檔案如下右圖所示,需要說明的是1 bs...

API函式執行可執行檔案

shellexecute hwnd hwnd,父視窗控制代碼 lpcstr lpoperation,操作型別 lpcstr lpfile,要進行操作的檔案或路徑 lpcstr lpparameters,當lpoperation為 explore 時指定要傳遞的引數,通常設為null lpcstr l...

Linux下執行可執行檔案

我們通常會為計算機配置環境變數 path,echo path 檢視當前的環境變數包含的目錄。這些目錄下的可執行檔案就無需輸入完整路徑來執行,直接輸入命令就行,我們shell中常使用的一些linux命令,例如man,cat等的目錄都被包含在該path目錄中,所以直接在shell中輸入這些命令就可以。即...