{"id":2295,"date":"2022-04-26T19:56:48","date_gmt":"2022-04-26T11:56:48","guid":{"rendered":"https:\/\/www.citerp.com.tw\/citwordpress\/?p=2295"},"modified":"2022-04-26T20:22:21","modified_gmt":"2022-04-26T12:22:21","slug":"delphi-createprocess","status":"publish","type":"post","link":"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/","title":{"rendered":"Delphi-CreateProcess"},"content":{"rendered":"\n<p>\u4ee5\u4e0b\u51fd\u5f0f\u5c01\u88dd\u4e86\u4f7f\u7528 CreateProcess Windows API \u555f\u52d5\u5176\u4ed6\u7a0b\u5f0f\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n\n\n\n<p>\u5b83\u662f\u53ef\u914d\u7f6e\u7684\uff0c\u53ef\u4ee5\u7b49\u5230\u547c\u53eb\u7a0b\u5e8f\u5b8c\u6210\u6216\u7acb\u5373\u8fd4\u56de\u3002<\/p>\n\n\n\n<p>\u5f15\u6578\uff1a<\/p>\n\n\n\n<p>FileName &#8211; \u53ef\u57f7\u884c\u6a94\u6848\u7684\u5b8c\u6574\u8def\u5f91<br>Params &#8211; \u547d\u4ee4\u5217\u5f15\u6578\u6216\u4f7f\u7528\u7a7a\u5b57\u4e32<br>Folder &#8211; \u88ab\u547c\u53eb\u7a0b\u5f0f\u7684\u5de5\u4f5c\u8cc7\u6599\u593e &#8211; \u5982\u679c\u5f9e FileName \u4e2d\u63d0\u53d6\u7a7a\u8def\u5f91<br>WaitUntilTerminated &#8211; \u5982\u679c true \u51fd\u5f0f\u5c07\u7b49\u5f85\u7a0b\u5e8f\u5b8c\u6210\u57f7\u884c<br>WaitUntilIdle &#8211; \u5982\u679c true \u51fd\u5f0f\u5c07\u547c\u53eb WaitForInputIdle \u51fd\u5f0f\u4e26\u7b49\u5f85\u6307\u5b9a\u7684\u7a0b\u5e8f\u5b8c\u6210\u8655\u7406\u5176\u521d\u59cb\u8f38\u5165\uff0c\u76f4\u5230\u6c92\u6709\u4f7f\u7528\u8005\u8f38\u5165\u639b\u8d77<br>RunMinimized &#8211; \u5982\u679c\u771f\u6b63\u7684\u904e\u7a0b\u5c07\u6700\u5c0f\u5316\u57f7\u884c<br>ErrorCode &#8211; \u5982\u679c\u51fd\u5f0f\u5931\u6557\uff0c\u5247\u6703\u5305\u542b\u9047\u5230\u7684 Windows \u932f\u8aa4\u7a0b\u5f0f\u78bc<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ExecuteProcess(const FileName, Params: string; Folder: string; WaitUntilTerminated, WaitUntilIdle, RunMinimized: boolean;\r\n  var ErrorCode: integer): boolean;\r\nvar\r\n  CmdLine: string;\r\n  WorkingDirP: PChar;\r\n  StartupInfo: TStartupInfo;\r\n  ProcessInfo: TProcessInformation;\r\nbegin\r\n  Result := true;\r\n  CmdLine := '\"' + FileName + '\" ' + Params;\r\n  if Folder = '' then Folder := ExcludeTrailingPathDelimiter(ExtractFilePath(FileName));\r\n  ZeroMemory(@StartupInfo, SizeOf(StartupInfo));\r\n  StartupInfo.cb := SizeOf(StartupInfo);\r\n  if RunMinimized then\r\n    begin\r\n      StartupInfo.dwFlags := STARTF_USESHOWWINDOW;\r\n      StartupInfo.wShowWindow := SW_SHOWMINIMIZED;\r\n    end;\r\n  if Folder &lt;> '' then WorkingDirP := PChar(Folder)\r\n  else WorkingDirP := nil;\r\n  if not CreateProcess(nil, PChar(CmdLine), nil, nil, false, 0, nil, WorkingDirP, StartupInfo, ProcessInfo) then\r\n    begin\r\n      Result := false;\r\n      ErrorCode := GetLastError;\r\n      exit;\r\n    end;\r\n  with ProcessInfo do\r\n    begin\r\n      CloseHandle(hThread);\r\n      if WaitUntilIdle then WaitForInputIdle(hProcess, INFINITE);\r\n      if WaitUntilTerminated then\r\n        repeat\r\n          Application.ProcessMessages;\r\n        until MsgWaitForMultipleObjects(1, hProcess, false, INFINITE, QS_ALLINPUT) &lt;> WAIT_OBJECT_0 + 1;\r\n      CloseHandle(hProcess);\r\n    end;\r\nend;<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528\u4e0a\u8ff0\u529f\u80fd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var\r\n  FileName, Parameters, WorkingFolder: string;\r\n  Error: integer;\r\n  OK: boolean;\r\nbegin\r\n  FileName := 'C:\\FullPath\\myapp.exe';\r\n  WorkingFolder := ''; \/\/ if empty function will extract path from FileName\r\n  Parameters := '-p'; \/\/ can be empty \r\n  OK := ExecuteProcess(FileName, Parameters, WorkingFolder, false, false, false, Error);\r\n  if not OK then ShowMessage('Error: ' + IntToStr(Error));\r\nend;<\/code><\/pre>\n\n\n\n<p><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms682425%28v=vs.85%29.aspx\">CreateProcess \u6587\u4ef6<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Delphi-CreateProcess<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"qubely_global_settings":"","qubely_interactions":"","footnotes":""},"categories":[89],"tags":[91],"class_list":["post-2295","post","type-post","status-publish","format-standard","hentry","category-delphi","tag-delphi"],"qubely_featured_image_url":null,"qubely_author":{"display_name":"\u5eb7\u6377Qoo","author_link":"https:\/\/www.citerp.com.tw\/citwordpress\/author\/cit001\/"},"qubely_comment":0,"qubely_category":"<a href=\"https:\/\/www.citerp.com.tw\/citwordpress\/category\/delphi\/\" rel=\"category tag\">Delphi<\/a>","qubely_excerpt":"Delphi-CreateProcess","yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Delphi-CreateProcess - \u514d\u8cbb\u8cc7\u6e90\u5206\u4eab<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/\" \/>\n<meta property=\"og:locale\" content=\"zh_TW\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Delphi-CreateProcess - \u514d\u8cbb\u8cc7\u6e90\u5206\u4eab\" \/>\n<meta property=\"og:description\" content=\"Delphi-CreateProcess\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/\" \/>\n<meta property=\"og:site_name\" content=\"\u514d\u8cbb\u8cc7\u6e90\u5206\u4eab\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/citerptw\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-26T11:56:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-26T12:22:21+00:00\" \/>\n<meta name=\"author\" content=\"\u5eb7\u6377Qoo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005:\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u5eb7\u6377Qoo\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9810\u4f30\u95b1\u8b80\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\u9418\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/\"},\"author\":{\"name\":\"\u5eb7\u6377Qoo\",\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/#\/schema\/person\/28cfdf2cec7315f2efe90573114fed37\"},\"headline\":\"Delphi-CreateProcess\",\"datePublished\":\"2022-04-26T11:56:48+00:00\",\"dateModified\":\"2022-04-26T12:22:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/\"},\"wordCount\":25,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/#organization\"},\"keywords\":[\"delphi\"],\"articleSection\":[\"Delphi\"],\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/\",\"url\":\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/\",\"name\":\"Delphi-CreateProcess - \u514d\u8cbb\u8cc7\u6e90\u5206\u4eab\",\"isPartOf\":{\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/#website\"},\"datePublished\":\"2022-04-26T11:56:48+00:00\",\"dateModified\":\"2022-04-26T12:22:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/#breadcrumb\"},\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9801\",\"item\":\"https:\/\/www.citerp.com.tw\/citwordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Delphi-CreateProcess\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/#website\",\"url\":\"https:\/\/www.citerp.com.tw\/citwordpress\/\",\"name\":\"\u514d\u8cbb\u8cc7\u6e90\u5206\u4eab\",\"description\":\"\u514d\u8cbb\u8cc7\u6e90\u5171\u4eab\",\"publisher\":{\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.citerp.com.tw\/citwordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-TW\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/#organization\",\"name\":\"\u514d\u8cbb\u8cc7\u6e90\u5206\u4eab\",\"url\":\"https:\/\/www.citerp.com.tw\/citwordpress\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.citerp.com.tw\/citwordpress\/wp-content\/uploads\/2022\/06\/find2.png\",\"contentUrl\":\"https:\/\/www.citerp.com.tw\/citwordpress\/wp-content\/uploads\/2022\/06\/find2.png\",\"width\":128,\"height\":128,\"caption\":\"\u514d\u8cbb\u8cc7\u6e90\u5206\u4eab\"},\"image\":{\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/citerptw\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/#\/schema\/person\/28cfdf2cec7315f2efe90573114fed37\",\"name\":\"\u5eb7\u6377Qoo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\/\/www.citerp.com.tw\/citwordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/87fa59ff417f35a6d53f05479d9dd918615095cadddb02e447511edc4f8b6302?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/87fa59ff417f35a6d53f05479d9dd918615095cadddb02e447511edc4f8b6302?s=96&d=mm&r=g\",\"caption\":\"\u5eb7\u6377Qoo\"},\"url\":\"https:\/\/www.citerp.com.tw\/citwordpress\/author\/cit001\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Delphi-CreateProcess - \u514d\u8cbb\u8cc7\u6e90\u5206\u4eab","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/","og_locale":"zh_TW","og_type":"article","og_title":"Delphi-CreateProcess - \u514d\u8cbb\u8cc7\u6e90\u5206\u4eab","og_description":"Delphi-CreateProcess","og_url":"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/","og_site_name":"\u514d\u8cbb\u8cc7\u6e90\u5206\u4eab","article_publisher":"https:\/\/www.facebook.com\/citerptw","article_published_time":"2022-04-26T11:56:48+00:00","article_modified_time":"2022-04-26T12:22:21+00:00","author":"\u5eb7\u6377Qoo","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005:":"\u5eb7\u6377Qoo","\u9810\u4f30\u95b1\u8b80\u6642\u9593":"1 \u5206\u9418"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/#article","isPartOf":{"@id":"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/"},"author":{"name":"\u5eb7\u6377Qoo","@id":"https:\/\/www.citerp.com.tw\/citwordpress\/#\/schema\/person\/28cfdf2cec7315f2efe90573114fed37"},"headline":"Delphi-CreateProcess","datePublished":"2022-04-26T11:56:48+00:00","dateModified":"2022-04-26T12:22:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/"},"wordCount":25,"commentCount":0,"publisher":{"@id":"https:\/\/www.citerp.com.tw\/citwordpress\/#organization"},"keywords":["delphi"],"articleSection":["Delphi"],"inLanguage":"zh-TW","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/","url":"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/","name":"Delphi-CreateProcess - \u514d\u8cbb\u8cc7\u6e90\u5206\u4eab","isPartOf":{"@id":"https:\/\/www.citerp.com.tw\/citwordpress\/#website"},"datePublished":"2022-04-26T11:56:48+00:00","dateModified":"2022-04-26T12:22:21+00:00","breadcrumb":{"@id":"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/#breadcrumb"},"inLanguage":"zh-TW","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.citerp.com.tw\/citwordpress\/delphi-createprocess\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9801","item":"https:\/\/www.citerp.com.tw\/citwordpress\/"},{"@type":"ListItem","position":2,"name":"Delphi-CreateProcess"}]},{"@type":"WebSite","@id":"https:\/\/www.citerp.com.tw\/citwordpress\/#website","url":"https:\/\/www.citerp.com.tw\/citwordpress\/","name":"\u514d\u8cbb\u8cc7\u6e90\u5206\u4eab","description":"\u514d\u8cbb\u8cc7\u6e90\u5171\u4eab","publisher":{"@id":"https:\/\/www.citerp.com.tw\/citwordpress\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.citerp.com.tw\/citwordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-TW"},{"@type":"Organization","@id":"https:\/\/www.citerp.com.tw\/citwordpress\/#organization","name":"\u514d\u8cbb\u8cc7\u6e90\u5206\u4eab","url":"https:\/\/www.citerp.com.tw\/citwordpress\/","logo":{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/www.citerp.com.tw\/citwordpress\/#\/schema\/logo\/image\/","url":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-content\/uploads\/2022\/06\/find2.png","contentUrl":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-content\/uploads\/2022\/06\/find2.png","width":128,"height":128,"caption":"\u514d\u8cbb\u8cc7\u6e90\u5206\u4eab"},"image":{"@id":"https:\/\/www.citerp.com.tw\/citwordpress\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/citerptw"]},{"@type":"Person","@id":"https:\/\/www.citerp.com.tw\/citwordpress\/#\/schema\/person\/28cfdf2cec7315f2efe90573114fed37","name":"\u5eb7\u6377Qoo","image":{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/www.citerp.com.tw\/citwordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/87fa59ff417f35a6d53f05479d9dd918615095cadddb02e447511edc4f8b6302?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/87fa59ff417f35a6d53f05479d9dd918615095cadddb02e447511edc4f8b6302?s=96&d=mm&r=g","caption":"\u5eb7\u6377Qoo"},"url":"https:\/\/www.citerp.com.tw\/citwordpress\/author\/cit001\/"}]}},"_links":{"self":[{"href":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-json\/wp\/v2\/posts\/2295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-json\/wp\/v2\/comments?post=2295"}],"version-history":[{"count":0,"href":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-json\/wp\/v2\/posts\/2295\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-json\/wp\/v2\/media?parent=2295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-json\/wp\/v2\/categories?post=2295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.citerp.com.tw\/citwordpress\/wp-json\/wp\/v2\/tags?post=2295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}