The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Force on February 12, 2012, 11:58:57 PM

Title: Rename Computer Name
Post by: Force on February 12, 2012, 11:58:57 PM
Hello !..



in Windows.hlp

BOOL SetComputerName(

    LPCTSTR lpComputerName    // address of new computer name
   );

and it's my code

.386
.model flat,stdcall
option casemap:none


include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib


.data
AppName db "Rename",0
compName db "Toshiba",0
err db "Failed",0
ok db "Succeed",0

.code
start:

invoke SetComputerName,addr compName

.if eax!=0
invoke MessageBox,NULL,addr ok,addr AppName,MB_OK
jmp Exit
.endif
invoke MessageBox,NULL,addr err,addr AppName,MB_OK

Exit:
invoke ExitProcess,NULL
end start

Something wrong with this code or it just dsnt work on Windows 7

Thanks


Force
Title: Re: Rename Computer Name
Post by: MichaelW on February 13, 2012, 12:31:23 AM
If the function is failing try calling the   GetLastError function (http://msdn.microsoft.com/en-us/library/windows/desktop/ms679360(v=vs.85).aspx) to get the last error code value. You can then either look up the error code value in the  System Error Codes (http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx), or use the MASM32 LastError$ macro to display the system-defined string for the error code.
Title: Re: Rename Computer Name
Post by: RotateRight on February 13, 2012, 12:54:16 AM
SetComputerName

See first line of docs here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724930(v=vs.85).aspx

for reason it is not working.
Title: Re: Rename Computer Name
Post by: Gunner on February 13, 2012, 01:08:36 AM
Fist line of doc is
QuoteSets a new NetBIOS name for the local computer. The name is stored in the registry and the name change takes effect the next time the user restarts the computer.

Instead, look at the remarks section:
QuoteRemarks

Applications using this function must have administrator rights.

Windows 7 IS NOT Windows 2K, or XP, it is a totally different beast.  Many things can only be done with Admin rights.
Title: Re: Rename Computer Name
Post by: Force on February 13, 2012, 03:22:04 PM
I just tried it on another computer with XP

SUCCEED

yeah after restarting i saw new name

that means it doesnt work on Win 7 or my computer is getting crazy i dont know :))