ProcessStartInfo.Verb 属性
获取或设置打开 FileName 属性指定的应用程序或文档时要使用的谓词。
**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)
语法
声明
Public Property Verb As String
用法
Dim instance As ProcessStartInfo
Dim value As String
value = instance.Verb
instance.Verb = value
public string Verb { get; set; }
public:
property String^ Verb {
String^ get ();
void set (String^ value);
}
/** @property */
public String get_Verb ()
/** @property */
public void set_Verb (String value)
public function get Verb () : String
public function set Verb (value : String)
属性值
要对进程打开的文件执行的操作。默认值为空字符串 ("")。
备注
每个文件扩展名都有它自己的一组谓词;可以使用 Verbs 属性获取这些谓词。例如,“print”谓词将打印使用 FileName 指定的文档。可使用空字符串 ("") 指定默认谓词。
当使用 Verbs 属性时,必须在设置 FileName 属性的值时包括文件扩展名。如果您手动为 Verb 属性输入一个值,则该文件名不需要具有扩展名。
示例
下面的示例使用指定的操作和文件名启动一个新进程。
Public Shared Sub StartWithVerb(fileName As String, verb As String, _
args As String)
If Not (fileName Is Nothing) AndAlso fileName.Length > 0 _
AndAlso Not (verb Is Nothing) AndAlso verb.Length > 0
If File.Exists(fileName)
Dim startInfo As ProcessStartInfo
startInfo = New ProcessStartInfo(fileName)
startInfo.Verb = verb
startInfo.Arguments = args
Dim newProcess As New Process()
newProcess.StartInfo = startInfo
Try
newProcess.Start()
Console.WriteLine( _
"{0} for file {1} started successfully with verb ""{2}""!", _
newProcess.ProcessName, fileName, startInfo.Verb)
Catch e As System.ComponentModel.Win32Exception
Console.WriteLine(" Win32Exception caught!")
Console.WriteLine(" Win32 error = {0}", e.Message)
Catch e As System.InvalidOperationException
' Catch this exception if the process exits quickly,
' and the properties are not accessible.
Console.WriteLine("File {0} started with verb {1}", _
startInfo.FileName, startInfo.Verb.ToString())
End Try
End If
End If
End Sub
public static void StartWithVerb(string fileName, string verb, string args)
{
if (((fileName != null) && (fileName.Length > 0)) &&
((verb != null) && (verb.Length > 0)))
{
if (File.Exists(fileName))
{
ProcessStartInfo startInfo;
startInfo = new ProcessStartInfo(fileName);
startInfo.Verb = verb;
startInfo.Arguments = args;
Process newProcess = new Process();
newProcess.StartInfo = startInfo;
try
{
newProcess.Start();
Console.WriteLine(
"{0} for file {1} started successfully with verb \"{2}\"!",
newProcess.ProcessName, fileName, startInfo.Verb);
}
catch (System.ComponentModel.Win32Exception e)
{
Console.WriteLine(" Win32Exception caught!");
Console.WriteLine(" Win32 error = {0}",
e.Message);
}
catch (System.InvalidOperationException)
{
// Catch this exception if the process exits quickly,
// and the properties are not accessible.
Console.WriteLine("File {0} started with verb {1}",
fileName, verb);
}
}
else
{
Console.WriteLine("File not found: {0}", fileName);
}
}
else
{
Console.WriteLine("Invalid input for file name or verb.");
}
}
void StartWithVerb( String^ fileName, String^ verb, String^ args )
{
if ( ((fileName != nullptr) && (fileName->Length > 0)) && ((verb != nullptr) && (verb->Length > 0)) )
{
if ( File::Exists( fileName ) )
{
ProcessStartInfo^ startInfo;
startInfo = gcnew ProcessStartInfo( fileName );
startInfo->Verb = verb;
startInfo->Arguments = args;
Process^ newProcess = gcnew Process;
newProcess->StartInfo = startInfo;
try
{
newProcess->Start();
Console::WriteLine( "{0} for file {1} started successfully with verb \"{2}\"!", newProcess->ProcessName, fileName, startInfo->Verb );
}
catch ( System::ComponentModel::Win32Exception^ e )
{
Console::WriteLine( " Win32Exception caught!" );
Console::WriteLine( " Win32 error = {0}", e->Message );
}
catch ( System::InvalidOperationException^ )
{
// Catch this exception if the process exits quickly,
// and the properties are not accessible.
Console::WriteLine( "File {0} started with verb {1}", fileName, verb );
}
}
else
{
Console::WriteLine( "File not found: {0}", fileName );
}
}
else
{
Console::WriteLine( "Invalid input for file name or verb." );
}
}
平台
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
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0
请参见
参考
ProcessStartInfo 类
ProcessStartInfo 成员
System.Diagnostics 命名空间
Verbs