RAPI提供了一些取系统信息的函数

CeGetSystemInfo:返回当前系统信息

CeGetSystemMetrics:获取Windows元素的尺寸和系统设置

CeGetVersionEx:获取当前运行的操作系统版本的扩展信息

CeGetSystemPowerStatusEx:获取电池状态

CeGlobalMemoryStatus:获取系统物理内存和虚拟内存信息

CeGetStoreInfomation:获取存储器信息并填入STORE_INFORMATION结构

        SYSTEM_INFO si; //系统信息
OSVERSIONINFO versionInfo; //版本信息
SYSTEM_POWER_STATUS_EX PowerStatus; //电源信息
MEMORYSYATUS ms; //内存信息
String info; private const int TimeOut = ;//异步连接设备超时时间2秒
private void btnGetSystemInfo_Click(object sender, EventArgs e)
{
Rapiinit ri = new Rapiinit();
ri.cbsize = Marshal.SizeOf(ri);
uint hRes = CeRapiInitEx(ref ri);
ManualResetEvent me = new ManualResetEvent(false);
me.SafeWaitHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle(ri.heRapiInit, false);
if (!me.WaitOne(TimeOut, true))
{
CeRapiUninit();
} //1、检索系统信息
try
{
CeGetSystemInfo(out si);
}
catch (Exception)
{
throw new Exception("Error retrieving system info.");
} //2、检索设备操作系统版本号
bool b;
versionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFO));//设置为结构大小
b = CeGetVersionEx(out versionInfo);
if (!b)
{
throw new Exception("Error retrieving version information.");
} //3、检索设备电源状态
try
{
CeGetSystemPowerStatusEx(out PowerStatus, true);// true 表示读取最新的电源信息,否则将从缓存中获得
}
catch (Exception)
{
throw new Exception("Error retriving System power status.");
} // 4、检索设备内存状态
CeGlobalMemoryStatus(out ms); //设置检索信息的格式
info = "The connected device has an";
switch (si.wProcessorArchitecture)
{
case ProcessorArchitecture.Intel:
info += "Intel processor.\n";
break;
case ProcessorArchitecture.ARM:
info += "ARM processor.\n";
break;
default:
info += "unknown processor type.\n";
break;
} info += "OS vesion:" + versionInfo.dwMajorVersion + "." + versionInfo.dwMinorVersion + "." + versionInfo.dwBuildNumber + "\n";
if (PowerStatus.ACLineStatus == )
{
info += "On AC power:Yes\n";
}
else
{
info += "On AC power:NO\n";
}
info += "Battery level:"+PowerStatus.BackupBatteryLifePercent+"%\n";
info += "Total memory:" + string.Format("{0:###,###,###}", ms.dwTotalPhys + "\n"); richTextBox1.AppendText(info); CeRapiUninit();
} #region 声明API [DllImport("rapi.dll")]
private static extern uint CeRapiInitEx(ref Rapiinit pRapiInt); [DllImport("rapi.dll", CharSet = CharSet.Unicode)]
internal static extern int CeRapiUninit(); [DllImport("rapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int CeGetSystemInfo(out SYSTEM_INFO pSI); [DllImport("rapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool CeGetVersionEx(out OSVERSIONINFO lpVersionInformation); [DllImport("rapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool CeGetSystemPowerStatusEx(out SYSTEM_POWER_STATUS_EX pStauts, bool fUpdate); [DllImport("rapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern void CeGlobalMemoryStatus(out MEMORYSYATUS msce); #endregion #region 声明结构 [StructLayout(LayoutKind.Explicit)]
private struct Rapiinit
{
[FieldOffset()]
public int cbsize;
[FieldOffset()]
public readonly IntPtr heRapiInit;
[FieldOffset()]
private readonly IntPtr hrRapiInit;
} //处理器架构CeGetSystemInfo
public enum ProcessorArchitecture : short
{
Intel=,
MIPS=,
Alpha=,
PPC=,
SHX=,
ARM=,
IA64=,
Alpha64=,
Unknown=-
} //移动设备内存信息
[StructLayout(LayoutKind.Sequential)]
public struct MEMORYSYATUS
{
internal uint dwLength;
public int dwMemoryLoad;//当前内存占用(%)
public int dwTotalPhys;//物理内存总量
public int dwAvailPhys;//可用物理内存
public int dwTotalPageFile;//分页数
public int dwAvailPageFile;//未分页
public int dwTotalVirtual;//虚拟内存总量
public int dwAvailVirtual;//可用虚拟内存
} //移动设备电源信息
public struct SYSTEM_POWER_STATUS_EX
{
public byte ACLineStatus;//交流电状态
public byte BatteryFlag;//电池充电状态 1 High,2 Low,4 Critical,8 Charging,128 No system battery,255 Unknown status
public byte BatteryLifePercent;//电池电量剩余百分比
internal byte Reserved1;//保留字段,设置为0
public int BatteryLifeTime;//电池电量剩余时间(秒)
public int BatteryFullLifeTime;//电池充满电的总可用时间(秒)
internal byte Reserved2;//保留字段,设置为0
public byte BackupBatteryFlag;//后备电池状态
public byte BackupBatteryLifePercent;//后备电池剩余电量百分比
internal byte Reserved3;//保留字段,设置为0
public int BackupBatteryLifeTime;//后备电池电量剩余时间(秒)
public int BackupBatteryFullLifeTime;//后备电池充满电的总可用时间(秒)
} //OSVERSIONINFO platform type
public enum PlatformType : int
{
//win32 on windows ce
VER_PLATFORM_WIN32_CE=
} public struct OSVERSIONINFO
{
internal int dwOSVersionInfoSize;
public int dwMajorVersion;//主板本信息
public int dwMinorVersion;//副版本信息
public int dwBuildNumber;//编译信息
public PlatformType dwPlatfromId;//操作系统类型
} //处理器类型CeGetSystemInfo
public enum ProcessorType : int
{
PROCESSOR_INTEL_386 = , //
PROCESSOR_INTEL_486 = , //
PROCESSOR_INTEL_PENTIUM = , //Pentium
PROCESSOR_INTEL_PENTIUMII = , //P2
PROCESSOR_INTEL_IA64 = , //IA 64
PROCESSOR_MIPS_R4000 = , //MIS 4000 series
PROCESSOR_ALPHA_21064 = , //Alpha 21064
PROCESSOR_PPC_403 = , //PowerPC 403
PROCESSOR_PPC_601 = , //PowerPC 601
PROCESSOR_PPC_603 = , //PowerPC 603
PROCESSOR_PPC_604 = , //PowerPC 604
PROCESSOR_PPC_620 = , //PowerPC 620
PROCESSOR_HITACHI_SH3 = , // Hitachi SH3
PROCESSOR_HITACHI_SH3E = , // Hitachi SH3E
PROCESSOR_HITACHI_SH4 = , //Hitachi SH4
PROCESSOR_MOTOROLA_821 = , //Motorola 821
PROCESSOR_SHx_SH3 = , //Hitachi SH3
PROCESSOR_SHx_SH4 = , //Hitachi SH4
PROCESSOR_STRONGARM = , //Intel StrongARM
PROCESSOR_ARM720 = , //ARM720
PROCESSOR_ARM820 = , //ARM820
PROCESSOR_ARM920 = , //ARM920
PROCESSOR_ARM_7TDMI = //ARM7
} //CeGetSystemInfo的数据结构
public struct SYSTEM_INFO
{
//处理器架构
public ProcessorArchitecture wProcessorArchitecture;
//保留
internal ushort wReserved;
//Specifies the page size and the granularity of page protection and commitment.
public int dwPageSize;
//应用程序可访问内存地址的最小值
//(Pointer to the lowest memory address accessible to applications and dynamic-link libraries (DLLs). )
public int lpMinimumApplicationAddress;
//应用程序可访问内存地址的最大值
public int lpMaximumApplicationAddress;
//Specifies a mask representing the set of processors configured into the system. Bit 0 is processor 0; bit 31 is processor 31.
public int dwActiveProcessorMask;
//处理器数量(Specifies the number of processors in the system.)
public int dwNumberOfProcessors;
//处理器类型(Specifies the type of processor in the system.)
public ProcessorType dwProcessorType;
//Specifies the granularity with which virtual memory is allocated.
public int dwAllocationGranularity;
//Specifies the system architecture-dependent processor level.
public short wProcessorLevel;
//Specifies an architecture-dependent processor revision.
public short wProcessorRevision;
} #endregion

Remote API(RAPI)之 系统信息的更多相关文章

  1. Docker入门教程(八)Docker Remote API

    Docker入门教程(八)Docker Remote API [编者的话]DockerOne组织翻译了Flux7的Docker入门教程,本文是系列入门教程的第八篇,重点介绍了Docker Remote ...

  2. 【转+自己研究】新姿势之Docker Remote API未授权访问漏洞分析和利用

    0x00 概述 最近提交了一些关于 docker remote api 未授权访问导致代码泄露.获取服务器root权限的漏洞,造成的影响都比较严重,比如 新姿势之获取果壳全站代码和多台机器root权限 ...

  3. Docker remote API简单配置使用

    1.启动docker remote API的方式如下: docker -d -H uninx:///var/run/docker.sock -H tcp://0.0.0.0:5678 2.但是为了伴随 ...

  4. V-REP Remote API(C++)实现简单的关节转动

    基础内容参考:https://www.cnblogs.com/eternalmoonbeam/p/10753149.html V-REP客户端设置: 在V-REP场景文件中需要添加三个实体,包括两个形 ...

  5. docker remote api enable in ubuntu

    现在使用docker作为开发环境,操作系统是ubuntu16.10,pycharm中使用remote interpreter,需要用到remote api,结果发现自己的原答案是针对ubuntu 14 ...

  6. Docker Remote API v1.24

    1. Brief introduction The Remote API has replaced rcli. The daemon listens on unix:///var/run/docker ...

  7. 关于docker remote api未授权访问漏洞的学习与研究

    漏洞介绍: 该未授权访问漏洞是因为docker remote api可以执行docker命令,从官方文档可以看出,该接口是目的是取代docker 命令界面,通过url操作docker. docker ...

  8. docker 开启remote api

    docker官方文档上有相关说明(Configure and run Docker on various distributions),ubuntu上是可行的 sudo vi /etc/default ...

  9. Docker开启Remote API 访问 2375端口

    Docker常见端口 我看到的常见docker端口包括: 2375:未加密的docker socket,远程root无密码访问主机2376:tls加密套接字,很可能这是您的CI服务器4243端口作为h ...

  10. Docker remote API

    Docker remote API 该教程基于Ubuntu或Debian环境,如果不是,请略过本文 Docker API 在Docker生态系统中一共有三种API Registry API:提供了与来 ...

随机推荐

  1. idea的配置文件------application.properties和application.yml

    当application.yml 和 application.properties 两个文件同时存在的时候,application.properties的优先级是高于application.yml的, ...

  2. 20190507-学习dubbo有感于梁飞

    “作为一名程序员,BAT肯定是大多数人都想进的,仿佛是一种情愫,就像学生时代的我们对清华北大的向往感觉一样.Dubbo团队中,其中主要负责人就是梁飞了,梁飞的经历还是蛮励志的.梁飞,花名虚极, 200 ...

  3. 19牛客暑期多校 round1 A 有关笛卡尔树的结论

    题目传送门//res tp nowcoder 分析 定理:B1~B2当且仅当B1与B2有同构的笛卡尔树. (B₁~B₂ iff B₁ and B₂ have isomorphic Cartesian ...

  4. Golang Module快速入门

    前言: 在Golang1.11之前的版本中,官方没有提供依赖和包管理工具.开发者通常会使用vendor或者glide的方式来管理依赖(也有直接使用GOPATH多环境方式),而在Golang1.11之后 ...

  5. Go语言Mac、Linux、Windows 下交叉编译

    在很多时候,由于开发的方便,会有这样的场景出现,使用Mac开发或使用Windows开发,需要编译成Linux系统的执行文件,那么如何做到?Go语言提供了非常方便的命令行操作,即可实现. 1.Mac下编 ...

  6. 从入门到自闭之Python--MySQL数据库的单表操作

    单表查询:select * from 表 where 条件 group by 分组 having 过滤 order by 排序 limit n; 语法: select distinct 字段1,字段2 ...

  7. [IOI2005]Riv河流

    题目链接:洛谷,BZOJ 前置知识:莫得 题解 直接考虑dp.首先想法是设状态 \(dp[u][i]\) 表示u的子树内建 \(i\) 个伐木场且子树内木头都运到某个伐木场的最小花费.发现这样的状态是 ...

  8. JavaScript设计模式(策略模式)

    策略模式的定义是:定义一系列的算法,把它们一个个封装起来,并且使它们可以相互替换.将不变的部分和变化的部分隔开是每个设计模式的主题,策略模式也不例外,策略模式的目的就是将算法的使用与算法的实现分离开来 ...

  9. 手把手教你搭建FastDFS集群(中)

    手把手教你搭建FastDFS集群(中) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/u0 ...

  10. 收下这波 JS 技巧,从此少加班

    各种业务开发都离不开对数据的处理,然而遇到的很多数据都是不好处理的.这个时候就需要寻求搜索引擎的帮助.这种方法效率是非常低下的,而且根据作者的个性不能保证其对自己的口味.因此这篇文字包含了一份 JS ...