Sign in to follow this  
Followers 0
jcpetu

Kernel32.dll - GetComputerNameEx Function –Returns nothing

3 posts in this topic

Hello, I am just begining with Autoit and I began to play with DLLs.

I am trying to get computer name from kernel32 library but I get nothing.

I will appreciate any help. Thanks a lot and regards.

The code is:

$p = DllStructCreate("char lpBuffer[128];dword lpnSize")

DllStructSetData($p, "lpnSize", DllStructGetSize($p))

DllCall("kernel32.dll","int","GetComputerNameEx", _

"str","ComputerNamePhysicalDnsFullyQualified", _ ;COMPUTER_NAME_FORMAT NameType,

"ptr",DllStructGetPtr($p), _ ;LPTSTR lpBuffer

"dword*", DllStructGetSize($p)) ;LPDWORD lpnSize

$name = DllStructGetData($p,"lpBuffer")

msgbox(0,"Info","Computer name: " & $name)

$p =0

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Few things...

First parameter for that function is (link): The type of name to be retrieved. This parameter is a value from the COMPUTER_NAME_FORMAT enumeration type

Enumeration means number. In AutoIt it's "dword" or "int".

Then following the link for COMPUTER_NAME_FORMAT you would see that the value that you want, ComputerNamePhysicalDnsFullyQualified, is 1 (enum starts at 0 unless otherwise specified).

Second thing is buffer to receive data to. AutoIt have "str" dllcall type. It's a buffer that's internally made for strings with DllCall function. It's size is minimum 65536 characters. It's wise to use it in these cases.

So, it can be written:

$aCall = DllCall("kernel32.dll", "bool", "GetComputerNameEx", _
        "dword", 1, _; "ComputerNamePhysicalDnsFullyQualified", _ ;COMPUTER_NAME_FORMAT NameType,
        "str", "", _ ; LPTSTR lpBuffer
        "dword*", 65536) ; LPDWORD lpnSize

;...place error checking here...

ConsoleWrite($aCall[2] & @CRLF)
Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Few things...

First parameter for that function is (link): The type of name to be retrieved. This parameter is a value from the COMPUTER_NAME_FORMAT enumeration type

Enumeration means number. In AutoIt it's "dword" or "int".

Then following the link for COMPUTER_NAME_FORMAT you would see that the value that you want, ComputerNamePhysicalDnsFullyQualified, is 1 (enum starts at 0 unless otherwise specified).

Second thing is buffer to receive data to. AutoIt have "str" dllcall type. It's a buffer that's internally made for strings with DllCall function. It's size is minimum 65536 characters. It's wise to use it in these cases.

So, it can be written:

$aCall = DllCall("kernel32.dll", "bool", "GetComputerNameEx", _
        "dword", 1, _; "ComputerNamePhysicalDnsFullyQualified", _ ;COMPUTER_NAME_FORMAT NameType,
        "str", "", _ ; LPTSTR lpBuffer
        "dword*", 65536) ; LPDWORD lpnSize

;...place error checking here...

ConsoleWrite($aCall[2] & @CRLF)

Trancexx: thanks a lot for your rapid response and for the valuable information its very kind of you. Now it is working like charm. I will try to convert it to function. Regards.

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  
Followers 0