Jump to content

Set/GetComputerName


Pavel
 Share

Recommended Posts

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

);

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

yeah, i tried :)

Thanks BigDod, i know that this macro exists :D

Who can re-write this functions?? :P

BOOL GetComputerNameEx(

COMPUTER_NAME_FORMAT NameType,

LPTSTR lpBuffer,

LPDWORD lpnSize

);

BOOL SetComputerNameEx(

COMPUTER_NAME_FORMAT NameType,

LPCTSTR lpBuffer

);

http://msdn.microsoft.com/library/default....puternameex.asp

http://msdn.microsoft.com/library/default....puternameex.asp

Link to comment
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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...