How to get Operating System Info in .net
B'mark-it! Http://www.vbcity.com/forums/faq.asp?fid=30&cat=systemtid4878
- posted by jspano - Last Updated on 7/28/2003 4:11:03 AM 1 Comment (s) [Read Comments]
- URL - http://www.vbcity.com/forums/faq.asp?tid=4878
In vs.net it is easy to get operation system info for c # code:
// Get the Operating System from Environment Class
Operatingsystem OS = Environment.osversion;
// Get the Version Information
Version Ver = Os.Version;
Console.writeLine (Ver.major);
Console.writeline (Ver.minor);
Console.WriteLine (Ver.Revision);
Console.WriteLine (Ver.Build);
// Get Platform Info
Console.writeLine (Os.Platform);
For VB.Net Code:
DIM OS as OPERATISTEM
OS = environment.osversion
DIM VER AS VERSION
Ver = os.version
'Get the version info
Console.writeline (Ver.major)
Console.writeline (Ver.minor)
Console.writeLine (Ver.Revision)
Console.writeline (Ver.Build)
'Get the Platform
Console.writeline (Os.Platform.toString)
THE OUTPUT for A Windows 2000 Pro Computer: 5 0 0 2195 Win32NT
Get operating system version information
http://dotnet.aspx.cc/showdetail.aspx?id=6977hlmy-elpn-4kir-bi89-7ys2lnent5hr
Msgbox (Environment.OSVersion.toString)
The System.Net Namespace of the NET Framework class library provides a simple network programming interface. The DNS class provides a simple domain name resolution function. It is a static class that can be used by Internet Domain Name System (DNS). The host information obtained by the DNS query is an instance of an IPHOSTENTRY class. If the specified host has more than one Entry in the DNS database, the iPhostentry will contain multiple addresses and their alias. The following code achieves the functions of all IPs of the machine.
http://dotnet.aspx.cc/showdetail.aspx?id=d5e84294-21ac-4815-579f-7f8786a31b3d
Getting started with WMI scripts: Part III
http://www.microsoft.com/china/msdn/library/enterprisedevelopment/softwareDev/wddnclinicscripting3.mspx What is WMI? WMI was initially issued as an additional component as an additional component in 1998, which is built in the core management support technology in Windows 2000, Windows XP, and Windows Server 2003 Series operating systems. Based on the industry standard supervised by Distributed Management Task Force (DMTF), WMI is a normative and infrastructure that can be accessed, configured, managed, and monitors all - almost all Windows resources. To master the powerful features and scope of WMI, consider how to manage and monitor Windows workstations and servers before (or now). You may use many graphical management tools to manage Windows resources - such as disks, event logs, files, folders, file systems, network components, operating system settings, performance data, printers, processes, registry settings. , Security, service, sharing, user, group, etc. Although the graphical tool provides a functional management solution, what is the things share? A answer is that before WMI, all Windows graphics management tools rely on the Win32 application programming interface (Application Programming Interface, APIS) to access and manage Windows resources. why? Because the only way to access Windows resources in programming methods is to pass the Win32 API. This situation allows Windows system administrators to automate commonly used system management tasks through a simple way to use common scripting languages because most scripting languages cannot call Win32 API directly. By providing consistent models and frameworks, WMI changes this - through models and frameworks, all Windows resources are described and disclosed to the outside world. The best point is that system administrators can use the WMI script library to create system management scripts, and manage any Windows resources exposed through WMI! Using Windows Script Host and Microsoft Visual Basic Scripting Edition (VBScript), or any scripting language that supports COM (for example, ActiveState Corporation ActivePerl), you can write scripts to manage and automate the following aspects of enterprise systems, applications, and networks:
• Windows Server 2003, Windows XP Professional and Windows 2000 System Management. You can write scripts to retrieve performance data, manage event logs, file systems, printers, processes, registry settings, schedulers, security, services, sharing, and many other operating system components and configuration settings. • Network management. You can create a WMI-based script to manage network services, such as DNS, DHCP, and devices that enable SNMP. • Sound monitoring in real time. Using WMI event subscriptions, you can write code to monitor and respond to event log items, monitor and respond to event log entries, monitor and respond to file systems, registry modifications, and other real-time operating system changes. Basically, WMI event subscriptions and notifications are what SNMP traps are in the SNMP environment. • Windows .NET Enterprise Server Management. You can write scripts to manage Microsoft Application Center, Operations Manager, Systems Management Server, Internet Information Server, Exchange Server, and SQL Server. http://www.microsoft.com/china/MSDN/library/enterprisedevelopment/softwaredev/WDdnclinicscripting.mspxImports System Imports System.Net Module Module1 Sub Main () Dim strMachineName As String 'to obtain the host name strMachineName = Dns.GetHostName () Console .Writeline ("Host Name:" strMachinename) 'Get the host DIM iPhost AS iPhostentry iPhost = DNS.GETHOSTBYNAME (STRMACHINENAME)' You can get DNS data information on the network. 'The syntax is as follows:' iphost = dns.gethostbyName ("Xml.sz.luhuedu.Net") Console.writeline ("Host AliaS:" iphost.aliases.length.tostring ()) Returns the relevant host in the form of an array Address Information DIM iPaddr () as ipaddress = iphost.addresslist Dim Count As Integer 'Enumerate The IP Addresses for Count = 0 To ipaddr.getupperBound (0) Console.write ("IP Address {0}: {1}", Count, _ ipaddr (count) .tostring Next End Sub End Module
NET Framework Class Library
PlatformID enumeration
Describes The Platforms Supported by an assembly.
[Visual Basic] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemplatformidClasStopic.asp
Public Enum PlatformID
[C #]
[Serializable]
Public Enum PlatformID
[C ]
[Serializable]
__value public enum platform gratformID [jscript]
public
Serializable
ENUM PlatformID
Remarks
THESE FLAGS Are Used to Bind to an assembly.
MEMBERS
Member nameDescriptionWin32NT Supported by the .NET Compact Framework.The operating system is Windows NT or later.Win32S Supported by the .NET Compact Framework.The operating system is Win32s. Win32s is a layer that runs on 16-bit versions of Windows to provide access to 32-bit applications.Win32Windows Supported by the .NET Compact Framework.The operating system is Windows 95 or later.WinCE Supported by the .NET Compact Framework.The operating system is Windows CE .NET.
Requirements
Namespace: system
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 Family, .Net Compact Framework
AskMBLY: Mscorlib (in mscorlib.dll)
See Also
System namespace | PlatformID Enumeration | Managed Extensions for C Programming
SYNTAX BASED ON .NET Framework Version 1.1.Documentation Version 1.1.1.
Get OS Name and Version http://weblogs.asp.net/mhawley/archive/2004/23/219117.aspx
Awhile ago, I had come across an article describing on how to get the current operating system version and name through .NET. While this article was great for Windows XP and prior OSes, it did not really pan out too much for Windows 2003 Server And longhorn. so after a bit of Digging to DETERMINE THE VERSION NUMBERS (THANKS TO Adam for getting me the current longhorn version #) I Was Able To successful map The Correct Versions / Names. Here's My Code:
private string GetOSName () {System.OperatingSystem os = System.Environment.OSVersion; string osName = "Unknown"; switch (os.Platform) {case System.PlatformID.Win32Windows: switch (os.Version.Minor) {case 0: OsName = "Windows 95"; Break; Case 10: OsName = "Windows 98"; Break; Case 90: OsName = "Windows Me"; Break;} Break; Case System.PlatformID.Win32NT: Switch (Os.Major ) {case 3: OsName = "Windws NT 3.51"; Break; Case 4: OsName = "Windows NT 4"; Break; Case 5: if (Os.Version.minor == 0) OsName = "Windows 2000"; ELSE IF (Os.Version.minor == 1) OsName = "Windows XP"; else if (Os.Version.minor == 2) OsName = "Windows Server 2003"; Break; Case 6: OsName = "longhorn"; Break } Break;} Return OsName "," OS.Version.toString (); ADAM HAS Also INF ORMED ME THAT 2.0, or Rather .NET 2.0, There IS A New Property That Will Return this for you, Versionstring.
Posted on Monday, August 23, 2004 4:26 PM