Sign in to follow this  
Followers 0
Pavel

Set/GetComputerName

7 posts in this topic

Hi,

Can anyone explain me, why thic function is not working ?? :P

Func _get_computer_name()

Local $MAX_COMPUTERNAME_LENGTH = 15

Local $x = DllCall("kernel32.dll","int","GetComputerName","wstr","","int",$MAX_COMPUTERNAME_LENGTH + 1)

If Not @error And $x[0] <> 0 Then Return $x[2]

EndFunc

Func _get_computer_name()

Local $MAX_COMPUTERNAME_LENGTH = 15

Local $dll_struct = DllStructCreate("char[" & $MAX_COMPUTERNAME_LENGTH + 1 & "]")

Local $x = DllCall("kernel32.dll","int","GetComputerName","char",$dll_struct,"int",$MAX_COMPUTERNAME_LENGTH + 1)

Return DllStructGetData($dll_Struct,1)

EndFunc

I found it in MSDN :

BOOL GetComputerName(

LPTSTR lpBuffer,

LPDWORD lpnSize

);

Share this post


Link to post
Share on other sites



Why re-invent the wheel

$name=@ComputerName
MsgBox(0,"Computer Name is",$name)


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi,

Can anyone explain me, why thic function is not working ?? :P

Func _get_computer_name()

Local $MAX_COMPUTERNAME_LENGTH = 15

Local $x = DllCall("kernel32.dll","int","GetComputerName","wstr","","int",$MAX_COMPUTERNAME_LENGTH + 1)

If Not @error And $x[0] <> 0 Then Return $x[2]

EndFunc

Func _get_computer_name()

Local $MAX_COMPUTERNAME_LENGTH = 15

Local $dll_struct = DllStructCreate("char[" & $MAX_COMPUTERNAME_LENGTH + 1 & "]")

Local $x = DllCall("kernel32.dll","int","GetComputerName","char",$dll_struct,"int",$MAX_COMPUTERNAME_LENGTH + 1)

Return DllStructGetData($dll_Struct,1)

EndFunc

I found it in MSDN :

BOOL GetComputerName(

LPTSTR lpBuffer,

LPDWORD lpnSize

);

I have been trying to get an answer to an almost identical question for a while so I don't know the answer, however I am sure the "char" is wrong because that would indicate that the following item was a character.

Have you tried 'str' or 'ptr'? But this is the bit I am having problems with myself.

Also I think that lpBuffer is a pointer to a buffer so instead of $dll_struct you should use

DllStructGetPtr($dll_struct)

I will watch this thread because if your problem is fixed then so is mine I hope.

EDIT - Oh dear, looks like BidDod has killed this thread

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Have a look at This topic



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Have a look at This topic

This works

Func _get_computer_name()
Local $MAX_COMPUTERNAME_LENGTH = 15
Local $dll_struct = DllStructCreate("char[" & $MAX_COMPUTERNAME_LENGTH + 2 & "]")
$sz = DllStructCreate('int')
Local $x = DllCall("kernel32.dll","int","GetComputerName","ptr",DllStructGetPtr($dll_struct),"int_ptr",DllStructGetPtr($sz))
;msgbox(0,'name',DllStructGetData($dll_Struct,1))
Return DllStructGetData($dll_Struct,1)
EndFunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks, martin, this is exactly that what I want :P

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