我在chen权限下(自己在系统中添加的用户,对D磁盘没有写的权限),我用软件怎么取得系统的admin权限,把文件写入磁盘?
多谢大侠指点,分不够可以在加!
多谢大侠指点,分不够可以在加!
解决方案 »
- 求jvrichedit 控件。
- 如何用程序操作gpedit.msc->计算机配置->安全设置->本地策略->安全选项->网络访问: 本地帐户的共享和安全模式?
- showmessage('在此一问,100分红包..(解答后,送20个QB.留下QQ即可)');
- delphi怎么显示UDP收到的字节呀?
- 如何实现一次性查询
- 判断文件大小
- Inside VCL第1-3章
- 请问StringGrid中可以填东西,然后发到数据库吗
- StrToInt('$'+ copy(src,SrcPos,2))这个是什么意思
- 用TDbChart画折线图的坐标问题?
- 服务器运行时报错“由于系统缓冲区空间不足或列队已满,不能执行套接字上的操作。” 是什么原因
- 再放个200分~~~~~~~
rl: Cardinal;
hToken: Cardinal;
tkp: TOKEN_PRIVILEGES;
begin
{获得用户关机特权,仅对Windows NT/2000/XP}
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken);
if LookupPrivilegeValue(nil, ’SeShutdownPrivilege’, tkp.Privileges[0].Luid) then
begin
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1;
AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);
end; 修改上面的代码应该就可
根据网上的资料,用LogonUser、CreateProcessAsUser这两个API,发现也要SE_TCB_NAME权限,且即使你是administrator,也很难在程序中得到要SE_TCB_NAME权限(我从未成功过)
后来终于找到一个M$未公开的函数:CreateProcessWithLogonW,它可以用administrator身份运行一个进程,以下是delphi的例程:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
LOGON_WITH_PROFILE = 1;
LOGON_NETCREDENTIALS_ONLY = 2;
function CreateProcessWithLogon(
lpUsername: PWChar;
lpDomain: PWChar;
lpPassword: PWChar;
dwLogonFlags: DWORD;
lpApplicationName: PWChar;
lpCommandLine: PWChar;
dwCreationFlags: DWORD;
lpEnvironment: Pointer;
lpCurrentDirectory: PWChar;
const lpStartupInfo: TStartupInfo;
var lpProcessInfo: TProcessInformation
): BOOL; stdcall;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function CreateProcessWithLogon; external advapi32 name 'CreateProcessWithLogonW';
procedure TForm1.Button1Click(Sender: TObject);
var
wUsername, wDomain, wPassword, wApplicationName: WideString;
pwUsername, pwDomain, pwPassword, pwApplicationName: PWideChar;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
wUsername := 'administrator';
wDomain := '';
wPassword := '123456';
wApplicationName := 'cmd.exe';
pwUsername := Addr(wUsername[1]);
pwDomain := Addr(wDomain[1]);
pwPassword := Addr(wPassword[1]);
pwApplicationName := Addr(wApplicationName[1]);
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
StartupInfo.cb := SizeOf(TStartupInfo);
if not CreateProcessWithLogon(pwUsername,pwDomain,pwPassword,LOGON_WITH_PROFILE,
pwApplicationName,nil,CREATE_DEFAULT_ERROR_MODE,
nil,nil,StartupInfo,ProcessInfo) then
RaiseLastOSError;
end;
end.其实,还有一个最简的方法,就是用系统的runas命令:
如:
runas /env /user:[email protected] "notepad \"my file.txt\""