惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
腾讯CDC
博客园 - Franky
Engineering at Meta
Engineering at Meta
C
Check Point Blog
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
S
SegmentFault 最新的问题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学

博客园 - 漂失在蓝天下的云

微软自带的sqlserver的jdbc驱动的缺陷及解决方法 SQL Sever中文乱码的分析解决 - 漂失在蓝天下的云 - 博客园 UTF-8乱码解决 在asp.net页面中的一些有关编码的问题 - 漂失在蓝天下的云 - 博客园 在ASP.net页面引用js时的注意事项 - 漂失在蓝天下的云 - 博客园 如何处理提交页面是GB2312编码格式,接收页面是UTF-8格式? - 漂失在蓝天下的云 - 博客园 Asp.Net细节性问题技巧精萃 日期正则表达式 什么是正则表达式 正则表达式之道 让你终身受用的4个经典故事 五个寓言故事令你受益匪浅 调用cmd.exe程序和外部程序(转) C#程序调用外部程序 帮你免于失业的十大软件技术! 网站首页head区代码规范(网页设计师必看) 网站首页head区代码规范(网页设计师必看) 一个不错的页面特效 网页制作代码
Asp.NET中运行exe
漂失在蓝天下的云 · 2006-10-11 · via 博客园 - 漂失在蓝天下的云

private void usec(string userName,string realm,string Pwd)
{
//声明一个程序信息类
System.Diagnostics.ProcessStartInfo  Info  =  new  System.Diagnostics.ProcessStartInfo();
 
//设置外部程序名
Info.FileName  =  "cmd.exe";
string path=System.Configuration.ConfigurationSettings.AppSettings["chash"];
path=path.Replace("\\","\\\\");
//设置外部程序的启动参数(命令行参数)为test.txt
Info.Arguments  =  "/c \"createauth.exe "+userName+" "+realm+" "+Pwd+" > createauth\"";
 
//设置外部程序工作目录为  C:\
Info.WorkingDirectory  =path;
//Response.Write(path);
 
//声明一个程序类
System.Diagnostics.Process  Proc  ;
 
try
{
//启动外部程序
Proc  =  System.Diagnostics.Process.Start(Info);
}
catch(System.ComponentModel.Win32Exception  e)
{
Response.Write("系统找不到指定的程序文\r{0}"+e);
Response.End();
return;
}
//打印出外部程序的开始执行时间
//Response.Write("外部程序的开始执行时间:");
//等待10秒钟
Proc.WaitForExit(10000);
 
//如果这个外部程序没有结束运行则对其强行终止
if(Proc.HasExited  ==  false)
{
//Response.Write("由主程序强行终止外部程序的运行!");
Proc.Kill();
}
else
{
//Response.Write("由外部程序正常退出!"); 
}
}
 

------------------------------------------------------------------------------------------------------------------------------

/// <summary>
/// 运行外部程序
/// </summary>
/// <param name="exeName">程序路径</param>
/// <returns>0:失败,1:成功</returns>
public bool RunIt( string exeName )
{
//声明一个程序信息类
System.Diagnostics.ProcessStartInfo  Info  =  new  System.Diagnostics.ProcessStartInfo();
//设置外部程序名
Info.FileName  = exeName;
//声明一个程序类
try
{
System.Diagnostics.Process  Proc  ;
Proc  =  System.Diagnostics.Process.Start(Info);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 判断是否运行
/// </summary>
/// <param name="exeName">程序名</param>
/// <returns>0:没运行,1:运行中</returns>
public bool IsRun( string exeName )
{
string isrunning = "0";
Process[] myProcesses = Process.GetProcesses();
foreach(Process myProcess in myProcesses)
{
if ( myProcess.ProcessName == exeName )
{
isrunning = "1";
break;
}
}
if ( isrunning == "1" )
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 结束进程
/// </summary>
/// <param name="exeName">进程名</param>
/// <returns>0:失败,1:成功</returns>
public bool Kill( string exeName )
{
string isrunning = "0";
Process[] myProcesses = Process.GetProcesses();
foreach(Process myProcess in myProcesses)
{
if ( myProcess.ProcessName == exeName )
{
try
{
myProcess.Kill();
isrunning = "1";
}
catch
{
isrunning = "0";
}
break;
}
}
if ( isrunning == "1" )
{
return true;
}
else
{
return false;
}
}