Delphi -- CreateProcess函数调用示例

procedure TfmMain.Login;
var
  si:STARTUPINFO;
  pi:PROCESS_INFORMATION;
  CommandLine:String;
  ProcessFileName:string;
begin
  if (Trim(edtLoginName.Text)='') or (Trim(edtPassword.Text)='') then
  begin
    MsgBoxError(Handle,'请输入用户名及密码!');
    Exit;
  end;
  if not SemsClientApp.LoginManager.ValidateLogin(edtLoginName.Text,edtPassword.Text) then
  begin
    MsgBoxError(Handle,'用户名或密码错误,请重新输入!');
    Exit;
  end;
  try
    FillChar(si,SizeOf(si),0);
    FillChar(pi,SizeOf(pi),0);
    si.cb:=SizeOf(si);
    ProcessFileName:=SemsClientApp.AppPath+'\sems.bin';
    CommandLine:='"'+ProcessFileName+'" /S"'+Application.ExeName+'" /L"'+edtLoginName.Text+'" /P"'+edtPassword.Text+'"';
    if CreateProcess(PAnsiChar(ProcessFileName),PAnsiChar(CommandLine),nil,nil,False,0,nil,nil,si,pi) then
    Close;
  except
    MsgBoxError(Handle,'启动程序失败!');
  end;
end
posted @ 2008-09-26 10:17  Max Woods  阅读(3785)  评论(0编辑  收藏  举报