wmi

How to get the drive letter of USB device using WMI

烂漫一生 提交于 2020-04-08 07:44:56
问题 I need to track the USB insertion and removal events from the C# application so I came up with the following ideas based on the other questions on SO. I can't use this method var drives = DriveInfo.GetDrives() .Where(drive => drive.IsReady && drive.DriveType == DriveType.Removable).ToList(); because it can lead to a lot of troubles when you need to differentiate between connected and disconnected devices (the new ones can have the same drive letter and name like the ones that was previously

How to get the drive letter of USB device using WMI

跟風遠走 提交于 2020-04-08 07:39:02
问题 I need to track the USB insertion and removal events from the C# application so I came up with the following ideas based on the other questions on SO. I can't use this method var drives = DriveInfo.GetDrives() .Where(drive => drive.IsReady && drive.DriveType == DriveType.Removable).ToList(); because it can lead to a lot of troubles when you need to differentiate between connected and disconnected devices (the new ones can have the same drive letter and name like the ones that was previously

Windows开启WMI时一些总结

▼魔方 西西 提交于 2020-04-04 06:09:50
  通过远程的方式连接WMI获取计算机信息时,可能会出现远程主机拒绝访问,这时就要通过下面的方式来开启当前计算机的WMI服务,下面以Win7和Win10为例来进行相关的说明,通过一步步排查去连接远程服务。 一 在本机测试是否可以连接远程主机WMI服务   1 按下Windows+R组合键,调用系统运行窗口。   2 输入wbemtest命令。 图1 调用WMI测试器   3 打开WMI测试器。 图2 打开WMI测试器   4 连接远程WMI服务   连接WMI服务时需要进行下面的步骤。   4.1 首先输入命名空间。   4.2 输入用户名和密码。 4.3 点击“连接” 4.4 查看连接状况 图3 连接远程WMI服务 图4 连接成功标志   如果连接不成功,可能出现下面的对话框,请按照下面的提示来进行一步步排查。 图5 访问失败   二 开启远程计算机WMI服务(下面的说明以Windows10为例)     1 查看计算机是否开启WMI服务 图5 查看WMI服务是否开启     2 查看是否启动远程服务。    依次打开计算机管理=》WMI控件=》更多操作=》属性 图6 设置远程主机的WMI属性 登录之后,设置WMI控件的属性,进入安全选项卡,然后设置Root\CIMV2安全设置,然后查看当前的组是否设置远程启用的权限,特别是查看Authenticated Users是否启用远程

Python wmi Cookbook 中文翻译

元气小坏坏 提交于 2020-03-24 07:42:32
3 月,跳不动了?>>> 简介: 本文所有的例均是假设你在使用来自 http://timgolden.me.uk/python/wmi/cookbook.html 的WMI模块。使用此模块,你可以在Windows系统中去体验下面这些实用的例子。或许你将由此了解到WMI的冰山一角。 下面这些例子,除非有特别说明,均假设你要连接的是当前的机器。如果要连接远程机器,只需要在WMI构造器中指定远程机器名即可: import wmi c = wmi.WMI("some_other_machine") 注:这都是些完整的例子,你可以直接复制粘贴到一个.py文件里面,也可以复制粘贴到Python命令行交互窗口(原文作者是在Windows2000系统的CMD窗口做的测试)。 实例: 列出所有正在运行的进程 import wmi c = wmi.WMI() for process in c.Win32_Process(): print process.ProcessId, process.Name 列出所有正在运行的记事本进程 import wmi c = wmi.WMI() for process in c.Win32_Process(name="notepad.exe"): print process.ProcessId, process.Name 创建一个新的记事本进程然后结束它 import

Python 利用WMI监控windows状态如CPU、内存、硬盘

孤人 提交于 2020-03-24 07:37:43
3 月,跳不动了?>>> Python 利用WMI监控windows状态如CPU、内存、硬盘 安装pywin32库 下载地址: https://sourceforge.net/projects/pywin32/files%2Fpywin32/ 选择对应python版本的文件。 下载后在windows安装好。 安装wmi库 下载地址: https://pypi.python.org/pypi/WMI/#downloads 下载后在windows安装好。 测试安装结果 import win32api import wmi 如果没有报错就是安装好了。 查询可用类 import wmi myWmi= wmi.WMI() for cls in myWmi.classes: print(cls) # 可以显示如下的可用类(省略),常用; Win32_Processor 查CPU Win32_ComputerSystem 查内存 Win32_LogicalDisk 查硬盘 查询CPU信息 从上面的可用类,有一个Win32_Processor cpuArr = myWmi.Win32_Processor() 查出来之后,它有哪些属性可用?比方说,cpu的名字,几核? 这时候要到MSDN查WMI资料,地址: https://msdn.microsoft.com/en-us/library

