DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 242297 - Last Review: July 19, 2012 - Revision: 2.0

 
This article was previously published under Q242297

Summary

This article demonstrates how to create a shortcut with parameters to be passed as command line arguments using the Microsoft Windows Script Host (WSH).

More information

To ensure that the necessary parameters are set correctly when using WSH to create a shortcut, use the WshShortcut.Arguments property in conjunction with WshShortcut.TargetPath. For example, the following code sample demonstrates how to create a shortcut (aaa.lnk) to open a text file (aaa.txt) using Microsoft Notepad:
'Create a WshShell Object
Set WshShell = Wscript.CreateObject("Wscript.Shell")

'Create a WshShortcut Object
Set oShellLink = WshShell.CreateShortcut("aaa.lnk")

'Set the Target Path for the shortcut
oShellLink.TargetPath = "notepad.exe"

'Set the additional parameters for the shortcut
oShellLink.Arguments = "c:\windows\desktop\aaa.txt"

'Save the shortcut
oShellLink.Save

'Clean up the WshShortcut Object
Set oShellLink = Nothing
				
Note: When using this code sample, you might need to include the full path for the WshShortcut.TargetPath property.


The WshShortcut.Arguments property can also be used for parameters that include forward slashes as well. For example, the following code sample demonstrates how to use the /u argument for Regsvr32.exe to unregister the control Mycontrol.ocx.
'Set the parameters to unregister Mycontrol.ocx
oShellLink.Arguments = "/u c:\windows\system\Mycontrol.ocx"
				

References

For more information on the Windows Script Host, see the following Microsoft Web page:
Windows Script Technologies (http://technet.microsoft.com/library/ee176792.aspx)
Keywords: 
kbdswmanage2003swept kbhowto KB242297
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support