d1r Posted October 26, 2006 Share Posted October 26, 2006 I am new on Autoit programming so I need some help to solve a problem.I am trying to convert this VBS function to AutoIT but from some reason it is not working.The function is checking if a user is member of a domain group (see below):(Based on a script I found it at: http://safariexamples.informit.com/0321213...sting_23.2.txt)-----------------------------------------Function AllowUser(sDomain, sAuthorizedGroup, szUser)Dim sUserADPath, bLoggedOnSet Group = GetObject("WinNT://" & sDomain & "/" & sAuthorizedGroup & ",group") For Each Member in Group.Members If LCase(Member.Name) = LCase(szUser) Then bLoggedOn = TRUE Exit for End If Next AllowUser = bLoggedOnEnd Function-----------------------------------In my opinion this script should look in AutoIT like:Func AllowUser($sDomain, $sAuthorizedGroup, $szUser)$Group = objGet("WinNT:\\" & $sDomain & "\" & $sAuthorizedGroup & ",group") For $Member in $Group.Members If StringLower($Member.Name) = StringLower($szUser) Then $bLoggedOn = True ExitLoop EndIf Next Return $bLoggedOnEndFunc---------------------------------------------But I am receiving the following error message when I am trying to compile it: >Running:(3.2.0.1):C:\Program Files\AutoIt3\autoit3.exe "group.au3" group.au3 (13) : ==> Variable must be of type "Object".: For $Member in $Group.Members For $Member in $Group^ ERROR+>AutoIT3.exe ended.rc:0>Exit code: 0 Time: 1.012Can you please tell me where I am wrong?TIA,Dan Link to comment Share on other sites More sharing options...
Developers Jos Posted October 26, 2006 Developers Share Posted October 26, 2006 (edited) looks close... I have posted this before in this forum. $oMyError = ObjEvent("AutoIt.Error", "ComError") If UserInGroup(@LogonDomain,@UserName,"Your AD groupNamee") then msgbox(0,"Validate","User in your groupname") Else msgbox(0,"Validate","User NOT in your groupname") EndIf Exit ; Check if User is in a group Func UserInGroup($Domain, $UserName, $InGroup) Local $objUser = ObjGet("WinNT://" & $Domain & "/" & $UserName) For $oGroup in $objUser.Groups If $oGroup.Name = $InGroup Then Return 1 EndIf Next Return 0 EndFunc ;COM Error function Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) SetError($HexNumber) Else SetError(1) EndIf Return 0 EndFunc ;==>ComError FileSetAttrib Edited October 26, 2006 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
d1r Posted October 26, 2006 Author Share Posted October 26, 2006 Thank you very much! Link to comment Share on other sites More sharing options...
craigholohan Posted November 13, 2006 Share Posted November 13, 2006 looks close... I have posted this before in this forum. $oMyError = ObjEvent("AutoIt.Error", "ComError") If UserInGroup(@LogonDomain,@UserName,"Your AD groupNamee") then msgbox(0,"Validate","User in your groupname") Else msgbox(0,"Validate","User NOT in your groupname") EndIf Exit ; Check if User is in a group Func UserInGroup($Domain, $UserName, $InGroup) Local $objUser = ObjGet("WinNT://" & $Domain & "/" & $UserName) For $oGroup in $objUser.Groups If $oGroup.Name = $InGroup Then Return 1 EndIf Next Return 0 EndFunc ;COM Error function Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) SetError($HexNumber) Else SetError(1) EndIf Return 0 EndFunc ;==>ComError FileSetAttrib Hi JdeB, This looks like something I could use but how would I minipulate the code to check if the user is in the Administrators goup on the local computer? Cheers, Craig Link to comment Share on other sites More sharing options...
Developers Jos Posted November 13, 2006 Developers Share Posted November 13, 2006 Hi JdeB, This looks like something I could use but how would I minipulate the code to check if the user is in the Administrators goup on the local computer? Cheers, CraigIsadmin() ? Or did you try?: If UserInGroup(@ComputerName,"UserID","Administrators") then msgbox(0,"Validate","User in your groupname") Else msgbox(0,"Validate","User NOT in your groupname") EndIf SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
craigholohan Posted November 13, 2006 Share Posted November 13, 2006 Isadmin() ? Or did you try?: If UserInGroup(@ComputerName,"UserID","Administrators") then msgbox(0,"Validate","User in your groupname") Else msgbox(0,"Validate","User NOT in your groupname") EndIf Wow that easy again.... I did try UserInGroup(@ComputerName,@UserName,"Administrators") but it never worked. Isadmin() works great though and its so simple..... when you know how. Thanks once again, Craig Link to comment Share on other sites More sharing options...
lod3n Posted November 13, 2006 Share Posted November 13, 2006 You can get local group membership too:Func LocalGroupContains( $GroupName,$UserName,$Domain=@ComputerName) $objGroup = ObjGet("WinNT://" & $Domain & "/" & $GroupName) For $objUser in $objGroup.Members if $username = $objUser.Name then return true Next return false EndFunc [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] Link to comment Share on other sites More sharing options...
craigholohan Posted November 14, 2006 Share Posted November 14, 2006 You can get local group membership too:Func LocalGroupContains( $GroupName,$UserName,$Domain=@ComputerName) $objGroup = ObjGet("WinNT://" & $Domain & "/" & $GroupName) For $objUser in $objGroup.Members if $username = $objUser.Name then return true Next return false EndFunc Hi lod3n, Thanks for the input but I cant seem to get your code to work, I keep getting an error "==> Variable must be of type "Object".: " pointing to "For $objUser in $objGroup.Members" What am I doing wrong? I am trying to get my app to look if the user has local Admin rights to run, if it doesnt the I want it to prompt the user to input local admin username and password. So if the user does not have admin I will call below function. Func _checkPower() $AdminName = IniRead (@ScriptDir & "\power.ini", "Power", "user","") $AdminPass = IniRead (@ScriptDir & "\power.ini", "Power", "PW","") If @UserName <> $AdminName Then Select Case @error = 0 ;OK - The string returned is valid RunAsSet($AdminName, @ComputerName, $AdminPass) If StringInStr(@ScriptFullPath, '.au3') Then Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" ' & $AdminPass) Else Run('"' & @ScriptFullPath & '" ' & $AdminPass) EndIf If @error Then $iMsgBoxAnswer = MsgBox(20,"Error","Error starting under admin mode." & @CRLF & "Quick NIC Changer will start in user mode." & @CRLF & "If you do not have Admin rights on this computer Quick NIC Changer will not work." & @CRLF & "Do you want to start Quick NIC Changer in user mode to set Admin Credentials ? " & @CRLF) Select Case $iMsgBoxAnswer = 6 ;Yes $AdminName1 = InputBox($s_Title, "Enter local Admin user name:", '', '', '280', '160', '-1', '-1') $AdminPass1 = InputBox($s_Title, "Enter local Admin password:", '', '*', '280', '160', '-1', '-1') IniWrite(@ScriptDir & "\power.ini", "Power", "user", $AdminName1) IniWrite(@ScriptDir & "\power.ini", "Power", "PW", $AdminPass1) RunAsSet($AdminName1, @ComputerName, $AdminPass1) Case $iMsgBoxAnswer = 7 ;No Exit EndSelect EndSelect Else Exit EndIf EndFunc Thanks in advance for any help, Craig Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now