当前位置:
文档之家› .net中打开应用程序的几种方法
.net中打开应用程序的几种方法
<BUTTON class=button onclick="Run('mspaint')">画图板</BUTTON><br/>
<BUTTON class=button onclick="Run('calc')">计算器</BUTTON><br/>
<BUTTON class=button onclick="Run('cmd')">cmd</BUTTON><br/>
StreamWriter wt = File.AppendText(@"D:\xPertErrLog.txt");
wt.Write("打开应用程序成功!路径为"+path);
wt.WriteLine(File.GetLastWriteTime(@"D:\xPertErrLog.txt"));
wt.Close();
第一种:System.Diagnostics.Process.Start(iexplore.exe) //为打开浏览器..
直接调用Diagnostics类打开Start的参数亦可为路径
string path = "C:\\Program Files\\Raymark\\Xpert-Central_live\\Main\\posisent.exe";
System.Diagnostics.Process.Start(path);
第二种:首先尝试用开始运行cmd输入路径start /D "C:\Program Files\Raymark\Xpert-Central\Main\" posisent.exe路径可随意更改为在本机的应用程序路径
确认该路径可用后代码中可按以下打开
public void OpenRunPark()
{
try
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
eShellExecute = false;
value="regedit"><BUTTON class=button
onclick="Run(exe.value)">确定</BUTTON><BUTTON class=button
onclick=exe.value="";>重新输入</BUTTON><br/>
<BUTTON class=button onclick="Run('notepad')">记事本</BUTTON><br/>
objShell.Run(strPath);
objShell = null;
}
catch (e){alert('找不到文件"'+strPath+'"(的库文件均可用。')
}
}
</SCRIPT>
请输入要运行的程序:<br/><input name=exe type=text size=20
p.Start();
string path = "start /D \"C:\\Program Files\\Raymark\\Xpert-Central_live\\Main\\\" posisent.exe";
p.StandardInput.WriteLine(path);
p.Close();
p.Dispose();
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
<BUTTON class=button onclick="Run('%temp%')">%temp%</BUTTON><br/>
</body>
</html>
<BUTTON class=button onclick="Run('Regedit')">Regedit</BUTTON><br/>
<BUTTON class=button onclick="Run('Msconfig')">Msconfig</BUTTON><br/>
<BUTTON class=button onclick="Run('file:///D:/Program%20Files/Winamp/WINAMP.EXE')">WINAMP</BUTTON><br/>
wt.Close();
}
}
第三种
在网页中打开本地应用程序(javascript)
<html>
<body>
<SCRIPT language=javascript>
function Run(strPath) {
exe.value=strPath;
try {
var objShell = new ActiveXObject("wscript.shell");
<BUTTON class=button onclick="Run('IEXPLORE.EXE')">IE</BUTTON><br/>
<BUTTON class=button onclick="Run('..')">..</BUTTON><br/>
<BUTTON class=button onclick="Run('%windir%')">%windir%</BUTTON><br/>
}
catch
{
StreamWriter wt = File.AppendText(@"D:\xPertErrLog.txt");
wt.Write("打开应用程序失败!请检查打开路径是否出错!");
wt.WriteLine(File.GetLastWriteTime(@"D:\xPertErrLog.txt"));