TO:chenxz,我正在做一个远程关机程序,需要先登录上对方。我想用程序方式以管理员登录,chenxz你能帮我看看下面的程序吗?
注:本地机名:LJZ
对方电脑名:WQW
对方user:administrator PASSWORD:microsoft
谢谢!
procedure AdjustToken();
var
hdlProcessHandle : Cardinal;
hdlTokenHandle : Cardinal;
tmpLuid : Int64;
tkpPrivilegeCount : Int64;
tkp : TOKEN_PRIVILEGES;
tkpNewButIgnored : TOKEN_PRIVILEGES;
lBufferNeeded : Cardinal;
Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;
begin
hdlProcessHandle := GetCurrentProcess;
OpenProcessToken(hdlProcessHandle,
(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY),
hdlTokenHandle);
// Get the LUID for shutdown privilege.
LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);
Privilege[0].Luid := tmpLuid;
Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1; // One privilege to set
tkp.Privileges[0] := Privilege[0];
// Enable the shutdown privilege in the access token of this
// process.
AdjustTokenPrivileges(hdlTokenHandle,
False,
tkp,
Sizeof(tkpNewButIgnored),
tkpNewButIgnored,
lBufferNeeded);
end;
procedure Tserver.Button1Click(Sender: TObject);
var
ReqCode:array[0..29] of char;
ReqCodeStr:string;
aa:TNetResource;
retval : integer;
begin
aa.dwScope := RESOURCE_CONNECTED;
aa.dwType := RESOURCETYPE_ANY;
aa.lpLocalName := 'ljz';
aa.lpRemoteName := 'wqw';
aa.lpProvider := Nil;
RetVal := WNetAddConnection2(aa,'microsoft','administrator',0);
showmessage(inttostr(retval));
AdjustToken;
InitiateSystemshutdown('wqw','HELLO',10,true,true);
end;