Link to home
Start Free TrialLog in
Avatar of lulli
lulli

asked on

Add User To "User Manager" In NT


i like to be able to add a user with the name "AdminALL" and set him into Administrator Groub, how can i do this? i start on 50 points and for complete answer i will raise upto ?

Thanks in advance
Lulli
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulli
lulli

ASKER


maybe i have to add the user to the administrator group on the fly, my email is lulli@vis.is
ok am sending in a couple of minute
Avatar of lulli

ASKER

I get error on NTADDLocalMember.pas , i'm using Delphi 4.0
C/S
i am going out for a while but leave the error message here and i say what is wrong,i also installed them in delphi4 c/s .are you installing them on nt?
i didnt install them all only some so i have a look when i get back.
Avatar of lulli

ASKER

alright, i have install theese components unless "NTADDLocalMember.pas" and i can't add user with "NTAddUser???" component , nothing works
Avatar of lulli

ASKER

alright, i have install theese components unless "NTADDLocalMember.pas" and i can't add user with "NTAddUser???" component , nothing works
hi
i find better ones(not installable components but units) that contain the nt functions you need here:
http://members.xoom.com/_XMCM/ray_adams/files/LM.ZIP
see the following functions declared in
lmacess.pas in this zip,just add this unit and any others it needs to your uses section then call the function you need.

functions include:

function NetGroupAdd (serverName : PWideChar; level : Integer; buffer : PChar; var parm_err : Integer) : NetAPIStatus; stdcall;

function NetGroupAddUser (serverName, GroupName, UserName : PWideChar) : NetAPIStatus; stdcall;

function NetGroupDelUser (serverName, groupName, userName : PWideChar) : NetAPIStatus; stdcall;

function NetLocalGroupAdd (serverName : PWideChar; level : Integer; buffer : PChar; var parm_err : Integer) : NetAPIStatus; stdcall;

function NetLocalGroupAddMember (serverName, groupName : PWideChar; memberSid : PSID) : NetAPIStatus; stdcall;
note:
 do you have registry access(admin access?)you will need this to create users etc..probably why it was failing before.
or
you can get around having to be the admin by using this TNTRegistry unit from:
http://www.maxoutput.com/ 

Avatar of lulli

ASKER

I'am adminitrator
Avatar of lulli

ASKER

I'am adminitrator
Avatar of lulli

ASKER

I can't install theese component from
                                                    http://www.maxoutput.com/ 

I'm using Delphi 4.0, and

if RegEnumKeyEx(DeleteKey, I, PChar(KeyName), Len, nil, nil, nil, nil) = ERROR_SUCCESS then

Error = type of actual parameter?????????????
Avatar of lulli

ASKER

Barry!!!!!!
hi,
sorry make you wait i been asleep.

you dont need the registry component as you are the admin,it is for people who are not admins to have more rights in reading/writing the registry
excerpt from page:
"
TNTRegistry is a Delphi 3.0 component which replaces Borland's built-in TRegistry component.   It fixes the bug in TRegistry which prevents NON-administrative users from modifying the system registry from under Windows NT.  
                                     "
i see it doesnt come with source code but tht dont matter i can paste a free version here if you want it.as there are some on dejanews.

the errors are because it was made for delphi3 ,in delphi4 youd need to change some of the variables from integers to cardinals etc..(but you cant as you dont have the source.)
did you try the lm.zip files?
do they work?
Avatar of lulli

ASKER

i get error on this " "

function NetGroupAdd (serverName : PWideChar; "level : Integer;" "buffer : PChar;" "var parm_err : Integer") : NetAPIStatus; stdcall;

Theese three in the function, what is that value e.g
"var parm_err : integer"

now on the TRegistry, you may send me "palli@vis.is"

i have administrator rights, but i'm buiding program for non administrator that have to write values to registry, but how?
Avatar of lulli

ASKER

do you have any example for "RegCreateKeyEx" API? and
ALL_KEY_ACCESS
hi,
basically the parm_err can be a 0 or a
var
 d : dword;

then use the d in parm_err.

the functions from these files are all documented in win32.hlp file in you delphi directory(do a search on your pc for win32.hlp probably under "borland shared" dir)
using the find of this help you will see
the following:

(special note the security requirements)

The NetGroupAdd function creates a global group in the security database.

Security Requirements

Only members of the Administrators or Account Operators local group can successfully execute NetGroupAdd.

NET_API_STATUS NetGroupAdd(

    LPWSTR servername,      
    DWORD level,      
    LPBYTE buf,      
    LPDWORD parm_err       
   );      
 

Parameters

servername

Pointer to a Unicode string containing the name of the remote server on which the function is to execute. A NULL pointer or string specifies the local computer.

