日期:2014-05-19  浏览次数:20905 次

C#如何运行一个外部程序
比如说我想通过C#程序启动Power   Point,但是我并不知道Power   Point主程序的路径。

也就是说:
1、如何找到PPT主程序的路径。
2、如何通过程序启动PPT。
3、在适当的时候关闭PPT,或者即使C#程序结束,PPT也不关闭。

请大家赐教。

------解决方案--------------------
比如:
Process.Start( "IExplore.exe ", "C:\\myPath\\myFile.asp ");

或用其它的Start重载函数来运行
------解决方案--------------------
要找到ppt主程序的路径,注册表里应该有
要运行ppt,直接System.Diagnostics.Process.Start( "filename ");就行
------解决方案--------------------
你可以这样来取这个值,因为这个键是默认名字,可以用String.Empty或 " "来取,如下:

RegistryKey PowerPointKey = Registry.ClassesRoot.OpenSubKey( "MSPowerPoint\\protocol\\StdFileEditing\\server ");
object value = PowerPointKey.GetValue( " ");
string strPowerPointPath = value as string;

或:

RegistryKey PowerPointKey = Registry.ClassesRoot.OpenSubKey( "MSPowerPoint\\protocol\\StdFileEditing\\server ");
object value = PowerPointKey.GetValue(string.Empty);
string strPowerPointPath = value as string;

------解决方案--------------------
直接运行就行了...

for example:

Process.Start(@ "E:\test.ppt ");