Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get remote machine OS version in .Net, without WMI?

Tags:

c#

.net

Is there any way to get OS version of remote machine in .Net(C#)? Using of WMI is not acceptable for me.

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

like image 501
vasyl Avatar asked Dec 13 '22 16:12

vasyl


2 Answers

based on sgmoore answer with some usings

    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"));
        }
    }
like image 149
Simon Avatar answered Dec 15 '22 06:12

Simon


If you have administrator credentials for the remote machine you could use PsExec to run a command remotely to get the OS version e.g.

CMD /c ver

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

like image 25
Tim Lloyd Avatar answered Dec 15 '22 05:12

Tim Lloyd