关于 windows mobile 进程操作的方法
#region Process class
/// <summary>
/// Summary description for Process.
/// </summary>
public class Process
{
private string processName;
private IntPtr handle;
private int threadCount;
private int baseAddress; //default constructor
public Process()
{ } private Process(IntPtr id, string procname, int threadcount, int baseaddress)
{
handle = id;
processName = procname;
threadCount = threadcount;
baseAddress = baseaddress;
} //ToString implementation for ListBox binding
public override string ToString()
{
return processName;
} public int BaseAddress
{
get
{
return baseAddress;
}
} public int ThreadCount
{
get
{
return threadCount;
}
} public IntPtr Handle
{
get
{
return handle;
}
} public string ProcessName
{
get
{
return processName;
}
} public int BaseAddess
{
get
{
return baseAddress;
}
} public void Kill()
{
IntPtr hProcess; hProcess = OpenProcess(PROCESS_TERMINATE, false, (int) handle); if(hProcess != (IntPtr) INVALID_HANDLE_VALUE)
{
bool bRet;
bRet = TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
} } public static Process[] GetProcesses()
{
ArrayList procList = new ArrayList(); IntPtr handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if ((int)handle > 0)
{
try
{
PROCESSENTRY32 peCurrent;
PROCESSENTRY32 pe32 = new PROCESSENTRY32();
//Get byte array to pass to the API calls
byte[] peBytes = pe32.ToByteArray();
//Get the first process
int retval = Process32First(handle, peBytes); while (retval == 1)
{
//Convert bytes to the class
peCurrent = new PROCESSENTRY32(peBytes);
//New instance
Process proc = new Process(new IntPtr((int)peCurrent.PID), peCurrent.Name, (int)peCurrent.ThreadCount, (int)peCurrent.BaseAddress); procList.Add(proc); retval = Process32Next(handle, peBytes);
}
}
catch (Exception ex)
{
throw new Exception("Exception: " + ex.Message);
} //Close handle
CloseToolhelp32Snapshot(handle); return (Process[])procList.ToArray(typeof(Process)); }
else
{
throw new Exception("Unable to create snapshot");
} } #region PROCESSENTRY32 implementation // typedef struct tagPROCESSENTRY32
// {
// DWORD dwSize;
// DWORD cntUsage;
// DWORD th32ProcessID;
// DWORD th32DefaultHeapID;
// DWORD th32ModuleID;
// DWORD cntThreads;
// DWORD th32ParentProcessID;
// LONG pcPriClassBase;
// DWORD dwFlags;
// TCHAR szExeFile[MAX_PATH];
// DWORD th32MemoryBase;
// DWORD th32AccessKey;
// } PROCESSENTRY32; private class PROCESSENTRY32
{
// constants for structure definition
private const int SizeOffset = 0;
private const int UsageOffset = 4;
private const int ProcessIDOffset=8;
private const int DefaultHeapIDOffset = 12;
private const int ModuleIDOffset = 16;
private const int ThreadsOffset = 20;
private const int ParentProcessIDOffset = 24;
private const int PriClassBaseOffset = 28;
private const int dwFlagsOffset = 32;
private const int ExeFileOffset = 36;
private const int MemoryBaseOffset = 556;
private const int AccessKeyOffset = 560;
private const int Size = 564;
private const int MAX_PATH = 260; // data members
public uint dwSize;
public uint cntUsage;
public uint th32ProcessID;
public uint th32DefaultHeapID;
public uint th32ModuleID;
public uint cntThreads;
public uint th32ParentProcessID;
public long pcPriClassBase;
public uint dwFlags;
public string szExeFile;
public uint th32MemoryBase;
public uint th32AccessKey; //Default constructor
public PROCESSENTRY32()
{ } // create a PROCESSENTRY instance based on a byte array
public PROCESSENTRY32(byte[] aData)
{
dwSize = GetUInt(aData, SizeOffset);
cntUsage = GetUInt(aData, UsageOffset);
th32ProcessID = GetUInt(aData, ProcessIDOffset);
th32DefaultHeapID = GetUInt(aData, DefaultHeapIDOffset);
th32ModuleID = GetUInt(aData, ModuleIDOffset);
cntThreads = GetUInt(aData, ThreadsOffset);
th32ParentProcessID = GetUInt(aData, ParentProcessIDOffset);
pcPriClassBase = (long) GetUInt(aData, PriClassBaseOffset);
dwFlags = GetUInt(aData, dwFlagsOffset);
szExeFile = GetString(aData, ExeFileOffset, MAX_PATH);
th32MemoryBase = GetUInt(aData, MemoryBaseOffset);
th32AccessKey = GetUInt(aData, AccessKeyOffset);
} #region Helper conversion functions
// utility: get a uint from the byte array
private static uint GetUInt(byte[] aData, int Offset)
{
return BitConverter.ToUInt32(aData, Offset);
} // utility: set a uint int the byte array
private static void SetUInt(byte[] aData, int Offset, int Value)
{
byte[] buint = BitConverter.GetBytes(Value);
Buffer.BlockCopy(buint, 0, aData, Offset, buint.Length);
} // utility: get a ushort from the byte array
private static ushort GetUShort(byte[] aData, int Offset)
{
return BitConverter.ToUInt16(aData, Offset);
} // utility: set a ushort int the byte array
private static void SetUShort(byte[] aData, int Offset, int Value)
{
byte[] bushort = BitConverter.GetBytes((short)Value);
Buffer.BlockCopy(bushort, 0, aData, Offset, bushort.Length);
} // utility: get a unicode string from the byte array
private static string GetString(byte[] aData, int Offset, int Length)
{
String sReturn = Encoding.Unicode.GetString(aData, Offset, Length);
return sReturn;
} // utility: set a unicode string in the byte array
private static void SetString(byte[] aData, int Offset, string Value)
{
byte[] arr = Encoding.ASCII.GetBytes(Value);
Buffer.BlockCopy(arr, 0, aData, Offset, arr.Length);
}
#endregion // create an initialized data array
public byte[] ToByteArray()
{
byte[] aData;
aData = new byte[Size];
//set the Size member
SetUInt(aData, SizeOffset, Size);
return aData;
} public string Name
{
get
{
return szExeFile.Substring(0, szExeFile.IndexOf('\0'));
}
} public ulong PID
{
get
{
return th32ProcessID;
}
} public ulong BaseAddress
{
get
{
return th32MemoryBase;
}
} public ulong ThreadCount
{
get
{
return cntThreads;
}
}
}
#endregion #region PInvoke declarations
private const int TH32CS_SNAPPROCESS = 0x00000002;
[DllImport("toolhelp.dll")]
public static extern IntPtr CreateToolhelp32Snapshot(uint flags, uint processid);
[DllImport("toolhelp.dll")]
public static extern int CloseToolhelp32Snapshot(IntPtr handle);
[DllImport("toolhelp.dll")]
public static extern int Process32First(IntPtr handle, byte[] pe);
[DllImport("toolhelp.dll")]
public static extern int Process32Next(IntPtr handle, byte[] pe);
[DllImport("coredll.dll")]
private static extern IntPtr OpenProcess(int flags, bool fInherit, int PID);
private const int PROCESS_TERMINATE = 1;
[DllImport("coredll.dll")]
private static extern bool TerminateProcess(IntPtr hProcess, uint ExitCode);
[DllImport("coredll.dll")]
private static extern bool CloseHandle(IntPtr handle);
private const int INVALID_HANDLE_VALUE = -1; #endregion
} #endregion
代码来至:http://msdn.microsoft.com/en-us/library/aa446560.aspx
关于 windows mobile 进程操作的方法的更多相关文章
- 转载扩展Windows Mobile模拟器存储空间的方法
扩展Windows Mobile模拟器存储空间的方法 在Windows Mobile应用程序开发的初期,可以使用SDK自带的模拟器来进行调试,这给我们开发人员提供了一种方便的途径.一般的应用程序,占用 ...
- Windows的拖放操作使用方法
Windows的拖放操作使用方法
- 在Linux下和Windows下遍历目录的方法及如何达成一致性操作
最近因为测试目的需要遍历一个目录下面的所有文件进行操作,主要是读每个文件的内容,只要知道文件名就OK了.在Java中直接用File类就可以搞定,因为Java中使用了组合模式,使得客户端对单个文件和文件 ...
- Windows提供了两种将DLL映像到进程地址空间的方法(隐式和显式)
调用DLL,首先需要将DLL文件映像到用户进程的地址空间中,然后才能进行函数调用,这个函数和进程内部一般函数的调用方法相同.Windows提供了两种将DLL映像到进程地址空间的方法: 1. 隐式的加载 ...
- Windows提供了两种将DLL映像到进程地址空间的方法
调用DLL,首先需要将DLL文件映像到用户进程的地址空间中,然后才能进行函数调用,这个函数和进程内部一般函数的调用方法相同.Windows提供了两种将DLL映像到进程地址空间的方法: 1. 隐式的加载 ...
- Day9 进程理论 开启进程的两种方式 多进程实现并发套接字 join方法 Process对象的其他属性或者方法 守护进程 操作系统介绍
操作系统简介(转自林海峰老师博客介绍) #一 操作系统的作用: 1:隐藏丑陋复杂的硬件接口,提供良好的抽象接口 2:管理.调度进程,并且将多个进程对硬件的竞争变得有序 #二 多道技术: 1.产生背景: ...
- Win10下windows mobile设备中心连接不上的方法无法启动
微软Win10自动更细补丁后windows mobile设备中心就无法启动了 需要重新启动相关的服务并授予 本机登录用户 权限 1.点击屏幕左下角“开始”图标,点击“运行”,在弹出的输入框中输入“se ...
- C#进程操作
C#进程操作 转:http://www.cnblogs.com/vienna/p/3560804.html 一.C#关闭word进程 foreach (System.Diagnostics.Proc ...
- Windows Mobile和Wince(Windows Embedded CE)的字符集问题
背景 开发过Windows Mobile和Wince(Windows Embedded CE)的开发者,特别是Native C++开发者,或多或少都遇到过ANSI字符集和Unicode字符集的转换问题 ...
随机推荐
- Codeforces 808D. Array Division
题目大意 给定你一个长为\(n\)的序列,问能否在最多一次取出某一元素然后插入到某一点后可以将整个序列分成两段使得其两段的元素之和相同. \(n \leq 10^5\) 题解 发现插入操作实际上是让某 ...
- python实现进程的并发
__author__ = 'luozt' import telnetlib import multiprocessing import random def telnet(ip,hostname): ...
- (转)heX——基于 HTML5 和 Node.JS 开发桌面应用
本文转载自:http://techblog.youdao.com/?p=685 简介:heX,一个允许你采用前端技术(HTML,CSS,JavaScript)开发桌面应用软件的跨平台解决方案.是你开发 ...
- 有关UCOS_II在LPC1768上的应用
https://www.cnblogs.com/chungshu/archive/2012/12/14/2818380.html
- Oracle user,role,profile常规操作--用户,权限,角色,配置文件
Oracle user,role,profile常规操作--用户,权限,角色,配置文件 1 权限查询 1查看所有用户 SQL> select username,account_status,lo ...
- 远程摄像头软件mjpg-streamer使用指南
转 自:http://bbs.hdchina.org/viewthread.php?tid=94749 mjpg-streamer 可以通过文件或者是HTTP方式访问linux UVC兼容摄像头.可以 ...
- 50 states of America
美国州名 州名英文 州名音标 简写 首府 首府 阿拉巴马州 Alabama [ˌæləˈbæmə] AL 蒙哥马利 Montgomery[mənt'gʌməri] 阿拉斯加州 Alaska [ ...
- [Python]python CGI脚本在apache服务器上运行时出现“Premature end of script headers”错误
在测试自己的python CGI脚本时, 当html网页中的表单form内容传送到服务器python脚本时, 总是出现Premature end of script headers错误, 网页显示是服 ...
- 将chrome浏览器的默认背景颜色修改为浅绿色,以减缓长时间看电脑的眼睛不舒服的问题
修改chrome文件夹中的Custom.css, 此文件里面默认内容是空的. 在其中添加下面这段代码: 你也可以选择自己的喜欢的颜色, 前提是你知道你想要更改的颜色的十六进制颜色值, 例如:#CCEB ...
- javascript——对象的概念——函数 3 (使用技巧)
1.回调函数:将函数A传给函数B,由函数B来执行A,则称A为回调函数. 例1: 例2 function addone(a){;}; //定义一个回调函数 function mulitiply(a,b, ...