Google Answers Logo
View Question
 
Q: How to determine from User-Agent or other info if user is an administrator ( Answered,   0 Comments )
Question  
Subject: How to determine from User-Agent or other info if user is an administrator
Category: Computers > Internet
Asked by: davepl-ga
List Price: $125.00
Posted: 05 Aug 2006 19:12 PDT
Expires: 04 Sep 2006 19:12 PDT
Question ID: 752991
How can I determine whether the user visiting my website is running on
their (Windows) PC as an administrator (ie: will be able to install
ActiveX controls, etc)?

Ideally this would be from User-Agent information, but I would also
accept a solution that requires, for example, attempting to
instantiate some object normally present on Windows machines (such as
the HTMLEdit control) or calling a method on such objects.

Request for Question Clarification by tisme-ga on 05 Aug 2006 20:27 PDT
This cannot be determined from user-agent. 

What code types/language would you be happy with?

tisme-ga

Clarification of Question by davepl-ga on 05 Aug 2006 22:01 PDT
Since we are talking about the scenario where the web page is trying
to determine whether or not the user is admin, it has to be something
that would run in a web page.

Thus, Javascript would likely be the best.  I could live with VBScript.
Answer  
Subject: Re: How to determine from User-Agent or other info if user is an administrator
Answered By: tisme-ga on 05 Aug 2006 22:22 PDT
 
Hello davepl-ga,

Here you go (in VBScript): 

-------------------------------------------------------------------

<HTML>
<HEAD><TITLE>Admin Groups Detector</TITLE>
</HEAD>
<BODY>
<H3>This page will detect if you are part of the administrator's group...</H3><HR>
<INPUT TYPE="button" NAME="button" VALUE="Check Admin Rights" onClick
= 'blnIsMemberOfAdminGroup()'>

<SCRIPT LANGUAGE="VBScript">
Function LoggedOnUser()
        On Error Resume Next
         Set objNet = CreateObject("WScript.Network")
        If err.Number <> 0 Then
            Msgbox "Error occured: " & err.Description
            Exit Function
        End If
        strAccount = objNet.UserDomain & "/" & objNet.UserName
        If strAccount = "" Then
          If err.Number <> 0 Then
            Msgbox "Error occured: " & err.Description
            Exit Function
          End If
        Else
          LoggedOnUser = strAccount
        End If
        On Error GoTo 0
    End Function
    Function blnIsMemberOfAdminGroup()
        On Error Resume Next
        blnIsMemberOfAdminGroup = False
        strUserName = LoggedOnUser()
        If strUserName = "" Then
            Msgbox "Unable to find the logged on username."
            Exit Function
        End If
        Set objShell = CreateObject("WScript.Shell")
        strComputerName = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
        strCommand = "cmd.exe /c net localgroup administrators"
        Set objShellScriptExec = objShell.Exec(strCommand)
        Set objStdOut = objShellScriptExec.StdOut
        strLine = objStdOut.ReadAll
        strUserName = Replace(strUserName, strComputerName & "/", "")
        If InStr(UCase(strLine), UCase(strUserName)) > 0 Then
           blnIsMemberOfAdminGroup = True
           msgbox "You are a member of administrator group on this
PC.",vbOKOnly + vbInformation
        Else
           msgbox "You are NOT an administrator on this PC.",vbOKOnly + vbCritical
        End If
        On Error Goto 0
    End Function    
</SCRIPT>
</BODY>
</HTML>

-------------------------------------------------------------------

I also found this link, but the above seemed a better choice:
http://www.windowsitpro.com/Files/07/49702/Listing_01.txt

All the best,

tisme-ga

Request for Answer Clarification by davepl-ga on 07 Aug 2006 11:53 PDT
This code looks promising, but when I run it and click the button I
get an error popup:

Error occured: ActiveX component can't create object.

Request for Answer Clarification by davepl-ga on 07 Aug 2006 11:58 PDT
BTW, I am surmising that this is because the WScript.Network control
might not be marked as safe for scripting.  So you really need to
limit yourself to controls that ARE marked safe for scripting.

Request for Answer Clarification by davepl-ga on 08 Aug 2006 11:28 PDT
This "answer" does not work, but the question is marked as answered. 
How do I reject an answer and ask for it to be reposted?

Thanks,
Dave

Clarification of Answer by tisme-ga on 08 Aug 2006 12:27 PDT
Hello davepl-ga,

I am still researching and working on this for you. Do you have
windows scripting installed?
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp

I am still looking into the error message.

tisme-ga

Request for Answer Clarification by davepl-ga on 14 Aug 2006 09:33 PDT
I can install anything you need on the SERVER side, but the client
that winds up visiting the site may not have anything more than a
vanilla Windows XP installation.

The problem with the first solution posted is that the control(s) you
were trying to use are not marked as "safe for scripting".  The
default security settings for Windows do not allow the client to run
scripts with controls that are not marked "safe for scripting".

Your earlier solution would work if the user changed their default
security settings, but of course that's not practical in the real
world, where you have to assume users are runnind defaults.
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy