wmi

Detecting USB drive insertion and removal using windows service and c#

谁说胖子不能爱 提交于 2019-12-16 22:37:02
问题 Looking into possibility of making an USB distributed application that will autostart on insertion of an USB stick and shutdown when removing the stick Will use .Net and C#. Looking for suggestion how to approach this using C#? Update: Two possible solutions implementing this as a service. - override WndProc or - using WMI query with ManagementEventWatcher 回答1: You can use WMI, it is easy and it works a lot better than WndProc solution with services. Here is a simple example: using System

VBScript using WMI to find out SQL Server version

家住魔仙堡 提交于 2019-12-14 04:24:16
问题 Can anyone point me to a vbscript (using WMI) to find out the installed SQL Server version. I have a scenario where either SQL Server 2008 R2 or SQL Server 2012 could be installed on a machine. 回答1: Based on the code in the first Google search result here: Dim WMI, Col, Prod, Q Set WMI = GetObject("WinMgmts:") Q = "Select * FROM Win32_Product WHERE Vendor = " & _ "'Microsoft Corporation' AND Name LIKE 'SQL Server%Database Engine Services'" Set Col = WMI.ExecQuery(Q) For Each Prod in Col if

How to programatically enable System Restore monitoring for a drive? [closed]

∥☆過路亽.° 提交于 2019-12-14 04:13:25
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I found a code that enables System Restore monitoring, but it's for C# and I need to convert it to Delphi. Here's the code: ManagementScope scope = new

Periodical WMI Query Causes Memory Leak?

爱⌒轻易说出口 提交于 2019-12-14 03:50:51
问题 I am fairly new to the .NET programming and I am currently developing a computer health monitoring system which is in its infant stage now. I will be using C# 2010 and querying computer information by using WMI queries. Before I could further develop the application, I have created a mini test app to test out my classes and its methods. The flow of the test app is as follow: App startup Input hostname, username and password Query button clicked and the querying methods fired. A textfield on

Is it necessary to dispose every ManagementObject?

耗尽温柔 提交于 2019-12-14 03:46:57
问题 I noticed that ManagementObject is IDisposable , but it's also returned from ManagementClass.GetInstances() and ManagementObjectSearcher.Get() , does this mean I need to dispose each object encountered? Like so: ManagementObject ret; foreach(ManagementObject mo in searcher.Get()) { if( IsWhatIWant(mo) ) ret = mo; else mo.Dispose(); } Further confounding this: there's a bug in ManagementBaseObject where it does not correctly implement IDisposable (See Using clause fails to call Dispose? ) so

How could I get or change the IP address of a disconnected NIC in Windows?

僤鯓⒐⒋嵵緔 提交于 2019-12-14 02:22:37
问题 I have configured the IP address for a NIC successfully in Windows7. But after pulling out the net cable, I can't get the IP address from API and ipconfig, but I can view it in "Network Connections". And if I insert the cable again, then I can get the address once more. How could I get or change the IP address of a NIC, when the NIC is disconnected? I have used "GetAdaptersInfo" "GetIpAddrTable" or WMI class. All above method return 0.0.0.0 ipaddress for such NIC. My platform is Windows7, and

WMI Performance counter Query issues

懵懂的女人 提交于 2019-12-14 02:17:48
问题 Is there a way to query via WMI in C# like you can do with the System.Diagnostics.PerformanceCounter class? Simply put how can I pass it a string like \\localhost\Processor(0)\% Processor Time and it would build the correct WMI query for me? I have huge list of counters in a flat file from a legacy program and I want to move it to a Service which just runs through the flat file and gets the value. 回答1: You can use the WMI Performance Class Counters. An example of this would be polling the

Cant access PerfRawData or PerfFormattedData

浪子不回头ぞ 提交于 2019-12-14 00:41:35
问题 The Win32_PerfFormattedData_* and Win32_PerfRawData_* classes are missing from my system. I'm running Windows 7, 64-bit, and using WMICodeCreator to browse the available classes. Neither WMICodeCreator nor my C# code can get information from them, and I have not been able to find any discussion boards talking about this particular issue. All other WMI classes are working perfectly fine. Could it be a service that I haven't started? 回答1: Start the perfmon to see if counters are present. If you

How to access hidden partitions/volumes

戏子无情 提交于 2019-12-14 00:26:09
问题 I have to write a code to access hidden disk partitions/volumes using c# or c++. But could not find any help reference on the matter. As a hidden volume, it does not contain a "Disk Letter", so you can´t just type "C:\" and access it. A example would be the "recovery partition" that comes with Windows. You can´t see it on explorer but it is there. My application will write and read data from thoose partitions and I have to find a way of doing something like "c:\" for thoose. In the above

Wait for service.InvokeMethod to finish - WMI, C#

蹲街弑〆低调 提交于 2019-12-13 20:29:35
问题 i'm stoppinga service on remote machine with WMI: protected override void Execute() { ConnectionOptions connectoptions = new ConnectionOptions(); connectoptions.Username = RemoteMachineUsername; connectoptions.Password = RemoteMachinePassword; ManagementScope scope = new ManagementScope(@"\\" + RemoteMachineName + @"\root\cimv2"); scope.Options = connectoptions; SelectQuery query = new SelectQuery("select * from Win32_Service where name = '" + ServiceName + "'"); using