(我们正在做类似的事情)您Postgres
使用此批处理文件为服务加注星标
"C:\Program Files\PostgreSQL\9.0\bin\pg_ctl.exe" -D "C:\Program Files\PostgreSQL\9.0\data" start
和 [停止] 服务
"C:\Program Files\PostgreSQL\9.0\bin\pg_ctl.exe" -D "C:\Program Files\PostgreSQL\9.0\data" stop
您可以从哪里C:\Program Files\PostgreSQL\9.0\bin\pg_ctl.exe
获得您的安装位置PostgreSQl
HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-9.0
现在在运行批处理文件以检查服务是否确实在运行时,您可以使用进程运行中的此代码
检查postgres.exe
它是否正在运行。
另外 1.检查 Windows 应用程序是否正在运行
2.我如何知道如果进程正在运行
public bool IsProcessOpen(string name)
{
//here we're going to get a list of all running processes on
//the computer
foreach (Process clsProcess in Process.GetProcesses()) {
//now we're going to see if any of the running processes
//match the currently running processes. Be sure to not
//add the .exe to the name you provide, i.e: NOTEPAD,
//not NOTEPAD.EXE or false is always returned even if
//notepad is running.
//Remember, if you have the process running more than once,
//say IE open 4 times the loop thr way it is now will close all 4,
//if you want it to just close the first one it finds
//then add a return; after the Kill
if (clsProcess.ProcessName.Contains(name))
{
//if the process is found to be running then we
//return a true
return true;
}
}
//otherwise we return a false
return false;
}