首先說下shellexecuteex是如何提公升許可權的,shellexecuteex函式只有乙個引數,就是shellexecuteinfo結構體,不過是指標型別的,這無所謂,關鍵是這個結構體中有乙個引數lpverb,它的作用就是指定如何操作檔案lpfile,提公升許可權就是設定lpverb為「runas」。
將lpverb設定為」open」或null的時候,建立的子程序繼承了主程序的許可權,當主程序使用管理員身份執行時,經lpverb設定為」open」或null時,就會發現建立的子程序依舊是管理員身份。
最終測試的結果是
(1).當主程序以管理員身份執行時,建立的子程序都是管理員身份;
(2).當主程序以普通使用者身份執行時,若將lpverb引數設定為「runas」,則建立的子程序是管理員身份;若將lpverb設定為「open」或null時,則建立的子程序時普通使用者身份。
函式原型
bool shellexecuteex(
_inout_ shellexecuteinfo *pexecinfo
);結構:
typedef struct _shellexecuteinfo dummyunionname;
handle hprocess; //返回子程序控制代碼
} shellexecuteinfo, *lpshellexecuteinfo;
測試:shellexecuteinfo shexecinfo = ;
shexecinfo.cbsize = sizeof(shellexecuteinfo);
shexecinfo.fmask = see_mask_nocloseprocess;
shexecinfo.hwnd = null;
shexecinfo.lpverb = l"runas";
shexecinfo.lpfile = l"cmd";
shexecinfo.lpparameters = l"";
shexecinfo.lpdirectory = null;
shexecinfo.nshow = sw_show;
shellexecuteex(&shexecinfo);
waitforsingleobject(shexecinfo.hprocess,infinite);
執行結果可以明顯看到,啟動的cmd命令列視窗,的許可權是不同的。
ShellExecuteEx 函式說明
簡介 可以使用 shellexecuteex 開啟檔案或執行程式。語法格式 bool shellexecuteex inout shellexecuteinfo pexecinfo 引數 輸入輸出引數都是 shellexecuteinfo 結構體,其結構定義如下 1 typedef struct s...
ShellExecuteEx呼叫第三方程式
呼叫第三方程式有很多方法,包括system winexec createprocess,shellexecute,shellexecuteex。對比這幾個啟動程序的函式,總結下來功能完善而且好用的就是 shellexecuteex函式了。這個函式不僅可以傳入引數到第三方而且能夠傳回程序控制代碼用於操...
2019 paypal提現 怎麼提?
上週paypal裡的美元 轉到個人銀行卡上竟然被退回了 外匯管制越來越嚴格 不能公轉私了麼 還有哪個銀行可以?可以嘗試用第三方收款的方式解決,還不用擔心每年5萬美金結匯的限制。方案一 paypal提現到payoneer 派安盈 提現到國內銀行卡 送 25 1.2 提現費 提現教程 paypal通過派...