473,508 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking if Administrator

Hi All,

Quick question, I manage to come up with a working code the
successfully checks if the current users is part of the Administrators
group or not. My question is, will this code work from Windows 95? 98?
ME? 2000?

My development machine is currently XP, and it works fine here.

Thanks in advance,
Henry :)

Private Function CheckAdministratorRole() As Boolean
On Error Resume Next
System.AppDomain.CurrentDomain.SetPrincipalPolicy( Security.Principal.PrincipalPolicy.WindowsPrincipa l)
Dim prpAdministrator As New
System.Security.Permissions.PrincipalPermission(En vironment.UserName,
"BUILTIN\Administrators")

prpAdministrator.Demand()

If Err.Number <> 0 Then
CheckAdministratorRole = True
Else
CheckAdministratorRole = False
End If
End Function

Nov 21 '05 #1
6 1364
Oh by the way, which is the better code, the 1st one i posted or the
ff:

Private Function CheckAdminRole() As Boolean
Dim myDomain As AppDomain = System.Threading.Thread.GetDomain()
myDomain.SetPrincipalPolicy(Security.Principal.Pri ncipalPolicy.WindowsPrincipal)
Dim myPrincipal As Security.Principal.WindowsPrincipal =
CType(System.Threading.Thread.CurrentPrincipal,
Security.Principal.WindowsPrincipal)

If myPrincipal.IsInRole("BUILTIN\Administrators") = True Then
CheckAdminRole = True
Else
CheckAdminRole = False
End If
End Function

It works the same, but what about scenarios on a user belonging to two
or more domains? Which is the better code?
And lastly, on my 1st code, what does the
"System.AppDomain.CurrentDomain*.SetPrincipalPolic y(Security.Principal.PrincipalPolicy.Windo*wsPrinc ipal)"
do? When I commented it out, the code still works.

Thanks again,
Henry :)

Nov 21 '05 #2
Henry,

Surely not on Windows'95 when you use VBNet, I never heard that it was not
working on W98/me and the others. However why would it not, it is a dotNet
part.

The only restriction I see here.
http://msdn.microsoft.com/library/de...10security.asp

However I did not test it so I can be wrong.

Cor


Nov 21 '05 #3
<he***********@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Hi All,

Quick question, I manage to come up with a working code the
successfully checks if the current users is part of the Administrators
group or not. My question is, will this code work from Windows 95? 98?
ME? 2000?

My development machine is currently XP, and it works fine here.

Thanks in advance,
Henry :)


As I recall, Windows 95, 98 and ME don't have the same security model as
NT4/2000/XP and don't have the concept of an administrator (nor of a
domain).

Your code should therefore work on NT4 and 2000. I haven't a clue what it
will do on 95/98/ME (not having tried it), but its possible it will degrade
gracefully ...? Hopefully someone with 95/98/ME will try it for you.

Brian.

www.cryer.co.uk/brian
Nov 21 '05 #4
<he***********@gmail.com> schrieb:
Quick question, I manage to come up with a working code the
successfully checks if the current users is part of the Administrators
group or not. My question is, will this code work from Windows 95? 98?
ME? 2000?
[...]
Private Function CheckAdministratorRole() As Boolean
On Error Resume Next
System.AppDomain.CurrentDomain.SetPrincipalPolicy( Security.Principal.PrincipalPolicy.WindowsPrincipa l)
Dim prpAdministrator As New
System.Security.Permissions.PrincipalPermission(En vironment.UserName,
"BUILTIN\Administrators")

prpAdministrator.Demand()

If Err.Number <> 0 Then
CheckAdministratorRole = True
Else
CheckAdministratorRole = False
End If
End Function


MSDN on 'IPrincipal.IsInRole' and 'AppDomain.SetPrincipalPolicy' says:

| *Requirements*
|
| *Platforms:* Windows 98, Windows NT 4.0, Windows
| Millennium Edition, Windows 2000, Windows XP Home Edition,
| Windows XP Professional, Windows Server 2003 family

This means that the methods are supported by all versions of Windows running
the .NET Framework. The .NET Framework doesn't work together with Windows
95. I suggest to check the documentation for the requirements of other
methods you are using too.

