怎样在delphi中用命令控制计算机的重起和关机?
解决方案 »
- 如何配置,可以连接到数据,进行grid读表操作
- 1.sql2000 的连接属于tcp? 2.如何测试本机SocketServer可以建立多少tcp连接?(用clientsocket和socketserver写的网络通讯程序)
- Borland为什么对日文IME特殊对待呢?
- combobox,dbcombobox的用法问题
- 关于delphi5 record(结构)成员内存对齐问题?
- 数据插入的问题
- 大麻烦,数据更新出错,用NULL不行,用''不行
- actionlist做权限控制,oracle的布尔型疑问
- DelphiXE6 Android WebBrowser报Segmentation fault (11).
- 请问一下哪里有李维的delphi5.X ado/mts/com+书籍下载?
- 如何由Delphi的DLL返回一个不定长的字符串给C++?在线等侯。
- 3个零散的问题,时间紧,任务急,希望大家帮帮忙。
BOOL ExitWindowsEx(
UINT uFlags, // shutdown operation
DWORD dwReason // shutdown reason
);
uFlags取值:
关机 EWX_POWEROFF
关闭windows EWX_SHUTDOWN
重启:EWX_REBOOT
2000下麻烦一些了.
unit main;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DsFancyButton;type
TForm1 = class(TForm)
EdtRomateName: TEdit;
BtnShutDown: TButton;
procedure BtnShutDownClick(Sender: TObject);
private
{ Private declarations }
function EnablePrivilege(lpSystemName:PChar; lpName:PChar):Bool;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }function TForm1.EnablePrivilege(lpSystemName, lpName: PChar): Bool;
var
hToken : THANDLE;
fOk : Bool;
fTest : Bool;
tp, tpNew : TOKEN_PRIVILEGES;
ReturnLength : Cardinal;
begin
fOk := FALSE;
if OpenProcessToken(GetCurrentProcess,(TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY),hToken) then
begin
tp.PrivilegeCount := 1;
if not (LookupPrivilegeValue(lpSystemName,lpName,tp.Privileges[0].Luid)) then
ShowMessage('Can not lookup privilege value!');
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
if not (AdjustTokenPrivileges(hToken,FALSE,tp,sizeof(tp),tpNew,ReturnLength)) then
ShowMessage('Can not adjust privilege value.');
if GetLastError = ERROR_SUCCESS then
fOk := TRUE
else
fOK := FALSE;
CloseHandle(hToken);
end;
Result := fOk;
end;procedure TForm1.BtnShutDownClick(Sender: TObject);
var
RemoteShutDown : Bool;
ComputerName : PChar;begin
if EdtRomateName.Text <> '' then
begin
ComputerName := PChar(EdtRomateName.Text;
EnablePrivilege(ComputerName,'SeRemoteShutdownPrivilege');
{此句EnablePrivilege(nil,'SeShutdownPrivilege');
下一句改为RemoteShutDown :=InitiateSystemShutdown(nil,nil,0,TRUE,FALSE);将实现本地关机}
RemoteShutDown :=InitiateSystemShutdown(ComputerName ,nil,0,TRUE,FALSE);
{将InitiateSystemShutdown函数的最后一个参数改为TRUE将实现restart}
if RemoteShutDown then
ShowMessage('(远程)关机成功!')
else
ShowMessage('(远程)关机失败!');
end;
end;end.