How to get remote operating system version in .Net without WMI?

Is there a way to get the version of the operating system on a remote computer in .Net (C #)? Using WMI is unacceptable to me.

I have the IP address of the remote machine :) and administrator credentials

+4
source share
4 answers

based on sgmoore answer with some posts

public string GetOsVersion(string ipAddress) { using (var reg = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, ipAddress)) using (var key = reg.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\")) { return string.Format("Name:{0}, Version:{1}", key.GetValue("ProductName"), key.GetValue("CurrentVersion")); } } 
+8
source

If you have administrator credentials for the remote machine, you can use PsExec to remotely run the command to get the OS version, for example.

Cmd / c ver

You can write a shell to run PsExec in C # using the Process class.

+2
source

Providing remote access to the registry,

  var reg = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, ipaddress); var key = reg.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\"); string version = (string) key.GetValue("CurrentVersion"); reg.Close(); 
+1
source

Can use pinvoke

[DllImport("Netapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetServerGetInfo(string serverName, int level, out IntPtr serverInfo);

See http://www.pinvoke.net/default.aspx/netapi32/netservergetinfo.html for type sorting and http://msdn.microsoft.com/en-us/library/windows/desktop/aa370624(v=vs .85) .aspx to use

0
source

Source: https://habr.com/ru/post/1335427/


All Articles