WinCE怎么判断进程是否已经存在???

nkhuangyanping 2011-12-08 05:18:44
在网上找到这端代码

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
/// <summary>
/// MobileUtils
/// </summary>
public class MobileUtils
{

/// <summary>
/// 判断某个进程是否已经存在
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool IsProcessRunning(string processName)
{
int hMutex;
hMutex = CreateMutex(null, false, processName);

if (GetLastError() == ERROR_ALREADY_EXISTS)
{
ReleaseMutex(hMutex);
return true;
}
return false;
}

/// <summary>
/// GetLastError
/// </summary>
/// <returns></returns>
[DllImport("coredll.Dll")]
private static extern int GetLastError();

/// <summary>
/// ReleaseMutex
/// </summary>
/// <param name="hMutex"></param>
/// <returns></returns>
[DllImport("coredll.Dll")]
private static extern int ReleaseMutex(int hMutex);

/// <summary>
/// CreateMutex
/// </summary>
/// <param name="lpMutexAttributes"></param>
/// <param name="bInitialOwner"></param>
/// <param name="lpName"></param>
/// <returns></returns>
[DllImport("coredll.Dll")]
private static extern int CreateMutex(SECURITY_ATTRIBUTES lpMutexAttributes, bool bInitialOwner, string lpName);

/// <summary>
///
/// </summary>
private const int ERROR_ALREADY_EXISTS = 0183;

/// <summary>
/// SECURITY_ATTRIBUTES
/// </summary>
[StructLayout(LayoutKind.Sequential)]
private class SECURITY_ATTRIBUTES
{

/// <summary>
///
/// </summary>
public int nLength;

/// <summary>
///
/// </summary>
public int lpSecurityDescriptor;

/// <summary>
///
/// </summary>
public int bInheritHandle;

}
}
}


我按照这个做的,我的工程名字是AProject,可是检测时候时候即使我已经开启了这个软件,再次开启时还是检测不到开启,请问CreateMutex(null, false, processName);中得软件名字该写什么呢?
...全文
224 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
nkhuangyanping 2012-02-17
  • 打赏
  • 举报
回复
不行的
meic1985 2011-12-13
  • 打赏
  • 举报
回复
processName = Assembly.GetExecutingAssembly().GetName().Name;
这么写试试
nkhuangyanping 2011-12-13
  • 打赏
  • 举报
回复
没有个人来接分。哎。
nkhuangyanping 2011-12-08
  • 打赏
  • 举报
回复
估计我这个不支持,大家知道有什么别的办法吗?

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