Jump to content
Sign in to follow this  
JSchmitt

Need help for ComputerJoinInformation using NetApi32

Recommended Posts

JSchmitt

Hello together,

my appended Function returns the correct DomainJoinStatus, but the name is just a number ... why?

Does someone has an idea why?

Thanks in advance

Jochen

;###################################################################################################

#

; Sources for NetGetJoinInformation

; http://msdn2.microsoft.com/en-us/library/aa370423.aspx

; http://vbnet.mvps.org/index.html?code/netw...information.htm

;###################################################################################################

#

$ComputerJoinedDomain = ""

$ComputerDomainJoinStatus = "0"

:---Call Function with Variables---

NetGetJoinInfo(@Computername,$ComputerJoinedDomain,$ComputerDomainJoinStatus)

If StringLeft($ComputerJoinedDomain,5) <> "Error" Then

MsgBox(0,"Domain","ComputerDomain: " & $ComputerJoinedDomain)

MsgBox(0,"Status","JoinedDomainStatus: " & $ComputerDomainJoinStatus)

Else

MsgBox(0,"Error",$ComputerJoinedDomain)

EndIf

Exit

;###################################################################################################

#

Func NetGetJoinInfo($wkst, ByRef $JoinedDomain, ByRef $DomainJoinStatus)

Local $err, $domStruct, $bufferType, $typStruct

If StringLen($wkst) = 0 Then $wkst = @Computername

If StringLeft($wkst,2) <> "\\" Then $wkst = "\\" & $wkst

Local $domStruct = DllStructCreate("ptr"), $typStruct = DllStructCreate("int")

DllCall("NetApi32.dll", "int" ,"NetGetJoinInformation", _

"int_ptr" ,$wkst , _

"ptr" ,DllStructGetPtr($domStruct) , _

"ptr" ,DllStructGetPtr($typStruct))

If @error <> "0" Then

$JoinedDomain="Error:" & @error

Else

$JoinedDomain=DllStructGetData ($domStruct,1)

$DomainJoinStatus=DllStructGetData ($typStruct,1)

EndIf

DllCall ("netapi32.dll", "int" ,"NetApiBufferFree", "ptr" , DllStructGetData ($domStruct,1) )

EndFunc

;###################################################################################################

#

Share this post


Link to post
Share on other sites
PaulIA

Hello together,

my appended Function returns the correct DomainJoinStatus, but the name is just a number ... why?

Does someone has an idea why?

Thanks in advance

Jochen

The prototype for NetGetJoinInformation is:

NET_API_STATUS NetGetJoinInformation(

LPCWSTR lpServer,

LPWSTR* lpNameBuffer,

PNETSETUP_JOIN_STATUS BufferType

)

Those are Unicode strings, not ANSI strings. You'll need to convert the server name to Unicode before passing it to the function and then convert the name from Unicode to ANSI when the function returns. You'll need something like MultiByteToWideChar and WideCharToMultiByte for this. These functions are defined in the Auto3Lib A3LWinAPI module if you want to look at how they are implemented.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites
PaulIA

$a = DLLCall("netapi32.dll","int","NetGetJoinInformation","wstr",@computername,"int_ptr",0,"int_ptr",0)

$b = DLLCall("kernel32.dll", "none", "RtlMoveMemory", "wstr", "", "ptr", $a[2], "int", 256)

MsgBox(4096,$a[3],$b[1])

DLLCall("netapi32.dll","int","NetApiBufferFree","ptr",$B)
I think you've got the wrong pointer in the last line. Should be $a[2] shouldn't it?

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites
JSchmitt

Thanks a lot to all helped me with that!

Regards

Jochen

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.