views:

148

answers:

2

Hello Folks,

How do you (programatically) show the windows local users/groups dialog? In Vista it's usually under Control Panel - Administrative Tools - Computer Management - Local Users and Groups. Similar kind of dialog with the same functionalities (add/remove users/groups) is also acceptable, as long as supported by Windows Xp and above.

Delphi codes would be great, although not necessary!

A: 

It sounds like you want the Directory Object Picker dialog, documented here:

http://msdn.microsoft.com/en-us/library/ms676973(v=VS.85).aspx

It works with Windows 2000 or higher. There is some sample code here (in C++):

http://msdn.microsoft.com/en-us/library/ms675899(VS.85).aspx

Nate
I haven't tried it, but from the msdn article I assume it's to display some kind of object select dialog (which the object can be computers, users, or groups), not a simple local users/groups management. Or am I mistaken?
DonnVall
I may have mis-read your question. I thought you wanted to let the user select a user/group. It displays this dialog: http://imgur.com/Xz6Fo.png. In this example, it lets you pick a user. It can also be configured to select groups, to select from just the local computer, or to select from an Active Directory domain. (The Microsoft example code shows how to pick from a domain.) This is the “standard” way to pick a user, although it is fairly complex.
Nate
There you have it, that "standard" dialog is fairly complex for ordinary users. That's why I've created my own very simple version of it (just a list with checkboxes). However I'm not going to provide full support of adding or removing users/groups.
DonnVall
+1  A: 

Seems like you are looking for lusrmgr.msc applet. You can execute it from command line, Delphi code example:

uses
  ShellAPI;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShellExecute(Handle, 'open', 'lusrmgr.msc', nil, nil, SW_SHOWNORMAL) ;
end;
Serg
This module is not available in Windows 7 Home Premium; probably the same applies to Windows Vista Home Premium.
Andreas Rejbrand
@Andreas Rejbrand - Yes, you can't run it in Vista Home Premium.
Serg
`control lusrmgr.msc`? or `control nusrmgr.msc`? or `control userpasswords`? or `control userpasswords2`?
Sertac Akyuz
@Sertac: You cannot start a *.msc by calling `control *.msc`; simply call `*.msc` alone. Anyhow: The first exists but is merely a template. The latter does not exist. The two remaining both work.
Andreas Rejbrand
@Andreas - Ah, Ok!, I thought I was writing `.cpl` not '.msc'. Anyway, working is good.. :)
Sertac Akyuz
@Serg: I have tried it, and this is exactly what I was looking for. The only problem is the add in is not available in any of Home editions of Windows (which is answered by Sertac).
DonnVall
@Andreas and Sertac: Thanks for pointing out that this solution does not available in Home editions and for possible replacement. Anyone can give me quick code to determine Home editions of Windows?
DonnVall
@Donn - See: [How to check in delphi the OS version?..](http://stackoverflow.com/questions/1268178/how-to-check-in-delphi-the-os-version-windows-7-or-server-2008-r2/1268320#1268320)
Sertac Akyuz
@DonnVall: check if localsec.dll is present in the system32 folder on Home editions and if so try registering it (regsvr32 localsec.dll).
Remko
DonnVall