急!!!求方法:编程控制Windows 2000 Server或Windows 2003 Server自动关机(100分)

  • 主题发起人 主题发起人 无名爱好者
  • 开始时间 开始时间

无名爱好者

Unregistered / Unconfirmed
GUEST, unregistred user!
见标题,急等!!!
 
//获取计算机的关闭、注销、重启的权限<br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br>&nbsp; hToken : THandle;<br>&nbsp; Tkp : TTokenPrivileges;<br>&nbsp; Zero:DWORD;<br>begin<br>&nbsp; OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TOKEN_QUERY,hToken);<br>&nbsp; LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);<br>&nbsp; Tkp.PrivilegeCount :=1;<br>&nbsp; Tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br>&nbsp; AdjustTokenPrivileges(hToken,False,Tkp,SizeOf(TTokenPrivileges),nil,Zero); &nbsp;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; WSAData: TWSAData;<br>&nbsp; MSocket: TSocket;<br>&nbsp; SockAddrIn: TSockAddrIn;<br>&nbsp; RetVal, OptVal, i: Integer;<br>&nbsp; MacAddr: array[0..5] of Byte;<br>&nbsp; MagicData: array[0..101] of Byte;<br>&nbsp; Position: Longint;<br>&nbsp; SAddr:string;<br>begin<br>&nbsp; &nbsp; if Edit1.Text =panel1.Caption then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Timer1.Enabled :=False;<br>&nbsp; &nbsp; &nbsp; if Combobox1.Text ='注销' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ExitWindowsEx(EWX_LOGOFF,0);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if Combobox1.Text ='重新启动' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ExitWindowsEx(EWX_REBOOT,0);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if Combobox1.Text ='关闭计算机' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ExitWindowsEx(EWX_SHUTDOWN or EWX_POWEROFF,0);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>end;
 

Similar threads

S
回复
0
查看
816
SUNSTONE的Delphi笔记
S
S
回复
0
查看
735
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部