level

Specifies one of the following values to set the level of information pointed to in the buf parameter.

Value      Meaning
0      Specify group name. The buf parameter contains a pointer to a GROUP_INFO_0 structure.
1      Specify group name and a comment. The buf parameter contains a pointer to a GROUP_INFO_1 structure.
2      Specifies information about the group. The buf parameter contains a pointer to a GROUP_INFO_2 structure.
 

buf

Pointer to a buffer containing the global group information structure.

parm_err

Optional pointer to a DWORD to return the index of the first parameter in error when ERROR_INVALID_PARAMETER is returned. If NULL, the parameter is not returned on error.


now the registry problem i am blind i didnt see te link to the source code:
http://www.maxoutput.com/ntreg.pas
you will definelty need this if your writing to the registry and not the admin.
rememeber any problems on using it you may need change integers to cardinals etc.
il try find an example of RegCreateKeyEx
couple of examples i found:

example1:

procedure TForm1.Button1Click(Sender: TObject);
var a:Hkey;
begin
RegCreateKeyEx(HKEY_LOCAL_MACHINE,'Klop',0,'',REG_OPTION_NON_VOLATILE,   KEY_ALL_ACCESS,nil,a,nil);
end;

example 2:

Function TForm1.ReadFromRegistry:DWord;
Var
  Res:Boolean;
  TempKey: HKey;
  TempKeyStr:Pchar;
  Disposition: Integer;
  Dtype:Integer;
  Dsize:Integer;
  RegData:DWORD;
Begin
  Dtype:=REG_BINARY;
  Dsize:=SizeOf(DWORD);
  TempKeyStr:=PChar('System\CurrentControlSet\Services\VxD\EL_I2C');   Res:=RegCreateKeyEx(HKEY_LOCAL_MACHINE,TempKeyStr, 0 ,nil,
                      REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,nil,                       TempKey,@Disposition) = ERROR_SUCCESS;
  if Disposition = REG_CREATED_NEW_KEY then
 
Res:=RegOpenKeyEx(HKEY_CLASSES_ROOT,TempKeyStr,0,KEY_ALL_ACCESS,TempKey) = ERROR_SUCCESS;
  res:=RegQueryValueEx(TempKey,'IO_BASE',nil,@Dtype,@RegData,@DSize) =ERROR_SUCCESS;
  RegCloseKey(TempKey);
  if not res then RegData:=$305;
  Result:=RegData;
End;

hope they help ;-)

Avatar of lulli

ASKER

Can you fix for me NTReg.pas ?
sure ,ill take a look but not till tommorrow (im exhausted after very long day at work ;-(

ill post something tommorrow night (probably about 24 hrs time from when i place this comment as cant acess internet from work at moment )
ok fixed :-)


the easy way open a new blank project in delphi and add ntreg to the uses  ,press f9 to compile and it will give error so click ok and scroll up a couple of lines to where "Len" is declared and all you have to do is replace these lines:

var
I,Len : Integer;
   
with

var
I : Integer;
Len: Cardinal;

press f9 again to compile and go to next error line.
this occurs in about 6 places the change is needed.

Regards Barry
Avatar of lulli

ASKER

i build a user on my computer that don't have administrator's rights, and when i try to create key under,
HKEY_LOCAL_MACHINE, came an error 'Can't Create Key', i'am administrator and i can write it. What's wrong with this TNTRegistry?
are you saying that you log on as  administrator and you code didnt work.

can you paste here the code you tried so i can test it.
as long as you are admin all functions should work but when your not admin it depends,tntregisry doesnt give non admins full access just fixes some bugs with createkey ,key_all_access etc.
 
Avatar of lulli

ASKER

Var Reg : TRegistry;
begin
Reg.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey('CLONE',True);
Try
Reg.CreateKey('Lulli');
Except
Begin
ShowMessage('Cant Create Key');
End;
Reg.CloseKey;
Reg.Free;
End;
ntreg lets you create keys etc when not admin but it doesnt let you create them under HKEY_LOCAL_MACHINE.
this is for nts security reasons.
you can create them under hkey_current_user etc though instead.

uses ntreg;

procedure TForm1.Button1Click(Sender: TObject);
Var Reg : TNTRegistry;
begin
REG := TNTRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
with reg do try
openKey('Software',True);
CreateKey('Lulli');
except
ShowMessage('Cant Create Key');
Reg.CloseKey;
Reg.Free;
End;
end;


i understand d5 has a new createkey function that you can call like:
reg:= tregistry.createkey(KEY_ALL_ACCESS);
but that wont help now..
Avatar of lulli

ASKER

Thanks "Inthe"