Remote API(RAPI)之 系统信息

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 = 2000;//异步连接设备超时时间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 == 1)
            {
                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(0)]
            public int cbsize;
            [FieldOffset(4)]
            public readonly IntPtr heRapiInit;
            [FieldOffset(8)]
            private readonly IntPtr hrRapiInit;
        }

        //处理器架构CeGetSystemInfo
        public enum ProcessorArchitecture : short
        {
            Intel=0,
            MIPS=1,
            Alpha=2,
            PPC=3,
            SHX=4,
            ARM=5,
            IA64=6,
            Alpha64=7,
            Unknown=-1
        }

        //移动设备内存信息
        [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=3
        }

        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 = 386,  //386
            PROCESSOR_INTEL_486 = 486,  //486
            PROCESSOR_INTEL_PENTIUM = 586,   //Pentium
            PROCESSOR_INTEL_PENTIUMII = 686,  //P2
            PROCESSOR_INTEL_IA64 = 2200,  //IA 64
            PROCESSOR_MIPS_R4000 = 4000,  //MIS 4000 series
            PROCESSOR_ALPHA_21064 = 21064,  //Alpha 21064
            PROCESSOR_PPC_403 = 403,  //PowerPC 403
            PROCESSOR_PPC_601 = 601,  //PowerPC 601
            PROCESSOR_PPC_603 = 603,  //PowerPC 603
            PROCESSOR_PPC_604 = 604,  //PowerPC 604
            PROCESSOR_PPC_620 = 620,  //PowerPC 620
            PROCESSOR_HITACHI_SH3 = 10003,  // Hitachi SH3
            PROCESSOR_HITACHI_SH3E = 10004,  // Hitachi SH3E
            PROCESSOR_HITACHI_SH4 = 10005,  //Hitachi SH4
            PROCESSOR_MOTOROLA_821 = 821,  //Motorola 821
            PROCESSOR_SHx_SH3 = 103,  //Hitachi SH3
            PROCESSOR_SHx_SH4 = 104,  //Hitachi SH4
            PROCESSOR_STRONGARM = 2577,  //Intel StrongARM
            PROCESSOR_ARM720 = 1824,  //ARM720
            PROCESSOR_ARM820 = 2080,  //ARM820
            PROCESSOR_ARM920 = 2336,  //ARM920
            PROCESSOR_ARM_7TDMI = 70001  //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
时间: 2024-10-29 10:46:33

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

docker 开启remote api

docker官方文档上有相关说明(Configure and run Docker on various distributions),ubuntu上是可行的 sudo vi /etc/default/docker DOCKER_OPTS="-H tcp://0.0.0.0:2375" 参考一 Ubuntu14.04使用参考一推荐的方法开启remote api没有成功 参考二 使用参考二的方法开启remote api成功了

借助Sigar API获取操作系统信息

Sigar(全称System Information Gatherer And Reporter,即系统信息收集报表器),它提供了一个开源的跨平台的收集计算机硬件和操作系统信息的API(该API底层接口用C语言编写),本文将演示如何借助Sigar API获取操作系统信息: package com.ghj.packageoftest; import java.net.InetAddress; import org.hyperic.sigar.OperatingSystem; import org.

关于docker rest api接口组件docker remote api的使用

前提: docker remote api 是docker自带的一个rest api 管理. 只要在配置文件里面申明下就可以了. 下面是docker remote api的官方的功能目录: Docker Remote API v1.3 3.1 Inside 'docker run' 3.2 Hijacking 3.3 CORS Requests 2.1 Containers 2.2 Images 2.3 Misc List containers Create a container Inspec

[开源夏令营][四] Docker remote API 之 镜像篇

列出镜像 列出镜像,有两个可选參数,一个是all,一个是filter,all可选值有,0/False/false,1/True/true,默觉得0:filter是一个包括一个过滤对象的json,形式如'{"dangling":["true"]}' GET /images/json 我们能够尝试请求一下 curl -s -XGET theegg.me/docker/images/json?all=0 | python -mjson.tool 能够看到例如以下的返回值:

Docker 1 12新功能探索(8) Remote Api 1 24

Docker的Remote Api并不是1.12才有的,Docker1.12的Remote Api升到了1.24.Remote api的使用在1.12中没有大的变化,稍微大一点的变化是到这个版本之后,二进制文件分裂成了主client的docker以及主server的dockerd了.在centos上通过systemd的配置变化不大,无非是将tcp://ip:port设定到启动的Option中而已,下面来看一下如何设定和简单使用. 事前确认 可以看到只有unix socket的方式 [[email

docker remote api

使用三种方式实现从docker hub 下载镜像,并推送到私有仓库 Docke client docker pull nginx docker tag nginx opshar.xxxx.com/app/nginx docker login opshar.xxxx.com docker push opshar.xxxx.com/app/nginx python sdk首先下载pip install docker #!/usr/bin/pythonimport sys, json, docker.

Docker开启Remote API 访问 2375端口

Docker常见端口 我看到的常见docker端口包括: 2375:未加密的docker socket,远程root无密码访问主机2376:tls加密套接字,很可能这是您的CI服务器4243端口作为https 443端口的修改2377:群集模式套接字,适用于群集管理器,不适用于docker客户端5000:docker注册服务4789和7946:覆盖网络 开启配置 方法一 首先是怎么配置远程访问的API: sudo vim /etc/default/docker 加入下面一行 DOCKER_OPT

docker remote api 的安全隐患

开启docker的api,首先要知道docker的守护进程daemon,在下认为daemon作为Client和service连接的一个桥梁,负责代替将client的请求传递给service端. 默认情况daemon只由root控制,但我们可以通过-H绑定到端口上,这样通过端口访问的方式执行命令. 我用的是Ubuntu17的虚拟机+docker17.03.0-ce,网上介绍两种方法 1.  直接执行 docker -d -H unix:///var/run/docker.sock -H 0.0.0

Centos 7 Docker配置secure remote api

log查看: sudo journalctl -fu docker.service 证书生成参考: https://docs.docker.com/engine/security/https/ vi /lib/systemd/system/docker.service: [Unit]Description=Docker Application Container EngineDocumentation=https://docs.docker.comAfter=network.target doc