dkwokgs Posted November 3, 2008 Share Posted November 3, 2008 Hi There, I am trying to convert these to AU3 but had a hard time changing it. Can anyone help me. Thanks. By the way is there a simple way of doing it? CODE if UserExists("dave",sDisplayName) then wscript.echo "Found " & sDisplayName else wscript.echo "Not account found for 'Dave'" end if Function UserExists(sUser,sDisplayName) Dim oConnection, oCommand, oRoot, sDNSDomain, sQuery, sFilter, oResults UserExists = False sDisplayName = sUser On Error Resume Next ' Use ADO to search the domain for all users. Set oConnection = CreateObject("ADODB.Connection") Set oCommand = CreateObject("ADODB.Command") oConnection.Provider = "ADsDSOOBject" oConnection.Open "Active Directory Provider" Set oCommand.ActiveConnection = oConnection ' Determine the DNS domain from the RootDSE object. Set oRoot = GetObject("LDAP://RootDSE") sDNSDomain = oRoot.Get("DefaultNamingContext") sFilter = "(&(ObjectClass=user)(ObjectCategory=person)(samAccountName=" & sUser & "))" sQuery = "<LDAP://" & sDNSDomain & ">;" & sFilter & ";displayName;subtree" oCommand.CommandText = sQuery oCommand.Properties("Page Size") = 100 oCommand.Properties("Timeout") = 30 oCommand.Properties("Cache Results") = False Set oResults = oCommand.Execute Do Until oResults.EOF if oResults.Fields("displayName") <> "" then sDisplayName = oResults.Fields("displayName") UserExists = True End if oResults.MoveNext Loop On Error Goto 0 End Function Link to comment Share on other sites More sharing options...
torels Posted November 3, 2008 Share Posted November 3, 2008 if UserExists("dave",$sDisplayName) then MsgBox(0,"","Found " & $sDisplayName) else msgbox(0,"","Not account found for 'Dave'") endif Func UserExists($sUser,$sDisplayName) Dim $oConnection, $oCommand, $oRoot, $sDNSDomain, $sQuery, $sFilter, $oResults $UserExists = False $sDisplayName = $sUser ;Use ADO to search the domain for all users. $oConnection = ObjCreate("ADODB.Connection") $oCommand = ObjCreate("ADODB.Command") $oConnection.Provider = "ADsDSOOBject" $oConnection.Open "Active Directory Provider" $oCommand.ActiveConnection = $oConnection ;Determine the DNS domain from the RootDSE object. $oRoot = ObjGet("LDAP://RootDSE") $sDNSDomain = $oRoot.Get("DefaultNamingContext") $sFilter = "(&(ObjectClass=user)(ObjectCategory=person)(samAccountName=" & $sUser & "))" $sQuery = "<LDAP://" & $sDNSDomain & ">;" & $sFilter & ";displayName;subtree" $oCommand.CommandText = $sQuery $oCommand.Properties("Page Size") = 100 $oCommand.Properties("Timeout") = 30 $oCommand.Properties("Cache Results") = False $oResults = $oCommand.Execute Do if $oResults.Fields("displayName") <> "" then $sDisplayName = $oResults.Fields("displayName") $UserExists = True Endif $oResults.MoveNext Until $oResults.EOF If @error then exit EndFunc this should work fine Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org Link to comment Share on other sites More sharing options...
dkwokgs Posted November 3, 2008 Author Share Posted November 3, 2008 Thanks man. Link to comment Share on other sites More sharing options...
dkwokgs Posted November 3, 2008 Author Share Posted November 3, 2008 hey. there is 2 error. pls advise C:\test.au3(2,35) : WARNING: $sDisplayName: possibly used before declaration. if UserExists("dave",$sDisplayName) C:\test.au3 (29) : ==> The requested action with this object has failed.: $oResults.MoveFirst $oResults.MoveFirst^ ERROR Link to comment Share on other sites More sharing options...
jerem488 Posted November 3, 2008 Share Posted November 3, 2008 In what version of Autoit are you ? Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
Zedna Posted November 3, 2008 Share Posted November 3, 2008 (edited) hey. there is 2 error. pls advise C:\test.au3(2,35) : WARNING: $sDisplayName: possibly used before declaration. if UserExists("dave",$sDisplayName) C:\test.au3 (29) : ==> The requested action with this object has failed.: $oResults.MoveFirst $oResults.MoveFirst^ ERROR expandcollapse popupGlobal $sDisplayName1 if UserExists("dave",$sDisplayName1) then MsgBox(0,"","Found " & $sDisplayName1) else msgbox(0,"","Not account found for 'Dave'") endif Func UserExists($sUser,ByRef $sDisplayName) Dim $oConnection, $oCommand, $oRoot, $sDNSDomain, $sQuery, $sFilter, $oResults $UserExists = False $sDisplayName = $sUser ;Use ADO to search the domain for all users. $oConnection = ObjCreate("ADODB.Connection") $oCommand = ObjCreate("ADODB.Command") $oConnection.Provider = "ADsDSOOBject" $oConnection.Open "Active Directory Provider" $oCommand.ActiveConnection = $oConnection ;Determine the DNS domain from the RootDSE object. $oRoot = ObjGet("LDAP://RootDSE") $sDNSDomain = $oRoot.Get("DefaultNamingContext") $sFilter = "(&(ObjectClass=user)(ObjectCategory=person)(samAccountName=" & $sUser & "))" $sQuery = "<LDAP://" & $sDNSDomain & ">;" & $sFilter & ";displayName;subtree" $oCommand.CommandText = $sQuery $oCommand.Properties("Page Size") = 100 $oCommand.Properties("Timeout") = 30 $oCommand.Properties("Cache Results") = False $oResults = $oCommand.Execute Do if $oResults.Fields("displayName") <> "" then $sDisplayName = $oResults.Fields("displayName") $UserExists = True Endif $oResults.MoveNext Until $oResults.EOF If @error then exit EndFunc Edited November 3, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
dkwokgs Posted November 3, 2008 Author Share Posted November 3, 2008 still the same. ? >Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "C:\test.au3" C:\test.au3 (34) : ==> The requested action with this object has failed.: $oResults.MoveNext $oResults.MoveNext^ ERROR Link to comment Share on other sites More sharing options...
torels Posted November 3, 2008 Share Posted November 3, 2008 still the same. ?>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "C:\test.au3" C:\test.au3 (34) : ==> The requested action with this object has failed.:$oResults.MoveNext$oResults.MoveNext^ ERRORmmm... the script has no .MoveFirst in it Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org Link to comment Share on other sites More sharing options...
dkwokgs Posted November 4, 2008 Author Share Posted November 4, 2008 mmm... the script has no .MoveFirst in it Hi there any solution? Pls advise. Link to comment Share on other sites More sharing options...
Zedna Posted November 4, 2008 Share Posted November 4, 2008 try $oResults.MoveNext() Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
dkwokgs Posted November 6, 2008 Author Share Posted November 6, 2008 try$oResults.MoveNext()Still the same error ..... 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