Announcement

Collapse
No announcement yet.

VBS - Alert if user isn't in System Administrator Group

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBS - Alert if user isn't in System Administrator Group

    I was wondering if anybody could cook me something up...

    Is there any way a VBS script can detect whether you have Admin Rights or not?
    If you aren't in the group, a message appears with a preset message.


    I've tried fooling Windows before by making an attempt to copy a non functional file to the local hard drive, if you aren't allowed, it would return an error. But I told it to display an error of my choice as opposed to VB's message.
    Problem with this way is that it isn't practical and can proove to be slow sometimes.

    I would like it if VB would check your system and then tell you. Rather than fooling it.

    Can anybody help?

    Thx

    Andy.

  • #2
    Re: VBS - Alert if user isn't in System Administrator Group

    Try modifying this fragment:

    UserString = WSHNetwork.UserName
    Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
    For Each GroupObj In UserObj.Groups
    IF GroupObj.Name = "Admin" THEN
    .......
    END IF
    Next


    Basically, loops through all the groups the user is a member of until the Admin (or whatever group you set) is found then does something.

    Alternatively you could use a select case statement to do different things for different groups.

    Hope this helps
    Tom
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: VBS - Alert if user isn't in System Administrator Group

      Hiya,

      This is the script I have below:
      __________________________________________________ ________
      UserString = WSHNetwork.UserName

      Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

      For Each GroupObj In UserObj.Groups

      IF GroupObj.Name = "Admin" THEN

      WScript.Echo "If you see this, the script ran successfully!"

      END IF

      Next
      __________________________________________________ ________

      I ran it the first time without trouble.

      However, any attempt after that resulted in the attached error...
      Attached Files
      Last edited by AndyBoot; 6th March 2006, 12:00.

      Comment


      • #4
        Re: VBS - Alert if user isn't in System Administrator Group

        Code:
        Set WshNetwork = WScript.CreateObject("WScript.Network")
        
        <script>
        Remember google is your friend.

        topper.
        * Shamelessly mentioning "Don't forget to add reputation!"

        Comment


        • #5
          Re: VBS - Alert if user isn't in System Administrator Group

          Alright smart arse! :P

          Work this one out:

          Code:
          Set WshNetwork = WScript.CreateObject("WScript.Network")
          
          UserString = WSHNetwork.UserName
          
          Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
          
          For Each GroupObj In UserObj.Groups
          
          IF GroupObj.Name = "Admin" THEN
          
          WScript.Echo "If you see this, the script ran successfully!"
          
          ELSE
          
          WScript.Echo "YOU ARE NOT IN THE ADMIN GROUP!"
          
          END IF
          
          Next
          P.S. Thanks! :P
          Attached Files

          Comment


          • #6
            Re: VBS - Alert if user isn't in System Administrator Group

            You are not specifying your DomainString !!

            The problem with this script is you will be checking a Domain User "Member Of" property for membership of a local admin group (which obviously won't be listed).

            A crude but simple way of doing this is

            Code:
            Set Shell = CreateObject("WScript.Shell")
            Set filesys = CreateObject("Scripting.FileSystemObject")
            
            computername = Shell.ExpandEnvironmentStrings("%computername%")
            
            if filesys.FolderExists("\\" & computername & "\Admin$\System32") then
              wScript.echo  ("Admin")
            else
              wScript.echo  ("Not Admin")
            end if
            * Shamelessly mentioning "Don't forget to add reputation!"

            Comment


            • #7
              Re: VBS - Alert if user isn't in System Administrator Group

              Yup! Cheers Chris!
              That script works like a treat!

              I would never of thought of doing that in a million years!

              Oh, And thanks Ossian for your help!

              Sorted!!!

              Comment

              Working...
              X