{"id":26769,"date":"2024-03-16T07:17:58","date_gmt":"2024-03-16T07:17:58","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/"},"modified":"2024-03-22T09:23:28","modified_gmt":"2024-03-22T09:23:28","slug":"usage-and-common-examples-of-shellexecuteex","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/","title":{"rendered":"Usage and common examples of ShellExecuteEx"},"content":{"rendered":"<p>The ShellExecuteEx function is a function in the Windows API that can open an external program or file, and allows for specifying parameters to control how it is opened. Below are the usage and common examples of the ShellExecuteEx function.<\/p>\n<p>How to use:<\/p>\n<ol>\n<li>You first need to include the windows.h header file.<\/li>\n<li>Declare a variable of type SHELLEXECUTEINFO structure, and initialize the cbSize member to the size of the structure.<\/li>\n<li>Set the other members of the SHELLEXECUTEINFO structure, including lpVerb, lpFile, lpParameters, lpDirectory, and nShow.<\/li>\n<li>Call the ShellExecuteEx function and pass the address of the SHELLEXECUTEINFO structure as a parameter to the function.<\/li>\n<li>Check the return value of the ShellExecuteEx function; if it is TRUE, then the execution was successful, but if it is FALSE, then the execution failed.<\/li>\n<\/ol>\n<p>Common examples:<\/p>\n<ol>\n<li>Open an external program:<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-meta\">#<span class=\"hljs-keyword\">include<\/span> <span class=\"hljs-string\">&lt;windows.h&gt;<\/span><\/span>\r\n\r\n<span class=\"hljs-function\"><span class=\"hljs-type\">int<\/span> <span class=\"hljs-title\">main<\/span><span class=\"hljs-params\">()<\/span>\r\n<\/span>{\r\n    SHELLEXECUTEINFO sei = { <span class=\"hljs-built_in\">sizeof<\/span>(SHELLEXECUTEINFO) };\r\n    sei.lpFile = <span class=\"hljs-string\">L\"notepad.exe\"<\/span>;\r\n    sei.nShow = SW_SHOW;\r\n    \r\n    <span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-built_in\">ShellExecuteEx<\/span>(&amp;sei))\r\n    {\r\n        <span class=\"hljs-comment\">\/\/ \u6267\u884c\u6210\u529f<\/span>\r\n    }\r\n    <span class=\"hljs-keyword\">else<\/span>\r\n    {\r\n        <span class=\"hljs-comment\">\/\/ \u6267\u884c\u5931\u8d25<\/span>\r\n    }\r\n    \r\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-number\">0<\/span>;\r\n}\r\n<\/code><\/pre>\n<p>The above code will open the Notepad program.<\/p>\n<ol>\n<li>Open a file:<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-meta\">#<span class=\"hljs-keyword\">include<\/span> <span class=\"hljs-string\">&lt;windows.h&gt;<\/span><\/span>\r\n\r\n<span class=\"hljs-function\"><span class=\"hljs-type\">int<\/span> <span class=\"hljs-title\">main<\/span><span class=\"hljs-params\">()<\/span>\r\n<\/span>{\r\n    SHELLEXECUTEINFO sei = { <span class=\"hljs-built_in\">sizeof<\/span>(SHELLEXECUTEINFO) };\r\n    sei.lpFile = <span class=\"hljs-string\">L\"C:\\\\path\\\\to\\\\file.txt\"<\/span>;\r\n    sei.nShow = SW_SHOW;\r\n    \r\n    <span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-built_in\">ShellExecuteEx<\/span>(&amp;sei))\r\n    {\r\n        <span class=\"hljs-comment\">\/\/ \u6267\u884c\u6210\u529f<\/span>\r\n    }\r\n    <span class=\"hljs-keyword\">else<\/span>\r\n    {\r\n        <span class=\"hljs-comment\">\/\/ \u6267\u884c\u5931\u8d25<\/span>\r\n    }\r\n    \r\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-number\">0<\/span>;\r\n}\r\n<\/code><\/pre>\n<p>The above code will open the file located at the path C:\\path\\to\\file.txt.<\/p>\n<p>Please note that when using the ShellExecuteEx function to open a file, the lpFile parameter should be passed the full path of the file.<\/p>\n<ol>\n<li>Open a URL link:<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-meta\">#<span class=\"hljs-keyword\">include<\/span> <span class=\"hljs-string\">&lt;windows.h&gt;<\/span><\/span>\r\n\r\n<span class=\"hljs-function\"><span class=\"hljs-type\">int<\/span> <span class=\"hljs-title\">main<\/span><span class=\"hljs-params\">()<\/span>\r\n<\/span>{\r\n    SHELLEXECUTEINFO sei = { <span class=\"hljs-built_in\">sizeof<\/span>(SHELLEXECUTEINFO) };\r\n    sei.lpFile = <span class=\"hljs-string\">L\"https:\/\/www.example.com\"<\/span>;\r\n    sei.nShow = SW_SHOW;\r\n    \r\n    <span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-built_in\">ShellExecuteEx<\/span>(&amp;sei))\r\n    {\r\n        <span class=\"hljs-comment\">\/\/ \u6267\u884c\u6210\u529f<\/span>\r\n    }\r\n    <span class=\"hljs-keyword\">else<\/span>\r\n    {\r\n        <span class=\"hljs-comment\">\/\/ \u6267\u884c\u5931\u8d25<\/span>\r\n    }\r\n    \r\n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-number\">0<\/span>;\r\n}\r\n<\/code><\/pre>\n<p>The above code will open a link to https:\/\/www.example.com.<\/p>\n<p>Note: When using the ShellExecuteEx function to open a URL link, the lpFile parameter needs to be passed the full URL link address.<\/p>\n<p>The above are the usage methods and common examples of the ShellExecuteEx function, I hope it helps you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The ShellExecuteEx function is a function in the Windows API that can open an external program or file, and allows for specifying parameters to control how it is opened. Below are the usage and common examples of the ShellExecuteEx function. How to use: You first need to include the windows.h header file. Declare a variable [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-26769","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Usage and common examples of ShellExecuteEx - Blog - Silicon Cloud<\/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.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Usage and common examples of ShellExecuteEx\" \/>\n<meta property=\"og:description\" content=\"The ShellExecuteEx function is a function in the Windows API that can open an external program or file, and allows for specifying parameters to control how it is opened. Below are the usage and common examples of the ShellExecuteEx function. How to use: You first need to include the windows.h header file. Declare a variable [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-16T07:17:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-22T09:23:28+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin Taylor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin Taylor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/\"},\"author\":{\"name\":\"Benjamin Taylor\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/ac801fe9549a25960ce48aa2e0a691c9\"},\"headline\":\"Usage and common examples of ShellExecuteEx\",\"datePublished\":\"2024-03-16T07:17:58+00:00\",\"dateModified\":\"2024-03-22T09:23:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/\"},\"wordCount\":250,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/\",\"name\":\"Usage and common examples of ShellExecuteEx - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-16T07:17:58+00:00\",\"dateModified\":\"2024-03-22T09:23:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Usage and common examples of ShellExecuteEx\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/ac801fe9549a25960ce48aa2e0a691c9\",\"name\":\"Benjamin Taylor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ec2e3d3e2d525fd148047c4520ae7c1cdccd1f4b48a1a488422b31f04f345c14?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ec2e3d3e2d525fd148047c4520ae7c1cdccd1f4b48a1a488422b31f04f345c14?s=96&d=mm&r=g\",\"caption\":\"Benjamin Taylor\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/benjamintaylor\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Usage and common examples of ShellExecuteEx - Blog - Silicon Cloud","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.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/","og_locale":"en_US","og_type":"article","og_title":"Usage and common examples of ShellExecuteEx","og_description":"The ShellExecuteEx function is a function in the Windows API that can open an external program or file, and allows for specifying parameters to control how it is opened. Below are the usage and common examples of the ShellExecuteEx function. How to use: You first need to include the windows.h header file. Declare a variable [&hellip;]","og_url":"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-16T07:17:58+00:00","article_modified_time":"2024-03-22T09:23:28+00:00","author":"Benjamin Taylor","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Benjamin Taylor","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/"},"author":{"name":"Benjamin Taylor","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/ac801fe9549a25960ce48aa2e0a691c9"},"headline":"Usage and common examples of ShellExecuteEx","datePublished":"2024-03-16T07:17:58+00:00","dateModified":"2024-03-22T09:23:28+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/"},"wordCount":250,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/","url":"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/","name":"Usage and common examples of ShellExecuteEx - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-16T07:17:58+00:00","dateModified":"2024-03-22T09:23:28+00:00","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/usage-and-common-examples-of-shellexecuteex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Usage and common examples of ShellExecuteEx"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/ac801fe9549a25960ce48aa2e0a691c9","name":"Benjamin Taylor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ec2e3d3e2d525fd148047c4520ae7c1cdccd1f4b48a1a488422b31f04f345c14?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ec2e3d3e2d525fd148047c4520ae7c1cdccd1f4b48a1a488422b31f04f345c14?s=96&d=mm&r=g","caption":"Benjamin Taylor"},"url":"https:\/\/www.silicloud.com\/blog\/author\/benjamintaylor\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/26769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=26769"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/26769\/revisions"}],"predecessor-version":[{"id":60954,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/26769\/revisions\/60954"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=26769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=26769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=26769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}