ProcessStartInfo.Arguments Property
Assembly: System (in system.dll)
/** @property */ public String get_Arguments () /** @property */ public void set_Arguments (String value)
public function get Arguments () : String public function set Arguments (value : String)
Property Value
File type-specific arguments that the system can associate with the application specified in the FileName property. The default is an empty string (""). The maximum string length is 2,003 characters in .NET Framework applications and 488 characters in .NET Compact Framework applications.using System; using System.Diagnostics; using System.ComponentModel; namespace MyProcessSample { /// <summary> /// Shell for the sample. /// </summary> class MyProcess { /// <summary> /// Opens the Internet Explorer application. /// </summary> void OpenApplication(string myFavoritesPath) { // Start Internet Explorer. Defaults to the home page. Process.Start("IExplore.exe"); // Display the contents of the favorites folder in the browser. Process.Start(myFavoritesPath); } /// <summary> /// Opens urls and .html documents using Internet Explorer. /// </summary> void OpenWithArguments() { // url's are not considered documents. They can only be opened // by passing them as arguments. Process.Start("IExplore.exe", "www.northwindtraders.com"); // Start a Web page using a browser associated with .html and .asp files. Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm"); Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp"); } /// <summary> /// Uses the ProcessStartInfo class to start new processes, both in a minimized /// mode. /// </summary> void OpenWithStartInfo() { ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); startInfo.WindowStyle = ProcessWindowStyle.Minimized; Process.Start(startInfo); startInfo.Arguments = "www.northwindtraders.com"; Process.Start(startInfo); } static void Main() { // Get the path that stores favorite links. string myFavoritesPath = Environment.GetFolderPath(Environment.SpecialFolder.Favorites); MyProcess myProcess = new MyProcess(); myProcess.OpenApplication(myFavoritesPath); myProcess.OpenWithArguments(); myProcess.OpenWithStartInfo(); } } }
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
If you are specifying an argument that is just a file name, the typical instinct is to say
psi.Arguments = filename;
What could be simpler? Depending on your style that may work all the time, half the time, or none of the time. Specifically, it will work for any file name that does not need to be quoted on a command-line, like these:
c:\temp\foobar.cs
..\abc\def\text_file.xyz
But it will fail for a file like this:
c:\documents and settings\yourdir\application data
for the same reason that would fail on the command line: tokens are separated by spaces. The filename, therefore, would be considered just c:\documents. In order to pass a filename safely, then, enclose it in quotes:
psi.Arguments = '"' + filename + '"';
Once you know this it is glaringly obvious, but this tip may save you some "head-scratching".
- 6/11/2007
- msorens