vc 執行exe檔案的方法

2021-05-22 09:25:42 字數 2969 閱讀 4868

winexec最簡單,兩個引數,前乙個指定路徑,後乙個指定顯示方式.後乙個引數  

值得說一下,比如泥用   sw_showmaxmized方式去加栽乙個無最大化按鈕的   程式,  

呵呵就是neterm,calc等等,就不會出現正常的窗體,但是已經被加到任務列表裡  

了。  

shellexecute較   winexex靈活一點,可以指定工作目錄,下面的   example就是直接  

開啟   c:/temp/1.txt,而不用加栽與   txt檔案關聯的應用程式,很多安裝程式完成  

後都會開啟乙個視窗,來顯示readme   or   faq,就是這麼作的啦.  

shellexecute(null,null,_t("1.txt"),null,_t("c://temp"),sw_showmaxmized);  

createprocess最複雜,一共有十個引數,不過大部分都可以用null代替,它可以  

指定程序的安全屬性,繼承資訊,類的優先順序等等.來看個很簡單的   example:  

startupinfo   stinfo;   //啟動視窗的資訊  

processinfo   procinfo;   //程序的資訊  

createprocess(null,_t("notepad.exe"),null,null.false,   normal_priority_  

class,null,null,   &stinfo,&procinfo);  

shellexecute應用詳細解釋

shellexecute(m_hwnd, "open", "calc.exe" ,"", "", sw_show );

或shellexecute(m_hwnd, "open" , "notepad.exe", "c://testlog.log","",sw_show );

系統自帶程式也可以不使用全路徑名。

開啟乙個同系統程式相關連的文件

shellexecute(m_hwnd,"open", "c://abc.txt","","",sw_show );

如何開啟乙個網頁

啟用相關程式,傳送email

shellexecute(m_hwnd,"open", "mailto:[email protected]","","", sw_show );

用系統印表機列印文件

shellexecute(m_hwnd,"print", "c://test.txt","","", sw_hide);

如何用系統查詢功能來查詢指定檔案

shellexecute(m_hwnd,"find","d://destfile", null,null,sw_show);

啟動乙個程式,直到它執行結束

方法一:

shellexecuteinfo shexecinfo = ;

shexecinfo.cbsize = sizeof(shellexecuteinfo);

shexecinfo.fmask = see_mask_nocloseprocess;

shexecinfo.hwnd = null;

shexecinfo.lpverb = null;

shexecinfo.lpfile = "c://myprogram.exe";

shexecinfo.lpparameters = "";

shexecinfo.lpdirectory = null;

shexecinfo.nshow = sw_show;

shellexecuteex(&shexecinfo);

waitforsingleobject(shexecinfo.hprocess,infinite);

方法二:

process_information processinfo;

startupinfo startupinfo; //this is an [in] parameter

zeromemory(&startupinfo, sizeof(startupinfo));

startupinfo.cb = sizeof startupinfo ; //only compulsory field

if(createprocess("c://winnt//notepad.exe", null, null,null,false,0,null, null,&startupinfo,&processinfo))

else

顯示檔案或資料夾的屬性

shellexecuteinfo shexecinfo =;

shexecinfo.cbsize = sizeof(shellexecuteinfo);

shexecinfo.fmask = see_mask_invokeidlist ;

shexecinfo.hwnd = null;

shexecinfo.lpverb = "properties";

shexecinfo.lpfile = "c://"; //can be a file as well

shexecinfo.lpparameters = "";

shexecinfo.lpdirectory = null;

shexecinfo.nshow = sw_show;

shellexecuteex(&shexecinfo);

要加命令引數就是:shexecinfo.lpparameters = "";或者

shellexecute(m_hwnd, "open", "calc.exe" ,"", "", sw_show );得第4個引數!!!

[email protected]

c python執行exe檔案的方法

vc中呼叫其他可執行程式,可以使用shellexecute函式,函式如下 hinstance shellexecute hwnd hwnd,lpctstr lpverb,lpctstr lpfile,lpctstr lpparameters,lpctstr lpdirectory,int nshow...

vc呼叫EXE檔案,並且等待其執行完畢

shellexecuteinfo shexecinfo shexecinfo.cbsize sizeof shellexecuteinfo shexecinfo.fmask see mask nocloseprocess shexecinfo.hwnd null shexecinfo.lpverb ...

VC中獲取當前exe檔案執行路徑

一 tchar szfilepath max path 1 getmodulefilename null,szfilepath,max path tcsrchr szfilepath,t 1 0 刪除檔名,只獲得路徑 cstring str url szfilepath afxmessagebox ...