wmi

Unit testing with network-reliant code

孤者浪人 提交于 2019-12-20 12:38:35
问题 I'm trying to be better about unit testing my code, but right now I'm writing a lot of code that deals with remote systems. SNMP, WMI, that sort of thing. With most classes I can mock up objects to test them, but how do you deal with unit testing a real system? For example, if my class goes out and gets the Win32_LogicalDisk object for a server, how could I possibly unit test it? 回答1: Assuming you meant "How do I test against things that are hard/impossible to mock": If you have a class that

Determine operating system and processor type in C#

风流意气都作罢 提交于 2019-12-20 12:25:59
问题 I want to check what type of operating system i use and what kind of processor. this should be check on run time. i tried using System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") and System.OperatingSystem osInfo2 = System.Environment.OSVersion; Console.WriteLine(osInfo2.ToString()); but it's just the enviroment that VS is running on. I was told to use WMI to check it but i can't find out how. can someone help me with that? 回答1: Yes WMI is the best way to do this kind of

Network Authentication when running exe from WMI

那年仲夏 提交于 2019-12-20 10:37:38
问题 I have a C# exe that needs to be run using WMI and access a network share. However, when I access the share I get an UnauthorizedAccessException. If I run the exe directly the share is accessible. I am using the same user account in both cases. There are two parts to my application, a GUI client that runs on a local PC and a backend process that runs on a remote PC. When the client needs to connect to the backend it first launches the remote process using WMI (code reproduced below). The

how to hook to events / messages in windows using python

爷,独闯天下 提交于 2019-12-20 10:24:30
问题 in short: i want to intercept suspend/standby messages on my laptop, but my program doesn't receives all relevant messages. background: there's a bug in ms-excel on windows xp/2k, which prevents system suspend if a file is opened on a network/usb drive. i'm trying to work-around it programmatically (my toolbox include python, vb6, or command line tools). i know nothing about windows instrumentation :-) i have a sysinternals utility that suspends the system anyhow. i want to hook it to the

How do I detect a disabled Network Interface Connection from a Windows application?

蹲街弑〆低调 提交于 2019-12-20 09:56:01
问题 I would like to know when a interface has been disabled. If I go into the windows manager and disable one of the 2 enabled connections, GetIfTable() only returns status about 1 interface, it no longer sees the disconnected one. (Returns 1 table) How can I get something to return that the disabled interface still exists but is currently disabled? Thanks. http://msdn.microsoft.com/en-us/library/aa365943%28VS.85%29.aspx 回答1: I think you would just need to read the registry. For example, this is

Creating a shadow copy using the “Backup” context in a PowerShell

只谈情不闲聊 提交于 2019-12-20 09:47:43
问题 I am in the process of writing a PowerShell script for backing up a windows computer using rsync. To this end, I am attempting to use WMI from said script to create a non-persistent Shadow copy with writer participation (as is apparently recommended for backups). I found out from another question (Accessing Volume Shadow Copy (VSS) Snapshots from powershell) a way to create a shadow copy in general, but the example given there uses "ClientAccessible" as the context parameter, which result in

Find USB drive letter from VID/PID (Needed for XP and higher)

混江龙づ霸主 提交于 2019-12-20 09:37:28
问题 So I thought I would include the final answer here so you don't have to make sense of this post. Big thanks to Simon Mourier for taking the time to figure this one out. MY WORKING CODE try { //Get a list of available devices attached to the USB hub List<string> disks = new List<string>(); var usbDevices = GetUSBDevices(); //Enumerate the USB devices to see if any have specific VID/PID foreach (var usbDevice in usbDevices) { if (usbDevice.DeviceID.Contains(USB_PID) && usbDevice.DeviceID

C# Find specific slot no of the USB Hub(10 slots) where USB is connected or not. I want to get the specific slot no where USB is connected or not

孤者浪人 提交于 2019-12-20 06:19:24
问题 C# I have a USB Hub of 10 USB slots connected to my USB Port. I want to get the USB device connected to the specific port. Example: Two USB's are connected at Slot 3 and Slot 7. So, I want a list which will show Slot 3 and Slot 7 have USB and rest slot are empty. I have tried using WMI Query Win32_USBHub. But here I am only getting 6 device id's and not 10. I am differentiating the ports using common VID for the Device ID. But still even after getting the USB's connected to the specific port.

Read/Write Remote File using WMI C#

江枫思渺然 提交于 2019-12-20 05:45:41
问题 I need to read and write(update) some remote machine file.I am able to find the remote file using WMI(System.Management) but not able to do read or updation on that. Any help would be appreciated. Thanks Himanshu 回答1: The WMI doesn't have any class (or method) to read or write the content of files. Only you can retrieve the metadata (FileName, Date, Size) of the files using the CIM_DataFile or you can do tasks like Copy, Rename, Delete or Compress files. 回答2: First check your file access in

Uninstalling using Get-WmiObject

半城伤御伤魂 提交于 2019-12-20 05:16:17
问题 I'm trying to run a PowerShell command in a batch script. Im trying to remove all traces of an old RMM tool from client PCs and for the life of me can't get this line to run correctly. The idea is that this searches for software that has N-Able in the vendor name and passes the GUID to the $nableguid variable and then msiexec.exe against the GUIDs found above. PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {$nableguid = (Get -WmiObject Win32_Product -Filter "vendor LIKE '%N-able%'"