i,
I'm trying to use the NetRenameMachineInDomain API call from within Delphi
4.
(see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netm...
mapi2_8hm6.asp for details of the API structure)
The VB6 code snippet below works fine, but my poor attempt to convert this
to Delphi (below) isn't so sucessfull
The errors I get are in the returncode I get either a:
87 : ShowMessage('The parameter is incorrect');
1113 : ShowMessage('No mapping for the Unicode character exists in the
target multi-byte code page');
1210 : ShowMessage('The format of the specified computer name is invalid');
1326 : ShowMessage('Logon failure: unknown user name or bad password');
I did try the string parameters as PChars, on the function declaration but
no joy their either.
I've got a feeling the problem lies with the flag, in VB this is &H2, I'm
not sure if my attempt at using "2", and "$00000002" are correct.
I'd appreicate it if someone could point me in the right direction.
thanks
David
'VB6 - Works OK
Private Declare Function NetRenameMachineInDomain Lib "netapi32" _
(ByVal lpserver As Long, ByVal machinename As Long, ByVal lpaccount As Long,
_
ByVal passwrd As Long, ByVal foptions As Long) As Long
Private Const NETSETUP_ACCT_CREATE = &H2 'Do the server side
account creation/rename
Private Sub Command1_Click()
Dim flags, res1 As Long
flags = NETSETUP_ACCT_CREATE
res1 = NetRenameMachineInDomain(0, StrPtr("NewName"),
StrPtr("administrator"), StrPtr("password"), flags)
MsgBox (res1)
End Sub
//--------------------------------------------------------------------------
// My attempt a the Delphi Port
// -------------------------------------------------------------------------
Const
NETSETUP_ACCT_CREATE = 0x00000002;
Function NetRenameMachineInDomain(lpserver:string; machinename:string;
lpaccount:string; passwrd:string; foptions : LongInt):LongInt
stdcall;far;external 'netapi32.dll';
procedure TForm1.Button1Click(Sender: TObject);
var strNewComputerName, strUserID, strPassword : string;
resultcode : LongInt;
flags : LongInt;
begin
flags:=NETSETUP_ACCT_CREATE;
resultcode:= NetRenameMachineInDomain('', 'New Name', 'administrator',
'password', flags);
Case resultcode of
0 : ShowMessage('Success');
87 : ShowMessage('The parameter is incorrect');
1113 : ShowMessage('No mapping for the Unicode character exists in
the target multi-byte code page');
1210 : ShowMessage('The format of the specified computer name is
invalid');
1326 : ShowMessage('Logon failure: unknown user name or bad
password');
Else
ShowMessage('Result Code : ' + IntToStr(resultcode));
End;
end;