{"rsdb":{"rid":"372759","subhead":"","postdate":"0","aid":"261625","fid":"86","uid":"1","topic":"1","content":"
\n

Delphi \u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\u5e76\u963b\u585e\u5230\u5916\u90e8\u7a0b\u5e8f\u4e2d<\/strong><\/p> \n

\u80cc\u666f\u8bf4\u660e\uff1a<\/em><\/strong><\/span><\/span><\/p> \n

\u524d\u6bb5\u65f6\u95f4\u5f00\u53d1\u4e00\u4e2a\u6570\u636e\u8f6c\u6362\u7684\u7cfb\u7edf\uff0c\u4e1a\u52a1\u903b\u8f91\u4e2d\u8bf4\u660e\u6570\u636e\u9700\u8981\u538b\u7f29\u6210.tar.gz\u683c\u5f0f\u3002<\/p> \n

\u6211\u5728Windows\u7cfb\u7edf\u4e0b\u91c7\u7528\uff0c\u5148\u751f\u6210\u6279\u5904\u7406\u6587\u4ef6\uff0c\u7136\u540e\u8c03\u7528WinExec\u6267\u884c\u6279\u5904\u7406\u6587\u4ef6\uff0c\u4f11\u7720\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\uff0c\u5b8c\u6210\u6570\u636e\u7684\u81ea\u52a8\u538b\u7f29\u3002<\/p> \n

\u540e\u6765\u53d1\u73b0\uff0c\u5f85\u538b\u7f29\u6587\u4ef6\u7684\u5927\u5c0f\u4e0d\u786e\u5b9a\uff0c\u5355\u7eaf\u7684\u6267\u884cWinExec\u65f6Sleep\u56fa\u5b9a\u65f6\u95f4\uff0c\u53ef\u80fd\u5bfc\u81f4\u538b\u7f29\u5931\u8d25\u3001\u6587\u4ef6\u4e0d\u5168\u6216\u635f\u574f\u3002<\/p> \n

\u4f18\u5316\u65b9\u6848\uff1a<\/em><\/span><\/strong><\/span><\/p> \n

\u53d6\u4ee3WinExe\u7528CreateProcess\u7528\u6765\u542f\u52a8\u8fdb\u7a0b, \u6267\u884c\u6279\u5904\u7406\u6587\u4ef6, \u540c\u65f6\u7cfb\u7edf\u4f1a\u81ea\u52a8\u586b\u5199TProcessInformation\u8fd9\u4e2a\u7ed3\u6784\u3002<\/p> \n

\u6b64\u65f6\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u963b\u585e\u5230\u8be5\u6279\u5904\u7406\u4e2d\uff0c\u7b49\u5f85\u6279\u5904\u7406\u53e5\u67c4\u7684\u8fdb\u7a0b\u7ed3\u675f\u6216\u8d85\u65f6\u3002\u8fd9\u6837\u5c31\u80fd\u89e3\u51b3\u538b\u7f29\u635f\u574f\u95ee\u9898\u3002<\/p> \n

 <\/p> \n

\u7ed9\u4e2a\u5b9e\u4f8bDemo:<\/p> \n

D7\u4ee3\u7801\u5982\u4e0b\uff1a<\/p> \n

\n
 1<\/span> unit<\/span> uMain;\r\n<\/span> 2<\/span> \r\n 3<\/span> interface<\/span>\r\n 4<\/span> \r\n 5<\/span> uses<\/span>\r\n 6<\/span>   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,\r\n<\/span> 7<\/span>   Dialogs, RzButton, StdCtrls;\r\n<\/span> 8<\/span> \r\n 9<\/span> type<\/span>\r\n10<\/span>   TFrmMain = class<\/span>(TForm)\r\n<\/span>11<\/span>     mmMsg: TMemo;\r\n<\/span>12<\/span>     btnExecute: TRzBitBtn;\r\n<\/span>13<\/span>     btnClear: TRzBitBtn;\r\n<\/span>14<\/span>     procedure<\/span> MsgDsp(v_Str: string<\/span>);\r\n<\/span>15<\/span>     procedure<\/span> btnExecuteClick(Sender: TObject);\r\n<\/span>16<\/span>     procedure<\/span> btnClearClick(Sender: TObject);\r\n<\/span>17<\/span>   private<\/span>\r\n18<\/span>     {<\/span> Private declarations <\/span>}<\/span>\r\n19<\/span>   public<\/span>\r\n20<\/span>     {<\/span> Public declarations <\/span>}<\/span>\r\n21<\/span>   end<\/span>;\r\n<\/span>22<\/span> \r\n23<\/span> var<\/span>\r\n24<\/span>   FrmMain: TFrmMain;\r\n<\/span>25<\/span> \r\n26<\/span> implementation<\/span>\r\n27<\/span> \r\n28<\/span> {<\/span>$R *.dfm<\/span>}<\/span>\r\n29<\/span> \r\n30<\/span> procedure<\/span> TFrmMain.MsgDsp(v_Str: string<\/span>);\r\n<\/span>31<\/span> begin<\/span>\r\n32<\/span>   mmMsg.Lines.Add('<\/span>[ admin ] - [<\/span>'<\/span> + v_Str + '<\/span>] - [<\/span>'<\/span> + FormatDateTime('<\/span>YYYY-MM-DD hh:mm:ss zzz<\/span>'<\/span>, Now()) + '<\/span>]<\/span>'<\/span>);\r\n<\/span>33<\/span> end<\/span>;\r\n<\/span>34<\/span> \r\n35<\/span> procedure<\/span> TFrmMain.btnExecuteClick(Sender: TObject);\r\n<\/span>36<\/span> var<\/span>\r\n37<\/span>   sInfo: TStartupInfo;\r\n<\/span>38<\/span>   pInfo: TProcessInformation;\r\n<\/span>39<\/span>   cmdLine: string<\/span>;\r\n<\/span>40<\/span>   exitCode: Cardinal;\r\n<\/span>41<\/span> begin<\/span>\r\n42<\/span>   MsgDsp('<\/span>\u521d\u59cb\u5316\u53c2\u6570<\/span>'<\/span>);\r\n<\/span>43<\/span>   cmdLine := '<\/span>C:\\Program Files\\7-Zip\\7zFM.exe<\/span>'<\/span>;\r\n<\/span>44<\/span>   FillChar(sInfo, sizeof(sInfo), #0<\/span>);\r\n<\/span>45<\/span>   sInfo.cb := SizeOf(sInfo);\r\n<\/span>46<\/span>   sInfo.dwFlags := STARTF_USESHOWWINDOW;\r\n<\/span>47<\/span>   sInfo.wShowWindow := SW_NORMAL;\r\n<\/span>48<\/span>   MsgDsp('<\/span>\u53c2\u6570\u521d\u59cb\u5316\u5b8c\u6210\uff0c\u542f\u52a8WinExec\u8c03\u8bd5<\/span>'<\/span>);\r\n<\/span>49<\/span>   \/\/<\/span>CreateProcess\u7528\u6765\u542f\u52a8\u8fdb\u7a0b, \u8fdb\u7a0b\u542f\u52a8\u540e, \u4f1a\u586b\u5199TProcessInformation\u8fd9\u4e2a\u7ed3\u6784\uff0c<\/span>\r\n50<\/span>   \/\/<\/span>\u6b64\u65f6\u7a0b\u5e8f\u963b\u585e\u5230\u8be5\u53e5\u67c4\u4e2d\uff0c\u7b49\u5f85\u53e5\u67c4\u7684\u8fdb\u7a0b\u7ed3\u675f\u6216\u8d85\u65f6<\/span>\r\n51<\/span>   if<\/span> not<\/span> CreateProcess(nil<\/span>, pchar(cmdLine), nil<\/span>, nil<\/span>, false, CREATE_NEW_CONSOLE or<\/span> NORMAL_PRIORITY_CLASS, nil<\/span>, nil<\/span>, sInfo, pInfo) then<\/span>\r\n52<\/span>   begin<\/span>\r\n53<\/span>     MsgDsp('<\/span>WinExec\u8c03\u8bd5\u5931\u8d25\uff01<\/span>'<\/span>);\r\n<\/span>54<\/span>     MessageBox(Application.handle, '<\/span>\u6307\u5b9a\u7a0b\u5e8f\u542f\u52a8\u5931\u8d25!<\/span>'<\/span>, '<\/span>\u9519\u8bef<\/span>'<\/span>, MB_OK or<\/span> MB_ICONSTOP);\r\n<\/span>55<\/span>   end<\/span>\r\n56<\/span>   else<\/span>\r\n57<\/span>   begin<\/span>\r\n58<\/span>     \/\/<\/span>\u7b49\u5f85\u6307\u5b9a\u53e5\u67c4\u7684\u8fdb\u7a0b\u7ed3\u675f\u6216\u8d85\u65f6<\/span>\r\n59<\/span>     WaitForSingleObject(pInfo.hProcess, INFINITE);\r\n<\/span>60<\/span>     GetExitCodeProcess(pInfo.hProcess, exitCode);\r\n<\/span>61<\/span>     MsgDsp('<\/span>WinExec\u8c03\u8bd5\u6210\u529f\uff01<\/span>'<\/span>);\r\n<\/span>62<\/span>   end<\/span>;\r\n<\/span>63<\/span> end<\/span>;\r\n<\/span>64<\/span> \r\n65<\/span> procedure<\/span> TFrmMain.btnClearClick(Sender: TObject);\r\n<\/span>66<\/span> begin<\/span>\r\n67<\/span>    mmMsg.Clear;\r\n<\/span>68<\/span> end<\/span>;\r\n<\/span>69<\/span> \r\n70<\/span> end<\/span>.<\/pre> \n <\/div> \n 

\u8fd0\u884c\u6548\u679c\u5982\u4e0b\uff1a<\/p> \n

\"\"<\/p> \n

 <\/p> \n

\u5c01\u88c5\u6210\u51fd\u6570\u5982\u4e0b<\/strong>\uff1a<\/p> \n

\n
 1<\/span> \/\/<\/span>Jeremy.Wu<\/span>\r\n 2<\/span> \/\/<\/span>2019.09.19<\/span>\r\n 3<\/span> \/\/<\/span>https:\/\/www.cnblogs.com\/jeremywucnblog\/<\/span>\r\n 4<\/span> function<\/span> TFrmMain.GetCreateProcess(vCmdLine: string<\/span>): Boolean;\r\n<\/span> 5<\/span> var<\/span>\r\n 6<\/span>   sInfo: TStartupInfo;\r\n<\/span> 7<\/span>   pInfo: TProcessInformation;\r\n<\/span> 8<\/span>   exitCode: Cardinal;\r\n<\/span> 9<\/span> begin<\/span>\r\n10<\/span>   Result := False;\r\n<\/span>11<\/span>   FillChar(sInfo, sizeof(sInfo), #0<\/span>);\r\n<\/span>12<\/span>   sInfo.cb := SizeOf(sInfo);\r\n<\/span>13<\/span>   sInfo.dwFlags := STARTF_USESHOWWINDOW;\r\n<\/span>14<\/span>   sInfo.wShowWindow := SW_NORMAL;\r\n<\/span>15<\/span>   \/\/<\/span>CreateProcess\u7528\u6765\u542f\u52a8\u8fdb\u7a0b, \u8fdb\u7a0b\u542f\u52a8\u540e, \u4f1a\u586b\u5199TProcessInformation\u8fd9\u4e2a\u7ed3\u6784\uff0c<\/span>\r\n16<\/span>   \/\/<\/span>\u6b64\u65f6\u7a0b\u5e8f\u963b\u585e\u5230\u8be5\u53e5\u67c4\u4e2d\uff0c\u7b49\u5f85\u53e5\u67c4\u7684\u8fdb\u7a0b\u7ed3\u675f\u6216\u8d85\u65f6<\/span>\r\n17<\/span>   if<\/span> not<\/span> CreateProcess(nil<\/span>, pchar(vCmdLine), nil<\/span>, nil<\/span>, false, CREATE_NEW_CONSOLE or<\/span> NORMAL_PRIORITY_CLASS, nil<\/span>, nil<\/span>, sInfo, pInfo) then<\/span>\r\n18<\/span>   begin<\/span>\r\n19<\/span>     Result := False;\r\n<\/span>20<\/span>   end<\/span>\r\n21<\/span>   else<\/span>\r\n22<\/span>   begin<\/span>\r\n23<\/span>     \/\/<\/span>\u7b49\u5f85\u6307\u5b9a\u53e5\u67c4\u7684\u8fdb\u7a0b\u7ed3\u675f\u6216\u8d85\u65f6<\/span>\r\n24<\/span>     WaitForSingleObject(pInfo.hProcess, INFINITE);\r\n<\/span>25<\/span>     GetExitCodeProcess(pInfo.hProcess, exitCode);\r\n<\/span>26<\/span>     Result := True;\r\n<\/span>27<\/span>   end<\/span>;\r\n<\/span>28<\/span> end<\/span>;<\/pre> \n <\/div> \n 

 <\/p> \n<\/div>","orderid":"0","title":"Delphi - \u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\u5e76\u963b\u585e\u5230\u5916\u90e8\u7a0b\u5e8f\u4e2d","smalltitle":"","mid":"0","fname":"Delphi","special_id":"0","bak_id":"0","info":"0","hits":"333","pages":"1","comments":"0","posttime":"2019-09-19 18:10:16","list":"1568887816","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"Delphi<\/A> \u8c03\u7528<\/A> \u5916\u90e8<\/A> \u7a0b\u5e8f<\/A> \u963b\u585e<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.32","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"Delphi - \u8c03\u7528\u5916\u90e8\u7a0b\u5e8f\u5e76\u963b\u585e\u5230\u5916\u90e8\u7a0b\u5e8f\u4e2d","lastview":"1713309979","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}