Strange Windows 98 bug with V 1.1 of the framework
The below code makes sure that the user running this code is an Administrator:
Dim myDomain As AppDomain = Thread.GetDomain()
myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
Dim myPrincipal As WindowsPrincipal = DirectCast(Thread.CurrentPrincipal, WindowsPrincipal)
If myPrincipal.IsInRole(WindowsBuiltInRole.Administrator) Then
When running this code on a Windows 98 machine, you get a vague security exception:
"Application has generated an exception that cannot be handled"
From Microsoft:
"It makes sense that we are seeing this exception on Windows 98 because there is no Administrator role, or even a concept of any role. Obviously we need to correct MSDN Help which incorrectly states that IsInRole is supported on Windows 98. There is a second issue here in that, you can also generate this exception on a Windows XP machine by calling the overloaded IsInRole method that takes an Integer (as you are doing) and pass it a Role ID (RID) that does not match any known RID. You may want to put your code in a Try...Catch block and handle the System.ArgumentException."
The solution, wrap this check with a check on the OS:
Dim strOS As String = System.Environment.OSVersion.ToString()
Dim strWin98 As String = "Microsoft Windows 98"
Dim intReturn As Integer
intReturn = strOS.IndexOf(strWin98)
If intReturn = -1 Then