您的位置:首页 > 其它

如何添加本地用户

2009-11-07 09:30 387 查看
;
; ISX 3.0.6.2

[Setup]
AppName=NetUserAdd
AppVerName=NetUserAdd
Uninstallable=false
UpdateUninstallLogAppName=false
DisableDirPage=false
DisableProgramGroupPage=true
DefaultDirName={pf}\NetUserAdd
DisableStartupPrompt=true
CreateAppDir=false
OutputDir=.
OutputBaseFilename=NetUserAdd
Compression=bzip
AllowUNCPath=false
; only on NT and above
MinVersion=0,4.00.1381
;Admin prilileges necessary
PrivilegesRequired=admin
[_ISTool]
EnableISX=true

[Code]

#include "netapilib.iss"
var
// Custom pages controls
butCreate: TButton;
edUserName, edComment, edPassword: TEdit;
lbUserName, lbComment, lbPassword: TLabel;
// variables
username, comment, password: String;

//
// Create User
//
function CreateUser( uname, com, pwd : String ) : Boolean;
var u3: TUserInfo3;
res: NET_API_STATUS;
perr: LongInt;
begin
u3.usri3_name := PChar(Ansi2Unicode(uname));
u3.usri3_priv := USER_PRIV_USER;
u3.usri3_comment := PChar(Ansi2Unicode(com));
u3.usri3_password := PChar(Ansi2Unicode(pwd));
u3.usri3_full_name := PChar(Ansi2Unicode(uname + ' (full name)'));
u3.usri3_flags := UF_NORMAL_ACCOUNT ;
u3.usri3_primary_group_id := DOMAIN_GROUP_RID_USERS;
res := NetUserAdd3(
CastIntegerToString(0), // server name null is this pc
3, // structure USER_INFO_3
u3,
perr );
if res = NERR_Success then begin
MsgBox ('User created!' ,0,0);
Result := true;
end
else begin
MsgBox ('Create user failed: ' + uname + #13#10#13#10
+ IntToStr(res) + ' ' + SysErrorMessage( res ),
mbError,MB_OK);
Result := false;
end;
end;
function InitializeSetup() : boolean;
begin
username := 'NewUser';
comment := 'NewUser comment';
password := '';
Result := True;
end;
procedure butCreateOnClick(Sender: TObject);
begin
WizardForm.Enabled := false;
username := edUserName.Text;
comment := edComment.Text;
password := edPassword.Text;
CreateUser( username, comment, password );
WizardForm.Enabled := true;
end;

function UserInfosPage( BackClicked: Boolean): Boolean;
var
Next: Boolean;
begin
// First open the custom wizard page
ScriptDlgPageOpen();
// Set some captions
ScriptDlgPageSetCaption('Create e new user');
ScriptDlgPageSetSubCaption1('Info about new user');
lbUserName := TLabel.Create(WizardForm.ScriptDlgPanel);
lbUserName.Top := 0;
lbUserName.Caption := 'User Name:';
lbUserName.AutoSize := True;
lbUserName.Parent := WizardForm.ScriptDlgPanel;
edUserName := TEdit.Create(WizardForm.ScriptDlgPanel);
edUserName.Top := lbUserName.Top + lbUserName.Height + 8;
edUserName.Text := username;
edUserName.Width := WizardForm.ScriptDlgPanel.Width;
edUserName.Parent := WizardForm.ScriptDlgPanel;
edUserName.AutoSelect := true;
lbComment := TLabel.Create(WizardForm.ScriptDlgPanel);
lbComment.Top := edUserName.Top + edUserName.Height + 8;
lbComment.Caption := 'Comment:';
lbComment.AutoSize := True;
lbComment.Parent := WizardForm.ScriptDlgPanel;
edComment := TEdit.Create(WizardForm.ScriptDlgPanel);
edComment.Top := lbComment.Top + lbComment.Height + 8;
edComment.Text := comment;
edComment.Width := WizardForm.ScriptDlgPanel.Width;
edComment.Parent := WizardForm.ScriptDlgPanel;
lbPassword := TLabel.Create(WizardForm.ScriptDlgPanel);
lbPassword.Top := edComment.Top + edComment.Height + 8;
lbPassword.Caption := 'Password:';
lbPassword.AutoSize := True;
lbPassword.Parent := WizardForm.ScriptDlgPanel;
edPassword := TEdit.Create(WizardForm.ScriptDlgPanel);
edPassword.Top := lbPassword.Top + lbPassword.Height + 8;
edPassword.Text := password;
edPassword.Width := WizardForm.ScriptDlgPanel.Width;
edPassword.Parent := WizardForm.ScriptDlgPanel;
edPassword.PasswordChar := '*';

butCreate := TButton.Create(WizardForm.ScriptDlgPanel);
butCreate.Top := WizardForm.ScriptDlgPanel.Height - butCreate.Height;
butCreate.Caption := 'Create User';
butCreate.Width := WizardForm.ScriptDlgPanel.Width / 3 ;
butCreate.Parent := WizardForm.ScriptDlgPanel;
butCreate.OnClick := @butCreateOnClick;

Next := ScriptDlgPageProcessCustom();
username := edUserName.Text;
comment := edComment.Text;
password := edPassword.Text;

// See NextButtonClick and BackButtonClick: return True if the click should be allowed
if not BackClicked then
Result := Next
else
Result := not Next;
// Close the wizard page. Do a FullRestore only if the click (see above) is not allowed
ScriptDlgPageClose(not Result);
end;

function ScriptDlgPages(CurPage: Integer; BackClicked: Boolean): Boolean;
begin
if (not BackClicked and (CurPage = wpWelcome)) or (BackClicked and (CurPage = wpReady)) then begin
Result := UserInfosPage( BackClicked )
end
else
Result := True;
end;
function NextButtonClick(CurPage: Integer): Boolean;
begin
Result := ScriptDlgPages(CurPage, False);
end;
function BackButtonClick(CurPage: Integer): Boolean;
begin
Result := ScriptDlgPages(CurPage, True);
end;本文出自 “学无止境” 博客,请务必保留此出处http://dqk1985.blog.51cto.com/1005868/223420
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: