Page 1 of 1 1
Topic Options
#174755 - 2007-03-19 06:45 PM Check for local admin status
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Anyone know of a way (KiX or otherwise) to determine whether the current user is a member of the local admins group on a remote pc? I'm looking specifically for solution that can even look through nested groups to determine local admin status for the current user.
Top
#174756 - 2007-03-19 07:13 PM Re: Check for local admin status [Re: Broxoth]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Have a look at the LocalAdmin() - checks for membership of local admin group UDF.

Maybe you already know how to use UDF's. If not have a look at the link below.
KiXtart FAQ & How to's » How to use UDFs


Edited by Mart (2007-03-19 07:14 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#174757 - 2007-03-19 07:18 PM Re: Check for local admin status [Re: Mart]
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
I do know how to use UDF's and I think I recall seeing this one in the past. However I'm not sure this would work for nested groups, such as Domain Admins.
Top
#174773 - 2007-03-20 10:06 AM Re: Check for local admin status [Re: Broxoth]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Have you tried it?

It will only take 5 minutes of your time to prove to your own satisfaction whether it will work for you or not. You may have some local idiosyncrasy which affects the UDF which we cannot replicate.

Give it a go and report back - both if it dows not work for you and also if it does. That way other people who stumble across this thread will be able to make use of the information.

Top
#174776 - 2007-03-20 12:30 PM Re: Check for local admin status [Re: Richard H.]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Being member of a group that is a member of another group should make the first one a member of the third one. At first sight, I see no problem in nested groups.
Top
#174791 - 2007-03-20 08:07 PM Re: Check for local admin status [Re: Richard H.]
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
 Originally Posted By: Richard H.
Give it a go and report back - both if it dows not work for you and also if it does. That way other people who stumble across this thread will be able to make use of the information.


Good point.
Yes, I've tried it and it will work. Now the problem seems that I can't get this script to pass either error (0 or 1) to a VB script. Here's what I'm trying to do.

In an Access database a button is pressed and it first detects that a PC listed in a field is available via a %comspec% call to ping.
If the PC does ping, I need it to check if the current user is a local admin.
If yes, then it will proceed with the next function (various WMI queries).
If no, it needs to return the proper error.

Here's the VB code:
 Code:
Function IsAdmin()
Dim oShell
Dim oFSO
Dim sTemp
Dim sTempFile
Dim fFile
Dim sResults

    Const OpenAsDefault = -2
    Const FailIfNotExist = 0
    Const ForReading = 1
    
    Set oShell = CreateObject("WScript.Shell")
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
    sTempFile = sTemp & "\inv_isadmin.tmp"

    oShell.Run "%comspec% /c kix32 %systemroot%\userislocaladmin.kix"
End Function
Private Sub CompAvail()
If IsConnectible(strComputer, 1, 750) Then 'Pings strComputer
   If IsAdmin = 1 Then
      WMIwrapper
   Else: MsgBox "    The operation has received an error. It is highly likely that" & Chr(13) & _
           "    you received this error due to a lack of administrator privileges " & Chr(13) & _
           "    on the remote computer. Please check the computer before " & Chr(13) & _
           "    reattempting this connection.", vbExclamation, "Error - Check permissions"
   End If
Else:
  Err_Handler
End If

End Sub

The KiX code is simply "LocalAdmin" which I have seen return a "1".
(I had to reformat the above code after I pasted. It looks right but I may have missed something.)
The result of all of this is the KiX script, when ran, flashes a 1, and then the VB script proceeds with Else statement and doesn't run the WMIwrapper function.
Now, I realize this is a forum for KiX but I'm hoping that someone will still be able to tell me where I'm going wrong, whether it's in the VB or KiX.

If it's VB, just tell me it's wrong and that's enough. I'll start looking for the answers elsewhere. I feel stupid for posting this on this forum but this is the only forum that I've had any help with recently .

Top
#174799 - 2007-03-21 12:36 AM Re: Check for local admin status [Re: Broxoth]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
If you had a quesion about vbscript, this would have been a question for the Lounge.
Just googled a bit. Maybe it can help you:
http://www.eggheadcafe.com/software/aspnet/27532999/re-login-script--add-pr.aspx
http://technet2.microsoft.com/WindowsSer...3.mspx?mfr=true
By reading the articles and looking at the example logon script, I understand why I still stick to KiX.
Thanks Ruud.

Top
#174801 - 2007-03-21 01:09 AM Re: Check for local admin status [Re: Witto]
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
At the outset, my question wasn't about VBScript. It morphed. \:\)
Thanks for the help.
I'm not really after a logon script but I can probably find something out there to help me piece this thing together.

Top
#174803 - 2007-03-21 01:15 AM Re: Check for local admin status [Re: Broxoth]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I thought I saw a method in it to see if you are member of a certain group.
Top
#174866 - 2007-03-22 04:07 PM Re: Check for local admin status [Re: Witto]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Local admin is easy:
 Code:
If InGroup(@WKSTA + "\Administrators")
  ? "True"
Else
  ? "False"
EndIf

Remote local admins is something else entirely

Top
#174868 - 2007-03-22 04:25 PM Re: Check for local admin status [Re: Arend_]
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Here's the solution I came up with:

 Code:
Function IsAdmin(strUsr)
On Error Resume Next
Dim strGroup
Dim objGroup
Dim objMember

' strUsr can be a user or a group
'Declare strComputer string outside of this function OR uncomment below for current computer
'strComputer="."

strGroup = "Administrators"
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")

For Each objMember In objGroup.Members
  If objMember.Name = strUsr Then
    Err.Raise 30000
  End If
Next

End Function

IsAdmin ("Domain Admins")
    If Err.Number = 30000 Then
      WMIwrapper
    ElseIf Err.Number = 0 Then
          MsgBox "    Whatever...."
  End If


You can set the error number to nearly anything but you'd obviously just need to ensure that it's not a number that's already used for a true error.
This may not be the cleanest method but it works. It provides an easy way to make sure that any user is in any local group.
It's kinda odd to post this VB solution on this forum but it may be helpful for those people out there who, like me, have hybrid scripts of VB and KiX.
Thanks to everyone, especially Witto who got me on the right track.

Top
#174870 - 2007-03-22 04:33 PM Re: Check for local admin status [Re: Broxoth]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Here's the one I came up with:
 Code:
Function RemoteLocalAdmin($pcName)
  $RemoteLocalAdmin = 0
  Dim $strNT, $objStr, $Member
  $strNT = "WinNT://" + $pcName + "/Administrators,Group"
  $objStr = GetObject($strNT)
  $objStr.GetInfo
  For Each $Member in $objStr.Members
    If Ingroup($Member.Name)
      $RemoteLocalAdmin = 1
    EndIf
    If $Member.Name = @userid
      $RemoteLocalAdmin = 1
    EndIf 
  Next
EndFunction

Returns 1 for true and 0 for false

Top
#174880 - 2007-03-22 07:05 PM Re: Check for local admin status [Re: Arend_]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
 Originally Posted By: Broxoth

In an Access database a button is pressed

Apronk,
Can this code be used in an Access database behind a button?

Top
#174892 - 2007-03-22 08:05 PM Re: Check for local admin status [Re: Witto]
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
Witto,

This could work if the VB calls the KiX script to run and the KiX script writes the result to a text file. Then the VB script could read that file and then delete it.

I would write the code for all of that but...meh. You all get the idea of it.

Top
#174899 - 2007-03-22 10:37 PM Re: Check for local admin status [Re: Broxoth]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
If you can call a kix script in access, can't you just catch a return value and/or a error value returned by the script in stead of writing it to a file?
I presume that the KiX script can return an error value on exit that could be catched by your Access Database?

Top
#174909 - 2007-03-23 10:18 AM Re: Check for local admin status [Re: Witto]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
 Originally Posted By: Witto
If you can call a kix script in access, can't you just catch a return value and/or a error value returned by the script in stead of writing it to a file?
I presume that the KiX script can return an error value on exit that could be catched by your Access Database?


To be honest I couln't say. I never played around with Access databases to the extend that it calls for external stuff. Only thing I used Acces for basically the same as an ini but for more stuff.

Top
#174919 - 2007-03-23 04:53 PM Re: Check for local admin status [Re: Witto]
Broxoth Offline
Getting the hang of it

Registered: 2005-04-07
Posts: 78
As I understand it, no. From what I have read, when a command is run from a Shell environment within a script, it cannot simply receive the returned error/value; it must be written to a file and then read from that file. I, of course, have no idea which site I read it on but I believe it was a MSDN KB article. If anyone out there can verify this, it would be helpful.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.077 seconds in which 0.031 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org