Simpler solution for checking if the user is an administrator:

\\\
Imports System.Security.Principal
..
..
..
Dim wp As New WindowsPrincipal(WindowsIdentity.GetCurrent())
Dim IsAdmin As Boolean = wp.IsInRole(WindowsBuiltInRole.Administrator)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
Herfried,

I forgot to look at the bottom, good that you did that

:-)

Cor
Nov 21 '05 #6
Thanks guys!

98 is ok to me!! :) Clients are up to 98!

Thanks again for the shorter code!!

Henry :)

Herfried K. Wagner [MVP] wrote:
<he***********@gmail.com> schrieb:
Quick question, I manage to come up with a working code the
successfully checks if the current users is part of the Administrators
group or not. My question is, will this code work from Windows 95? 98?
ME? 2000?
[...]
Private Function CheckAdministratorRole() As Boolean
On Error Resume Next
System.AppDomain.CurrentDomain.SetPrincipalPolicy( Security.Principal.PrincipalPolicy.WindowsPrincipa l)
Dim prpAdministrator As New
System.Security.Permissions.PrincipalPermission(En vironment.UserName,
"BUILTIN\Administrators")

prpAdministrator.Demand()

If Err.Number <> 0 Then
CheckAdministratorRole = True
Else
CheckAdministratorRole = False
End If
End Function


MSDN on 'IPrincipal.IsInRole' and 'AppDomain.SetPrincipalPolicy' says:

| *Requirements*
|
| *Platforms:* Windows 98, Windows NT 4.0, Windows
| Millennium Edition, Windows 2000, Windows XP Home Edition,
| Windows XP Professional, Windows Server 2003 family

This means that the methods are supported by all versions of Windows running
the .NET Framework. The .NET Framework doesn't work together with Windows
95. I suggest to check the documentation for the requirements of other
methods you are using too.

Simpler solution for checking if the user is an administrator:

\\\
Imports System.Security.Principal
.
.
.
Dim wp As New WindowsPrincipal(WindowsIdentity.GetCurrent())
Dim IsAdmin As Boolean = wp.IsInRole(WindowsBuiltInRole.Administrator)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1549
by: ColinWard | last post by:
Hi. I know there is a simple answer to this one but for the life of me I can't get it. I have a login form where users type their username and password. When they press the login button, I have...
9
6912
by: Jonny | last post by:
Hey all, I need to verify that a provided username is a Domain Administrator. Any idea's on how to do this? Thanks, Jonny -- /Jonny
2
2910
by: Simple Java Drinker | last post by:
I decided to reinstall the Windows XP on my computer by using the Repair Option. After typing "R" as required I am requested to input an administrator password. The problem is that no administrator...
2
1737
by: Pat | last post by:
Hi, I installed Mysql Administrator with file mysql-administrator-1.0.22a-1.rh9.src.rpm from the mysql-site on my RedHat 9.0 computer I did: rpm -Uvh mysql-administrator-1.0.22a-1.rh9.src.rpm...
7
33375
by: phillip.s.powell | last post by:
We're looking at a GUI interface for our MySQL DB and I am interested in MySQL Administrator, however, one of our requirements is to be able to import/export databases. Is this possible or do I...
1
3424
by: grabro | last post by:
Having just upgraded to from Suse 10.0 to 10.1 mysql-administrator will not work. When I try to acccess it I get the following message. linux:/home/grabro # mysql-administrator...
3
4073
by: Mark Rae | last post by:
Hi, I've been asked to write a WinForms app which will create reports as PDF documents. The client has agreed that all desktops (WinXP Pro, 32-bit Vista Business) *will* have Adobe Acrobat...
8
9813
by: =?Utf-8?B?TWFydGluIFNhY2hz?= | last post by:
I have been using MSCONFIG (XP Pro) for four years with no problem. I always use it in Administrator. Last night, when I attempted to go into selective startup mode, I got the following error...
1
1548
by: Jack Russell | last post by:
Under XP I used the following code AppDomain.CurrentDomain.SetPrincipalPolicy(Security.Principal.PrincipalPolicy.WindowsPrincipal) Dim MyPrincipal As System.Security.Principal.WindowsPrincipal...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.