按照交通银行提供的*面启动方法试验了很多次,都没有成功,所以自己动手用C# 知识写了一个。
小工具可以判断 交通银行 JAVA SOCKET 服务是否启动,并可以启动/关闭服务
主要代码如下:
判断服务是否启动
引用 :using System.Management;
SelectQuery selectQuery = new SelectQuery(“select * from Win32_Process where Name = ‘java.exe’”);
object cmdLine = string.Empty;
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery))
{
foreach (ManagementObject process in searcher.Get())
{
cmdLine = process.Properties["CommandLine"].Value;
if (cmdLine != null)
{
if (cmdLine.ToString().IndexOf(this.txtSocketPath.Text.Trim()) != -1)//当前服务已经启动了
{
this.btnStartService.Enabled = false;
this.btnKill.Enabled = true;
lblServerStatus.Text = “服务已经启动“;
continue;
}
}
}
}
启动服务
Process myProcess = new Process();
myProcess.StartInfo.FileName = string.IsNullOrEmpty(this.txtJavaPath.Text.Trim()) ?“java” : this.txtJavaPath.Text.Trim();
myProcess.StartInfo.Arguments = string.Format(“-jar {0} {1} {2} {3}”,this.txtSocketPath.Text.Trim(), this.txtSocketPort.Text.Trim(),this.txtConfigPath.Text.Trim(), this.txtLogPath.Text.Trim());
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.Start();
this.btnStartService.Enabled = false;
lblServerStatus.Text = “服务已经启动“;
this.btnKill.Enabled = true;
关闭服务
foreach (System.Diagnostics.Process thisproc inSystem.Diagnostics.Process.GetProcesses())
{
if (thisproc.ProcessName.ToUpper().Equals(“JAVA”))
{
thisproc.Kill();
}
}
this.btnStartService.Enabled = true;
this.btnKill.Enabled = false;
lblServerStatus.Text = “服务未启动“;
运行界面
原创,转载请注明:原地址:http://www.cnblogs.com/xt_hjl/p/3864120.html
技术支持:好搜 http://www.haosearch.com/