• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi如何以管理员权限运行程序

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

        IT 时常会碰到一个困扰,就是当用户权限太大时,容易出现各种问题,比如乱装软件,病毒等问题。但权限太小,也很麻烦,时常要IT给用户装一些允许的软件。一下程序允许用户以管理员的身份安装IT允许用户自己安装的软件而不用给用户管理员密码。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

 type
_STARTUPINFOW = record
cb: DWORD;
lpReserved: LPWSTR;
lpDesktop: LPWSTR;
lpTitle: LPWSTR;
dwX: DWORD;
dwY: DWORD;
dwXSize: DWORD;
dwYSize: DWORD;
dwXCountChars: DWORD;
dwYCountChars: DWORD;
dwFillAttribute: DWORD;
dwFlags: DWORD;
wShowWindow: Word;
cbReserved2: Word;
lpReserved2: PByte;
hStdInput: THandle;
hStdOutput: THandle;
hStdError: THandle;
end;
STARTUPINFOW = _STARTUPINFOW;
var
  Form1: TForm1;

implementation

{$R *.dfm}

function CreateProcessWithLogonW(lpUserName, lpDomain, lpPassword: LPCWSTR;
dwLogonFlags: DWORD; lpApplicationName: LPCWSTR; lpCommandLine: LPWSTR;
dwCreationFlags: DWORD; lpEnvironment: Pointer; lpCurrentDirectory: LPCWSTR;
const lpStartupInfo: STARTUPINFOW; var lpProcessInformation: PROCESS_INFORMATION): BOOL; stdcall;
external advapi32 Name 'CreateProcessWithLogonW'

procedure TForm1.FormCreate(Sender: TObject);
var
STARTUPINFO: StartupInfoW;
ProcessInfo: TProcessInformation;
AUser, ADomain, APass, AExe: WideString;
const
LOGON_WITH_PROFILE = $00000001;
LOGON_NETCREDENTIALS_ONLY = $00000002;
begin
FillChar(STARTUPINFO, SizeOf(StartupInfoW), 0);
STARTUPINFO.cb := SizeOf(StartupInfoW);
STARTUPINFO.dwFlags := STARTF_USESHOWWINDOW;
STARTUPINFO.wShowWindow := SW_SHOW;
AUser := 'administrator';
ADomain := 'msic.com.cn';
APass := 'xxxxxx';
AExe := '\\it\tools\install_flash_player_ax.exe';
if not CreateProcessWithLogonW(PWideChar(AUser), PWideChar(ADomain),
PWideChar(APass),
LOGON_WITH_PROFILE, nil, PWideChar(AExe),
NORMAL_PRIORITY_CLASS, nil, nil, STARTUPINFO, ProcessInfo) then
RaiseLastOSError;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
close;
end;

end.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
2.Matlab数值数组及其运算发布时间:2022-07-18
下一篇:
MATLAB入门(一)数组发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap