小弟是用DELPHI搞控制的,编了一个关机的程序,在正常情况下可以实现.但只要Facon Server程序运行着就不行了,各位大哥请帮助。
unit uexit;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ShellAPI, IniFiles, Buttons ;type
Tfrmexit = class(TForm)
Image1: TImage;
ComboBox1: TComboBox;
Label1: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox1KeyPress(Sender: TObject; var Key: Char);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
procedure ReadSource;
procedure WriteSource;
procedure autodisplay;
{ Private declarations }
public
{ Public declarations }
end;var
frmexit: Tfrmexit;const
OrignWidth =800;
OrignHeight=600;
implementation
{$R *.dfm}procedure Tfrmexit.FormClose(Sender: TObject; var Action: TCloseAction);
begin
AcTion := CaFree ;
frmexit := nil;end;procedure Tfrmexit.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.Text = 'ShutDown' then
label1.Caption :='Are you close windows?';
if ComboBox1.Text = 'Reset Computer' then
label1.Caption :='Are you reset windows?';end;procedure Tfrmexit.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then
Bitbtn1Click(self);
end;procedure Tfrmexit.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
VK_ESCAPE:
close;
end;
end;procedure Tfrmexit.FormCreate(Sender: TObject);
begin
autodisplay;
// scaleby()
{
scaled:=true;
if (screen.Width<>orignwidth)then
begin
height:=longint(height)*longint(screen.height)div orignheight;
width:=longint(width)*longint(screen.width)div orignwidth;
scaleby(screen.Width,screen.Height);
end;
}
label1.Caption :='Are you close windows?';
end;procedure Tfrmexit.ReadSource;
begin
end;procedure Tfrmexit.WriteSource;
begin
end;procedure Tfrmexit.BitBtn1Click(Sender: TObject);
var
hToken: THANDLE;
Tkp:TOKEN_PRIVILEGES;
Nothing:Cardinal;
begin
// 強制關閉,其它執行中的應用程式資料並不會被儲存
//ExitWindowsEx(EWX_LOGOFF | EWX_FORCE,0); // 登出, 重新登入使用者
//ExitWindowsEx(EWX_REBOOT | EWX_FORCE,0); // 重新開機
//ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,0); // 結束作業系統
//ExitWindowsEx(EWX_POWEROFF | EWX_FORCE,0); // 結束作業系統,並關閉電 if ComboBox1.Text = 'ShutDown' then
begin
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY, hToken);
LookupPrivilegeValue(nil, 'SeShutdownPrivilege',
tkp.Privileges[0].Luid);
tkp.PrivilegeCount:=1;
tkp.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, tkp, 0, nil, Nothing);
ExitWindowsEx(EWX_FORCE, 0);
ExitWindowsEx(EWX_POWEROFF,0);
end; if ComboBox1.Text = 'Reset Computer' then
begin
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY, hToken);
LookupPrivilegeValue(nil, 'SeShutdownPrivilege',
tkp.Privileges[0].Luid);
tkp.PrivilegeCount:=1;
tkp.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, tkp, 0, nil, Nothing);
ExitWindowsEx(EWX_REBOOT, 0)
end;
{ case RadioGroup1.ItemIndex of
0: application.Terminate;
1: Win32Check(ExitWindowsEx(EWX_SHUTDOWN,0)); //退出,然后关闭系统
2: Win32Check(ExitWindowsEx(EWX_REBOOT,0)); //退出,然后重启系统
3: Win32Check(ExitWindows(0,0));//退出,然后以另一个用户登陆
end;
}
end;procedure Tfrmexit.BitBtn2Click(Sender: TObject);
begin
close;
end;procedure Tfrmexit.autodisplay;
begin scaled:=true;
if (screen.Width<>orignwidth)then
begin
height:=longint(height)*longint(screen.height)div orignheight;
width:=longint(width)*longint(screen.width)div orignwidth;
scaleby(screen.Width,screen.Height);
end;
end;
end.
unit uexit;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ShellAPI, IniFiles, Buttons ;type
Tfrmexit = class(TForm)
Image1: TImage;
ComboBox1: TComboBox;
Label1: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ComboBox1Change(Sender: TObject);
procedure ComboBox1KeyPress(Sender: TObject; var Key: Char);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
procedure ReadSource;
procedure WriteSource;
procedure autodisplay;
{ Private declarations }
public
{ Public declarations }
end;var
frmexit: Tfrmexit;const
OrignWidth =800;
OrignHeight=600;
implementation
{$R *.dfm}procedure Tfrmexit.FormClose(Sender: TObject; var Action: TCloseAction);
begin
AcTion := CaFree ;
frmexit := nil;end;procedure Tfrmexit.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.Text = 'ShutDown' then
label1.Caption :='Are you close windows?';
if ComboBox1.Text = 'Reset Computer' then
label1.Caption :='Are you reset windows?';end;procedure Tfrmexit.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then
Bitbtn1Click(self);
end;procedure Tfrmexit.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
VK_ESCAPE:
close;
end;
end;procedure Tfrmexit.FormCreate(Sender: TObject);
begin
autodisplay;
// scaleby()
{
scaled:=true;
if (screen.Width<>orignwidth)then
begin
height:=longint(height)*longint(screen.height)div orignheight;
width:=longint(width)*longint(screen.width)div orignwidth;
scaleby(screen.Width,screen.Height);
end;
}
label1.Caption :='Are you close windows?';
end;procedure Tfrmexit.ReadSource;
begin
end;procedure Tfrmexit.WriteSource;
begin
end;procedure Tfrmexit.BitBtn1Click(Sender: TObject);
var
hToken: THANDLE;
Tkp:TOKEN_PRIVILEGES;
Nothing:Cardinal;
begin
// 強制關閉,其它執行中的應用程式資料並不會被儲存
//ExitWindowsEx(EWX_LOGOFF | EWX_FORCE,0); // 登出, 重新登入使用者
//ExitWindowsEx(EWX_REBOOT | EWX_FORCE,0); // 重新開機
//ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,0); // 結束作業系統
//ExitWindowsEx(EWX_POWEROFF | EWX_FORCE,0); // 結束作業系統,並關閉電 if ComboBox1.Text = 'ShutDown' then
begin
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY, hToken);
LookupPrivilegeValue(nil, 'SeShutdownPrivilege',
tkp.Privileges[0].Luid);
tkp.PrivilegeCount:=1;
tkp.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, tkp, 0, nil, Nothing);
ExitWindowsEx(EWX_FORCE, 0);
ExitWindowsEx(EWX_POWEROFF,0);
end; if ComboBox1.Text = 'Reset Computer' then
begin
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY, hToken);
LookupPrivilegeValue(nil, 'SeShutdownPrivilege',
tkp.Privileges[0].Luid);
tkp.PrivilegeCount:=1;
tkp.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, tkp, 0, nil, Nothing);
ExitWindowsEx(EWX_REBOOT, 0)
end;
{ case RadioGroup1.ItemIndex of
0: application.Terminate;
1: Win32Check(ExitWindowsEx(EWX_SHUTDOWN,0)); //退出,然后关闭系统
2: Win32Check(ExitWindowsEx(EWX_REBOOT,0)); //退出,然后重启系统
3: Win32Check(ExitWindows(0,0));//退出,然后以另一个用户登陆
end;
}
end;procedure Tfrmexit.BitBtn2Click(Sender: TObject);
begin
close;
end;procedure Tfrmexit.autodisplay;
begin scaled:=true;
if (screen.Width<>orignwidth)then
begin
height:=longint(height)*longint(screen.height)div orignheight;
width:=longint(width)*longint(screen.width)div orignwidth;
scaleby(screen.Width,screen.Height);
end;
end;
end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货