{"id":64703,"date":"2007-06-07T23:33:00","date_gmt":"2007-06-07T23:33:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/06\/07\/how-can-i-create-a-shortcut-for-an-executable-file-that-uses-parameters\/"},"modified":"2007-06-07T23:33:00","modified_gmt":"2007-06-07T23:33:00","slug":"how-can-i-create-a-shortcut-for-an-executable-file-that-uses-parameters","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-create-a-shortcut-for-an-executable-file-that-uses-parameters\/","title":{"rendered":"How Can I Create a Shortcut For an Executable File That Uses Parameters?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! How can I create a shortcut where the target path is an executable file that uses parameters (for example, <B>something.exe -t \u2013s<\/B>)?<BR><BR>&#8212; MC <\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, MC. <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/may07\/hey0530.mspx\"><B>A week or so ago<\/B><\/A> we mentioned that we were going to make some changes to <I>Hey, Scripting Guy!<\/I>; in particular, we were going to stop wasting time and start getting straight to the point. Needless to say, we didn\u2019t exactly get around to that. Now we\u2019re considering making a <I>different<\/I> change. You might have noticed that the layout for each of our <I>Hey, Scripting Guy!<\/I> columns includes a big <B>Q<\/B> for question and a big <B>A<\/B> for answer. That makes sense: after all, this is a question-and-answer column, something commonly referred to as \u201cQ and A.\u201d Except that Q and A is the way old fogeys describe this column, and the Scripting Guys would never want to be thought of as old fogeys. Therefore, we\u2019re thinking about updating this column to A and A rather than Q and A, and replacing the big Q for question with a big A.<\/P>\n<P>What\u2019s the big A for? Well, for you old fogeys out there, the big A is for <I>ask<\/I>. You might be thinking, \u201cWait a second: ask is a verb, not a noun.\u201d Well, that just shows how out-of-touch you are. At Microsoft (the company that consistently tries to reinvent the English language) the latest rage is to use the word ask as a noun; in particular, to use the word ask instead of using the word <I>question<\/I>. Here are a couple of examples drawn from emails the Scripting Guy who writes this column received the other day:<\/P>\n<P>\u201cI have an ask for everyone on this list.\u201d<\/P>\n<P>\u201cNever mind; I discovered the answer to my own ask.\u201d<\/P>\n<P>OK, if you promise not to tell anyone, that sounds really weird to us, too. However, if that\u2019s what it takes to sound cool, well, then that\u2019s what it takes to sound cool. Therefore, MC, here\u2019s an answer to <I>your<\/I> ask:<\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Wscript.Shell&#8221;)\nstrDesktop = objShell.SpecialFolders(&#8220;Desktop&#8221;)<\/p>\n<p>Set objShortcut = objShell.CreateShortcut(strDesktop &amp; &#8220;\\Test.lnk&#8221;)\nobjShortcut.TargetPath = &#8220;Notepad.exe&#8221;\nobjShortcut.Arguments = &#8220;C:\\Scripts\\Test.txt&#8221;<\/p>\n<p>objShortcut.Description = &#8220;Starts Notepad with a file already loaded.&#8221;\nobjShortcut.WorkingDirectory = strDesktop<\/p>\n<p>objShortcut.Save\n<\/PRE>\n<P>So how <I>did<\/I> we answer this ask? (You know, that <I>still<\/I> sounds kind of dorky to us.) To begin with, we created an instance of the <B>Wscript.Shell<\/B> object:<\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Wscript.Shell&#8221;)\n<\/PRE>\n<P>We then grabbed the path to the Desktop folder, something we do using the Shell object\u2019s <B>SpecialFolders<\/B> property and the parameter <I>Desktop<\/I>:<\/P><PRE class=\"codeSample\">strDesktop = objShell.SpecialFolders(&#8220;Desktop&#8221;)\n<\/PRE>\n<TABLE class=\"dataTable\" id=\"EZE\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Note<\/B>. If you\u2019re wondering why we grabbed the path to the Desktop folder, well, that\u2019s easy: we have to put our shortcut <I>somewhere<\/I>, so we decided to put it on the Desktop.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>From there we call the <B>CreateShortcut<\/B> method, passing the path to the Desktop folder and the value <B>\\Test.link<\/B> as the method parameter:<\/P><PRE class=\"codeSample\">Set objShortcut = objShell.CreateShortcut(strDesktop &amp; &#8220;\\Test.lnk&#8221;)\n<\/PRE>\n<P>We probably don\u2019t need to tell you that <B>Test.lnk<\/B> is the file name for our new shortcut file. But apparently we went ahead and told you anyway, didn\u2019t we? Oh well.<\/P>\n<P>For our little sample script we\u2019re creating a shortcut that starts Notepad and then opens the file C:\\Scripts\\Test.txt. To that end, we assign <I>Notepad.exe<\/I> to the shortcut\u2019s <B>TargetPath<\/B> property:<\/P><PRE class=\"codeSample\">objShortcut.TargetPath = &#8220;Notepad.exe&#8221;\n<\/PRE>\n<P>What\u2019s that? Shouldn\u2019t we have assigned <I>Notepad.exe C:\\Scripts\\Test.txt<\/I> to the TargetPath property? Well, you\u2019d think so, wouldn\u2019t you? However, that typically doesn\u2019t work; in general, the target path needs to be a pointer to a specific file (or folder). In this case, that file is Notepad.exe; therefore, we need to set the TargetPath to Notepad.exe <I>without<\/I> including the parameter C:\\Scripts\\Test.txt.<\/P>\n<P>So then where the heck do we put our parameter? That\u2019s easy; we assign that value to the <B>Arguments<\/B> property:<\/P><PRE class=\"codeSample\">objShortcut.Arguments = &#8220;C:\\Scripts\\Test.txt&#8221;\n<\/PRE>\n<P><I>That\u2019s<\/I> where your command-line parameters go.<\/P>\n<P>After that we assign values to the <B>Description<\/B> and <B>WorkingDirectory<\/B> properties. (Which we don\u2019t have to do; these are optional properties.) We then call the <B>Save<\/B> method and officially create our new Desktop shortcut:<\/P><PRE class=\"codeSample\">objShortcut.Save\n<\/PRE>\n<P>And what do you think will happen when we double-click that shortcut? You already know what\u2019s going to happen: Notepad is going to start up and, when it does, it\u2019s going to load the file C:\\Scripts\\Test.txt. Which is just the sort of thing we wanted it to do.<\/P>\n<P>OK. Having taken care of today\u2019s ask we now have a <I>tell<\/I> for you. (Which is yet another example of Microsoft-speak. And, to be honest, we always thought that tell was a verb, too.) The Scripting Guys are still in <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/teched07\/default.mspx\"><B>Orlando<\/B><\/A>, but that doesn\u2019t mean cool things aren\u2019t happening in the Script Center. For example, you still have plenty of time to win a Scripting Guys Gift Pack as part of our <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/teched07\/challenge.mspx\"><B>TechEd Challenge<\/B><\/A>. We\u2019ve got several new articles aimed at people interested in learning <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/winpsh\/manual\/default.mspx\"><B>Windows PowerShell<\/B><\/A>, and today we\u2019re featuring part 2 of our two-part series on <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/imapi\/imapi2-2.mspx\"><B>burning CDs with Windows Vista<\/B><\/A>. If that doesn\u2019t qualify as a tell, well, we don\u2019t know what does.<\/P>\n<P>Although, come to think of it, we <I>don\u2019t<\/I> know what qualifies as a tell. Gee, maybe we <I>are<\/I> old fogeys after all.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I create a shortcut where the target path is an executable file that uses parameters (for example, something.exe -t \u2013s)?&#8212; MC Hey, MC. A week or so ago we mentioned that we were going to make some changes to Hey, Scripting Guy!; in particular, we were going to stop wasting [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[16,47,3,5],"class_list":["post-64703","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-general-management-tasks","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I create a shortcut where the target path is an executable file that uses parameters (for example, something.exe -t \u2013s)?&#8212; MC Hey, MC. A week or so ago we mentioned that we were going to make some changes to Hey, Scripting Guy!; in particular, we were going to stop wasting [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/64703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=64703"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/64703\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=64703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=64703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=64703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}