How to Identify a Windows User With ASP

Part of providing dynamic software for users is programming content that works well with their operating systems. If your program does not run well with older Windows operating systems, it's good programming practice to detect the operating system and alert the user of incompatibility. There are 2 classes used to detect the operating system and the version in ASP, and both are needed for thorough identification.

Things You'll Need

  • Visual Studio .NET (2005 or 2008)
Show More

Instructions

    • 1

      Create a small windows form in the design window. On the window, create 2 labels. These 2 labels will be used to see the results of the program visually to verify its accuracy.

    • 2

      Use the Environment class and the OperatingSystem class. The Environment class sends back the operating system version, and the OperatingSystem class sends back the platform.

    • 3

      Determine the platform using a switch. The code below detects platform:
      System.OperatingSystem osInfo = System.Environment.OSVersion;
      switch(osInfo.Platform)
      {
      case System.PlatformID.Win32Windows:
      {
      //this detects older Windows versions including
      //Win98, Win95, or Me.
      }

      case System.PlatformID.Win32NT:
      {
      // This is for newer platforms of Windows including Win2000
      // and newer
      }

      }

    • 4

      Determine the operating system version. This is important for software programs that need to configure systems based on specifics of the operating system. For instance, root directory and registry configurations may be different for Windows 2000 versus Windows XP. For instance, the code below determines the version.
      switch (osInfo.Version.Minor)
      {
      switch(osInfo.Version.Major)
      {
      case 3:
      Label1.Text = "Windows NT 3.51";
      break;
      case 4:
      Label1.Text = "Windows NT 4.0";
      break;
      case 5:
      if (osInfo.Version.Minor==0)
      Label1.Text = "Windows 2000";
      else
      Label1.Text = "Windows XP";
      break;
      }break;
      }

    • 5

      Build the application. If you put these snippets of code in the Page_Load event, the label you created in Step 1 will display your current operating system.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured