![](/img/trans.png)
[英]How can I run a mklink system command (cmd.exe) from a delphi 7 aplpication
[英]How can I run a cmd command in delphi?
我正在嘗試在 delphi 中運行 cmd 命令並嘗試過
ShellExecute(Handle, 'runas', 'cmd.exe', ' net start ExportFileMainService', nil, SW_SHOWNORMAL);
但它似乎沒有工作,我不知道為什么。
這是我在 Delphi 2010 中編寫的一些代碼,用於打開命令提示符:
function TForm7.RunCmdAndWait(hWnd: HWND; aParameters: string):
Cardinal;
var
sei: TShellExecuteInfo;
aFile, dir: string;
begin
Result := 0;
dir := ExtractFilePath(Application.ExeName);
SetCurrentDir(dir);
FillChar(sei, SizeOf(sei), 0);
sei.cbSize := SizeOf(sei);
sei.Wnd := hWnd;
sei.fMask := {SEE_MASK_FLAG_NO_UI or} SEE_MASK_NOCLOSEPROCESS;
sei.lpVerb := 'open';
aFile := 'cmd';
sei.lpFile := PChar(aFile);
sei.lpParameters := PChar(aParameters);
sei.lpDirectory := PChar(dir);
sei.nShow := SW_SHOWNORMAL;
if not ShellExecuteEx(@sei) then
begin
RaiseLastOSError;
end;
if sei.hProcess <> 0 then
begin
while WaitForSingleObject(sei.hProcess, 250) = WAIT_TIMEOUT do
Application.ProcessMessages;
GetExitCodeProcess(sei.hProcess, Result);
CloseHandle(sei.hProcess);
end else
TaskMessageDlg('Error running program!', 'No handle to process.',
mtError, [mbOK], 0);
end;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.