#174791 - 2007-03-20 08:07 PM
Re: Check for local admin status
[Re: Richard H.]
|
Broxoth
Getting the hang of it
Registered: 2005-04-07
Posts: 78
|
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:
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
|
|
|
|
#174801 - 2007-03-21 01:09 AM
Re: Check for local admin status
[Re: Witto]
|
Broxoth
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
|
|
|
|
#174866 - 2007-03-22 04:07 PM
Re: Check for local admin status
[Re: Witto]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Local admin is easy:
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
Getting the hang of it
Registered: 2005-04-07
Posts: 78
|
Here's the solution I came up with:
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_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
Here's the one I came up with:
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1452 anonymous users online.
|
|
|