自己封装了一个取得电脑信息及关机相关操作的类

 
  1. using System;
  2. using System.Management;
  3. using System.IO;
  4. using System.Runtime.InteropServices;
  5. using System.Security.Cryptography;
  6. using System.Text;
  7. using Microsoft.Win32;
  8. namespace WWBClassLib.PC
  9. {
  10.     public class PCTool
  11.     {
  12.         ///   <summary> 
  13.         ///   获取cpu序列号     
  14.         ///   </summary> 
  15.         ///   <returns> string </returns> 
  16.         public static string GetCpuInfo()
  17.         {
  18.             string cpuInfo = " ";
  19.             ManagementClass cimobject = new ManagementClass("Win32_Processor");
  20.             ManagementObjectCollection moc = cimobject.GetInstances();
  21.             foreach (ManagementObject mo in moc)
  22.             {
  23.                 cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
  24.             }
  25.             return cpuInfo.ToString();
  26.         }
  27.         ///   <summary> 
  28.         ///   获取硬盘ID     
  29.         ///   </summary> 
  30.         ///   <returns> string </returns> 
  31.         public static string GetHDid()
  32.         {
  33.             string HDid = " ";
  34.             ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
  35.             ManagementObjectCollection moc1 = cimobject1.GetInstances();
  36.             foreach (ManagementObject mo in moc1)
  37.             {
  38.                 HDid = (string)mo.Properties["Model"].Value;
  39.             }
  40.             return HDid.ToString();
  41.         }
  42.         /// <summary>
  43.         /// 获取网卡Mac地址
  44.         /// </summary>
  45.         /// <returns></returns>
  46.         public static string GetMacAddress()
  47.         {
  48.             System.Management.ManagementObjectSearcher mos = 
  49.                 new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
  50.             foreach (ManagementObject m in mos.Get())
  51.             {
  52.                 if ((bool)m["IPEnabled"])
  53.                 {
  54.                     return m["MACAddress"].ToString();
  55.                 }
  56.             }
  57.             return "";
  58.         }
  59.         /// <summary>
  60.         /// 获取IP地址
  61.         /// </summary>
  62.         /// <returns></returns>
  63.         public static string GetIPAddress()
  64.         {
  65.             string st = "";
  66.             ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
  67.             ManagementObjectCollection moc = mc.GetInstances();
  68.             foreach (ManagementObject mo in moc)
  69.             {
  70.                 if ((bool)mo["IPEnabled"] == true)
  71.                 {
  72.                     //st=mo["IpAddress"].ToString(); 
  73.                     System.Array ar;
  74.                     ar = (System.Array)(mo.Properties["IpAddress"].Value);
  75.                     st = ar.GetValue(0).ToString();
  76.                     break;
  77.                 }
  78.             }
  79.             return st;
  80.         }
  81.         /// <summary>
  82.         /// 获取用户名
  83.         /// </summary>
  84.         /// <returns></returns>
  85.         public static string GetUserName()
  86.         {
  87.             try
  88.             {
  89.                 string st = "";
  90.                 ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
  91.                 ManagementObjectCollection moc = mc.GetInstances();
  92.                 foreach (ManagementObject mo in moc)
  93.                 {
  94.                     st = mo["UserName"].ToString();
  95.                 }
  96.                 moc = null;
  97.                 mc = null;
  98.                 return st;
  99.             }
  100.             catch
  101.             {
  102.                 return "unknow";
  103.             }
  104.             finally
  105.             {
  106.             } 
  107.         }
  108.         /// <summary>
  109.         /// 获取系统类型
  110.         /// </summary>
  111.         /// <returns></returns>
  112.         public static string GetSystemType()
  113.         {
  114.             try
  115.             {
  116.                 string st = "";
  117.                 ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
  118.                 ManagementObjectCollection moc = mc.GetInstances();
  119.                 foreach (ManagementObject mo in moc)
  120.                 {
  121.                     st = mo["SystemType"].ToString();
  122.                 }
  123.                 moc = null;
  124.                 mc = null;
  125.                 return st;
  126.             }
  127.             catch
  128.             {
  129.                 return "unknow";
  130.             }
  131.             finally
  132.             {
  133.             } 
  134.         }
  135.         /// <summary>
  136.         /// 物理内存
  137.         /// </summary>
  138.         /// <returns></returns>
  139.         public static string GetTotalPhysicalMemory()
  140.         {
  141.             try
  142.             {
  143.                 string st = "";
  144.                 ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
  145.                 ManagementObjectCollection moc = mc.GetInstances();
  146.                 foreach (ManagementObject mo in moc)
  147.                 {
  148.                     st = mo["TotalPhysicalMemory"].ToString();
  149.                 }
  150.                 moc = null;
  151.                 mc = null;
  152.                 return st;
  153.             }
  154.             catch
  155.             {
  156.                 return "unknow";
  157.             }
  158.             finally
  159.             {
  160.             } 
  161.         }
  162.         /// <summary>
  163.         /// 获得机器名
  164.         /// </summary>
  165.         /// <returns></returns>
  166.         public static string GetComputerName()
  167.         {
  168.             try
  169.             {
  170.                 return System.Environment.GetEnvironmentVariable("ComputerName");
  171.             }
  172.             catch
  173.             {
  174.                 return "unknow";
  175.             }
  176.             finally
  177.             {
  178.             }
  179.         }
  180.         #region 关机
  181.         [StructLayout(LayoutKind.Sequential, Pack = 1)]
  182.         internal struct TokPriv1Luid
  183.         {
  184.             public int Count;
  185.             public long Luid;
  186.             public int Attr;
  187.         }
  188.         [DllImport("kernel32.dll", ExactSpelling = true)]
  189.         internal static extern IntPtr GetCurrentProcess();
  190.         [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
  191.         internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
  192.         [DllImport("advapi32.dll", SetLastError = true)]
  193.         internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);
  194.         [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
  195.         internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
  196.             ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
  197.         [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  198.         internal static extern bool ExitWindowsEx(int flg, int rea);
  199.         internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
  200.         internal const int TOKEN_QUERY = 0x00000008;
  201.         internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
  202.         internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
  203.         internal const int EWX_LOGOFF = 0x00000000;
  204.         internal const int EWX_SHUTDOWN = 0x00000001;
  205.         internal const int EWX_REBOOT = 0x00000002;
  206.         internal const int EWX_FORCE = 0x00000004;
  207.         internal const int EWX_POWEROFF = 0x00000008;
  208.         /// <summary>
  209.         /// 关机命令
  210.         /// </summary>
  211.         /// <param name="flg">具体参数</param>
  212.         private static void DoExitWin(int flg)
  213.         {
  214.             bool ok;
  215.             TokPriv1Luid tp;
  216.             IntPtr hproc = GetCurrentProcess();
  217.             IntPtr htok = IntPtr.Zero;
  218.             ok = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
  219.             tp.Count = 1;
  220.             tp.Luid = 0;
  221.             tp.Attr = SE_PRIVILEGE_ENABLED;
  222.             ok = LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid);
  223.             ok = AdjustTokenPrivileges(htok, falseref tp, 0, IntPtr.Zero, IntPtr.Zero);
  224.             ok = ExitWindowsEx(flg, 0);
  225.         }
  226.         /// <summary>
  227.         /// 关机
  228.         /// </summary>
  229.         public static void ShutdownPC()
  230.         {
  231.             DoExitWin(EWX_SHUTDOWN);
  232.         }
  233.         /// <summary>
  234.         /// 注销
  235.         /// </summary>
  236.         public static void LogOff()
  237.         {
  238.             DoExitWin(EWX_LOGOFF);
  239.         }
  240.         /// <summary>
  241.         /// 重启
  242.         /// </summary>
  243.         public static void ReBoot()
  244.         {
  245.             DoExitWin(EWX_REBOOT);
  246.         }
  247.         /// <summary>
  248.         /// 关机
  249.         /// </summary>
  250.         public static void PowerOff()
  251.         {
  252.             DoExitWin(EWX_POWEROFF);
  253.         }
  254.         /// <summary>
  255.         /// 强制关机
  256.         /// </summary>
  257.         public static void Force()
  258.         {
  259.             DoExitWin(EWX_FORCE);
  260.         }
  261.         #endregion
  262.     }
  263. }
【3D应力敏感度分析拓扑优化】【基于p-范数全局应力衡量的3D敏感度分析】基于伴随方法的有限元分析和p-范数应力敏感度分析(Matlab代码实现)内容概要:本文档介绍了基于伴随方法的有限元分析与p-范数全局应力衡量的3D应力敏感度分析,并结合拓扑优化技术,提供了完整的Matlab代码实现方案。该方法通过有限元建模计算结构在载荷作用下的应力分布,采用p-范数对全局应力进行有效聚合,避免传统方法中应力约束过多的问题,进而利用伴随法高效求解设计变量对应力的敏感度,为结构优化提供关键梯度信息。整个流程涵盖了从有限元分析、应力评估到敏感度计算的核心环节,适用于复杂三维结构的轻量化与高强度设计。; 适合人群:具备有限元分析基础、拓扑优化背景及Matlab编程能力的研究生、科研人员与工程技术人员,尤其适合从事结构设计、力学仿真与多学科优化的相关从业者; 使用场景及目标:①用于实现高精度三维结构的应力约束拓扑优化;②帮助理解伴随法在敏感度分析中的应用原理与编程实现;③服务于科研复现、论文写作与工程项目中的结构性能提升需求; 阅读建议:建议读者结合有限元理论与优化算法知识,逐步调试Matlab代码,重点关注伴随方程的构建与p-范数的数值处理技巧,以深入掌握方法本质并实现个性化拓展。
下载前必看:https://pan.quark.cn/s/9f13b242f4b9 Android 平板设备远程操控个人计算机的指南 Android 平板设备远程操控个人计算机的指南详细阐述了如何运用 Splashtop Remote 应用程序达成 Android 平板设备对个人计算机的远程操控。 该指南被划分为四个环节:首先,在个人计算机上获取并部署 Splashtop Remote 应用程序,并设定客户端密码;其次,在 Android 平板设备上获取并部署 Splashtop Remote 应用程序,并与之建立连接至个人计算机的通道;再次,在 Splashtop Remote 应用程序中识别已部署个人计算机端软件的设备;最后,运用平板设备对个人计算机实施远程操控。 关键点1:Splashtop Remote 应用程序的部署与配置* 在个人计算机上获取并部署 Splashtop Remote 应用程序,可通过官方网站或其他获取途径进行下载。 * 部署结束后,必须输入客户端密码,该密码在平板控制计算机时用作验证,密码长度至少为8个字符,且需包含字母与数字。 * 在配置选项中,能够设定是否在设备启动时自动运行客户端,以及进行互联网搜索设置。 关键点2:Splashtop Remote 应用程序的 Android 版本获取与部署* 在 Android 平板设备上获取并部署 Splashtop Remote 应用程序,可通过 Google Play Store 或其他获取途径进行下载。 * 部署结束后,必须输入客户端密码,该密码用于连接至个人计算机端软件。 关键点3:运用 Splashtop Remote 远程操控个人计算机* 在 Splashtop Remote 应用程序中识别...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值