Why does WMI work through a search but not directly?

半世苍凉 提交于 2020-03-05 05:42:05
问题 The first of these 2 locks a BitLocked drive. The 2nd's InvokeMethod throws: 'Invalid object path'. Why? They seem equivalent. //Using a search: ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2\\Security\\MicrosoftVolumeEncryption", "SELECT * FROM Win32_EncryptableVolume WHERE DriveLetter = 'E:'"); foreach (ManagementObject classInstance1 in searcher.Get()) classInstance1.InvokeMethod("Lock", new object[] { true }); //Direct: ManagementObject classInstance2 = new

WMI获取硬件信息

℡╲_俬逩灬. 提交于 2020-03-02 16:57:58
// 硬件 Win32_Processor, // CPU 处理器 Win32_PhysicalMemory, // 物理内存条 Win32_Keyboard, // 键盘 Win32_PointingDevice, // 点输入设备,包括鼠标。 Win32_FloppyDrive, // 软盘驱动器 Win32_DiskDrive, // 硬盘驱动器 Win32_CDROMDrive, // 光盘驱动器 Win32_BaseBoard, // 主板 Win32_BIOS, // BIOS 芯片 Win32_ParallelPort, // 并口 Win32_SerialPort, // 串口 Win32_SerialPortConfiguration, // 串口配置 Win32_SoundDevice, // 多媒体设置,一般指声卡。 Win32_SystemSlot, // 主板插槽 (ISA & PCI & AGP) Win32_USBController, // USB 控制器 Win32_NetworkAdapter, // 网络适配器 Win32_NetworkAdapterConfiguration, // 网络适配器设置 Win32_Printer, // 打印机 Win32_PrinterConfiguration, // 打印机设置 Win32

WMI获取磁盘信息

对着背影说爱祢 提交于 2020-03-02 16:53:37
  这段时间写有关获取磁盘信息的demo,通过WMI能实现 磁盘驱动器的信息读取(Win32_DiskDrive class) 和 逻辑分区的信息读取(Win32_LogicalDisk class)。如何在显示物理驱动器时也能同时显示下属分区的信息?我从一个博客中找到了答案: 代码 private void GetAllDisk1() { foreach (ManagementObject drive in new ManagementObjectSearcher( " select * from Win32_DiskDrive " ).Get()) { // associate physical disks with partitions string type = drive[ " Caption " ].ToString(); foreach (ManagementObject partition in new ManagementObjectSearcher( " ASSOCIATORS OF {Win32_DiskDrive.DeviceID=' " + drive[ " DeviceID " ] + " '} WHERE AssocClass = Win32_DiskDriveToDiskPartition " ).Get()) { Console.WriteLine

WMI信息获取

。_饼干妹妹 提交于 2020-03-02 16:49:26
<html><head><title>WMI信息获取——请将本站点加入到可信站点</title></head><body><p align=center>List: <input type=button value="NetworkAdapter" onclick="vbscript:DoListNetworkAdapter"><input type=button value="NetworkAdapterCfg" onclick="vbscript:DoListNetworkAdapterCfg"><input type=button value="Computer" onclick="vbscript:DoListComputer"><input type=button value="Disk" onclick="vbscript:DoListDisk"><input type=button value="System" onclick="vbscript:DoListSystem"><input type=button value="CPU" onclick="vbscript:DoListCPU"><input type=button value="Memory" onclick="vbscript:DoListMemory"><input type=button

How do I query for USB devices not listed in USB Root Hub

萝らか妹 提交于 2020-02-28 07:59:11
问题 Query which works for some devices found in Win32_USBHub SELECT * FROM Win32_USBHub WHERE DeviceID = '{0}' Here's the code context, // Check if USB device is plugged in string deviceQuery = String.Format("SELECT * FROM Win32_USBHub WHERE DeviceID = '{0}'", deviceID); using (var searcher = new System.Management.ManagementObjectSearcher(deviceQuery)) if (searcher.Get().Count == 0) MessageBox.Show(@"Device not detected"); However when a device is not listed inside 'Universal Serial Bus