本文整理匯總了C#中System.Diagnostics.Process.Start方法的典型用法代碼示例。如果您正苦於以下問題:C# Process.Start方法的具體用法?C# Process.Start怎麽用?C# Process.Start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.Start方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
// NOTE: This example requires a text.txt file file in your Documents folder
using System;
using System.Diagnostics;
using System.Security;
using System.ComponentModel;
class Example
{
static void Main()
{
Console.Write("Enter your domain: ");
string domain = Console.ReadLine();
Console.Write("Enter you user name: ");
string uname = Console.ReadLine();
Console.Write("Enter your password: ");
SecureString password = new SecureString();
ConsoleKeyInfo key;
do
{
key = Console.ReadKey(true);
// Ignore any key out of range.
if (((int)key.Key) >= 33 && ((int)key.Key <= 90) && key.Key != ConsoleKey.Enter)
{
// Append the character to the password.
password.AppendChar(key.KeyChar);
Console.Write("*");
}
// Exit if Enter key is pressed.
} while (key.Key != ConsoleKey.Enter);
Console.WriteLine();
try
{
Console.WriteLine("\nTrying to launch NotePad using your login information...");
Process.Start("notepad.exe", uname, password, domain);
}
catch (Win32Exception ex)
{
Console.WriteLine(ex.Message);
}
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\";
try
{
// The following call to Start succeeds if test.txt exists.
Console.WriteLine("\nTrying to launch 'text.txt'...");
Process.Start(path + "text.txt");
}
catch (Win32Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
// Attempting to start in a shell using this Start overload fails. This causes
// the following exception, which is picked up in the catch block below:
// The specified executable is not a valid application for this OS platform.
Console.WriteLine("\nTrying to launch 'text.txt' with your login information...");
Process.Start(path + "text.txt", uname, password, domain);
}
catch (Win32Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
password.Dispose();
}
}
}
示例2: OpenApplication
//引入命名空間
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
class MyProcess
{
// Opens the Internet Explorer application.
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);
}
// Opens urls and .html documents using Internet Explorer.
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");
}
// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
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();
}
}
}
示例3: Main
//引入命名空間
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
class MyProcess
{
public static void Main()
{
try
{
using (Process myProcess = new Process())
{
myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
// This code assumes the process you are starting will terminate itself.
// Given that is is started without a window so you cannot terminate it
// on the desktop, it must terminate itself or you can do it programmatically
// from this application using the Kill method.
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
示例4: Main
//引入命名空間
using System;
using System.Diagnostics;
class MainClass {
public static void Main() {
Process newProc = Process.Start("wordpad.exe");
Console.WriteLine("New process started.");
newProc.WaitForExit();
newProc.Close(); // free resources
Console.WriteLine("New process ended.");
}
}