0

I am new to C# and one of my intentions in my program is to know a remote machine system architecture. I found this command:

System.Environment.Is64BitOperatingSystem

that essentially gets the value of the environment property, but this only on the local machine i am developing from.

Is there a way to run this commnad, or any other command remotely?

Or, I know how to do that in PowerShell, by querying with Get-WMIObject with -ComputerName Parameter that gives my the option the query WMI remotely. So maybe there another simple way to do that also in C#?

Thank you

UPDATE: I used that link: https://learn.microsoft.com/en-us/windows/desktop/wmisdk/connecting-to-wmi-remotely-with-c- what Alex gave me, and in the article I need to use the assembly:

Microsoft.Management.Infrastructure

But I just can't reference it, or find it in my computer... The microsoft article doesn't say anything about that assembly where I can find it.

Lior
  • 139
  • 2
  • 13
  • 2
    with c# you also query WMI – enno.void Dec 19 '18 at 12:14
  • 1
    [Connecting to WMI Remotely with C#](https://learn.microsoft.com/en-us/windows/desktop/wmisdk/connecting-to-wmi-remotely-with-c-) – Alex K. Dec 19 '18 at 12:20
  • See: [Win32_OperatingSystem](https://learn.microsoft.com/en-us/windows/desktop/cimwin32prov/win32-operatingsystem). Often combined with [Win32_ComputerSystem](https://learn.microsoft.com/en-us/windows/desktop/cimwin32prov/win32-computersystem) (useful to *extract* UserName / Domain / WorkGroup of a machine). See [here](https://stackoverflow.com/questions/49118708/get-serial-number-of-usb-storage-device-in-net-core-2-1?answertab=active#tab-top) (at the bottom of the code section) how to setup the WMI ConnectionOptions for authentication – Jimi Dec 19 '18 at 12:25
  • @AlexK. For some reason I cannot reference the Microsoft.Management.Infrastructrue assembly. I also cannot reference it. after searching online, no answer on where to download it :( – Lior Dec 19 '18 at 15:44
  • [Microsoft.Management.Infrastructure - NuGet](https://www.nuget.org/packages/Microsoft.Management.Infrastructure/). You should use it for monitoring purposes. If you just need to test a machine's system *bitness*, `System.Management` gives the same results. – Jimi Dec 19 '18 at 17:05

1 Answers1

0

I recommend you use PowerShell to run remote command since it's very common used . you can do it run it something like this :

Invoke-Command -ComputerName Server01, Server02 -FilePath c:\Scripts\yourPowerShellScript.ps1

You can run powershell scripts from c# as we can see here https://blogs.msdn.microsoft.com/kebab/2014/04/28/executing-powershell-scripts-from-c/

you can find more information in https://learn.microsoft.com/es-es/powershell/scripting/learn/remoting/running-remote-commands?view=powershell-6

jecaestevez
  • 119
  • 1
  • 3