system.management

Running powershell in VB.NET - how to access the content of my variable

不想你离开。 提交于 2021-02-11 12:38:04
问题 I am running a simple script in VB using System.Management.Automation as below Script runs fine, but how do I then access content of $offline and $online in my code after it has run? Dim scriptContents = New StringBuilder() scriptContents.AppendLine("$computers = @(""PC-1"", ""PC-2"", ""PC-3"")") scriptContents.AppendLine("$online = @()") scriptContents.AppendLine("$offline = @()") scriptContents.AppendLine("Foreach ($computer in $computers) {") scriptContents.AppendLine("If (Test-Connection

Reference to type 'Component' claims it is defined in 'System'

≡放荡痞女 提交于 2020-02-01 05:35:06
问题 Trying to get some WMI objects in a UWP application. Running VS2015 on .net 4.6. I'm getting errors for the ForEach and method calls stating "Reference to type 'Component' claims it is defined in 'System'" with error CS7069. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Management; namespace SystemInfo { class wmiObject { static osDetails Program() { ManagementObjectCollection osDetailsCollection = getWMIObject

System.Management.ManagementException

社会主义新天地 提交于 2019-12-30 06:40:14
问题 I am running following code: System.Management.ManagementClass wmiNetAdapterConfiguration = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration"); System.Management.ManagementObjectCollection wmiNetAdapters = wmiNetAdapterConfiguration.GetInstances(); Log.logInfo("Net adapters:" + wmiNetAdapters.get_Count()); And on some machines it is ok, and on some I am getting following error: System.Management.ManagementException: Not found Call stack: System.Management

Map a DiskIndex to a Volume Label

自闭症网瘾萝莉.ら 提交于 2019-12-11 07:53:57
问题 Current I am able to get all the Drives and their labels in c# by using the DriveInfo.GetDrives(). Then I am able to get the Disk Index / Index of the Partition by this methodology. var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskPartition"); foreach (var queryObj in searcher.Get()) { Console.WriteLine("-----------------------------------"); Console.WriteLine("Win32_DiskPartition instance"); Console.WriteLine("Name:{0}", (string)queryObj["Name"]); Console

Running Dot Net project exe on Linux which makes use of System.Management to get USB Device information

早过忘川 提交于 2019-12-11 04:23:56
问题 Hi, I have created a Dot Net application in C# to get USB Device Information like DeviceID, Caption, ClassGUID etc using System.Management Namespace. I'm using the ManagementObjectSearcher Method to fetch the value from Win32_DiskDrive. It's running fine on Windows. I want to run it on Linux machine. You can run Dot Net applications on Linux machine using Mono. http://mono-project.com/Main_Page When i run my application's exe on Linux using Mono i get the following error: Missing method .ctor

Using System.Drawing.Printing to get Queue Status

荒凉一梦 提交于 2019-12-11 02:44:57
问题 I've been trying to use System.Drawing.Printing; in order to get the queue status of a network printer. I can retrieve the properties of the printer but I can't really seem to get the queue status. This is what I've tried so far: PrinterSettings ps = new PrinterSettings(); ps.PrinterName = "ES5461 MFP(PCL)"; // Load the appropriate printer's setting From there I can see that the Printer is valid since ps.IsValid is true but I can't go any further. I've tried as well to use System.Management

C# System.Management.Automation.Powershell class leaking memory on Invoke() call

强颜欢笑 提交于 2019-12-10 17:55:45
问题 I have code for a C# test app that queries system info using PowerShell, and in it I have a few simple functions like the following: public void GetSystemInfo() { using (PowerShell ps = PowerShell.Create()) { ps.AddCommand("Get-Disk"); // Get-Disk is an example; this varies foreach (PSObject result in ps.Invoke()) { // ... // Do work here. Process results, etc... // ... } } } This is straightforward and mostly taken from MSDN examples, like here: https://msdn.microsoft.com/en-us/library

System.Management.ManagementException

ぃ、小莉子 提交于 2019-12-04 06:29:39
I am running following code: System.Management.ManagementClass wmiNetAdapterConfiguration = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration"); System.Management.ManagementObjectCollection wmiNetAdapters = wmiNetAdapterConfiguration.GetInstances(); Log.logInfo("Net adapters:" + wmiNetAdapters.get_Count()); And on some machines it is ok, and on some I am getting following error: System.Management.ManagementException: Not found Call stack: System.Management.ManagementException: Not found at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus

Create PSCredential without a password

此生再无相见时 提交于 2019-11-29 09:07:29
How to create a instance in PSCredential that has no password? Things I tried: $mycreds = New-Object System.Management.Automation.PSCredential ("username", $null) Error: Cannot process argument because the value of argument "password" is null $mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString $null -AsPlainText -Force)) Error: ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null. $mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "" -AsPlainText -Force)) Error: