
判断代码如下:
string name = "进程名"
if (GetPidByProcessName(name) == 0)
{
MessageBox.Show("程序未运行")
return
}public static int GetPidByProcessName(string processName)
{
Process[] arrayProcess = Process.GetProcessesByName(processName)foreach (Process p in arrayProcess)
{
return p.Id
}
return 0
}
扩展资料:注意事项
/获取欲启动进程名
string strProcessName
strProcessName = System.Diagnostics.Process.GetCurrentProcess().ProcessName
//检查进程是否已经启动,已经启动则退出程序虚局。
if (System.Diagnostics.Process.GetProcessesByName(strProcessName).Length >扰伏 1)
{
Application.Exit()
缓誉携 return
}
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(false)
Application.Run(new frmMainPlatform())
下面是列举进程的代码,态敬闹改一下就形了HANDLE SnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0)
if(SnapShot==NULL)
{
MessageBox("检测当前进程失败!")
return FALSE
}
SHFILEINFO shSmall
int nIndex
CString str,prcnum
PROCESSENTRY32 ProcessInfo//声明进程信息变量
ProcessInfo.dwSize=sizeof(ProcessInfo)//设置ProcessInfo的大小
//返回系统中帆罩第一稿羡个进程的信息
BOOL Status=Process32First(SnapShot,&ProcessInfo)
int m_nProcess=0,num=0
while(Status)
{
m_nProcess++
num++
//获取进程文件信息
SHGetFileInfo(ProcessInfo.szExeFile,0,&shSmall,
sizeof(shSmall),SHGFI_ICON|SHGFI_SMALLICON)
//在列表控件中添加映像名称
nIndex=m_list.InsertItem(m_nProcess,ProcessInfo.szExeFile)
//获取下一个进程的信息
Status=Process32Next(SnapShot,&ProcessInfo)
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)