Jump to content
Sign in to follow this  
dkwokgs

converting vbs to AU3 - is there a simple way?

Recommended Posts

dkwokgs

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

Share this post


Link to post
Share on other sites
torels

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 :mellow:


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

Share this post


Link to post
Share on other sites
dkwokgs

Thanks man.

Share this post


Link to post
Share on other sites
dkwokgs

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

Share this post


Link to post
Share on other sites
jerem488

In what version of Autoit are you ? :mellow:


Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites
Zedna

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

Global $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 by Zedna

Share this post


Link to post
Share on other sites
dkwokgs

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

Share this post


Link to post
Share on other sites
torels

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

mmm... the script has no .MoveFirst in it :mellow:

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

Share this post


Link to post
Share on other sites
dkwokgs

mmm... the script has no .MoveFirst in it :mellow:

Hi there any solution? Pls advise.

Share this post


Link to post
Share on other sites
dkwokgs

try

$oResults.MoveNext()

Still the same error .....

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×