在非XP操作系统下模拟的LockWorkStation函数
作者:Delphiscn
**************************************************************
*code by Delphiscn(cnBlaster#sohu.com)http://blog.csdn.net/delphiscn
*Application's Password: administrators **************************************************************
unit unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, SUIForm, StdCtrls, SUIEdit, SUIButton, Inifiles, SUIDlg;
type
TForm1 = class(TForm)
Form1: TsuiForm;
InputPassword: TsuiEdit;
OK: TsuiButton;
ChangePassword: TsuiButton;
SavePassword: TsuiButton;
PasswordNew: TsuiEdit;
CloseApplication: TsuiButton;
Notes: TLabel;
Message: TsuiMessageDialog;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure OKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SavePasswordClick(Sender: TObject);
procedure CloseApplicationClick(Sender: TObject);
procedure ChangePasswordClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key=VK_F4) and ([ssALT]=shift) then key:=0;
end;
procedure Lock;
var
hDesktop:THandle;
wndHandle:THandle;
wndClass:array[0..50]of Char;
begin
hDesktop:=FindWindow('Progman',nil);
showWindow(hDesktop,SW_Hide);
StrPCopy(@wndClass[0],'shell_TrayWnd');
wndHandle:=FindWindow(@wndClass[0],nil);
ShowWindow(wndHandle,SW_HIDE);
end;
procedure UnLock;
var
hDesktop:THandle;
wndHandle:THandle;
wndClass:array[0..50]of Char;
begin
hDesktop:=FindWindow('Progman',nil);
showWindow(hDesktop,SW_show);
StrPCopy(@wndClass[0],'shell_TrayWnd');
wndHandle:=FindWindow(@wndClass[0],nil);
ShowWindow(wndHandle,SW_show);
end;
procedure TForm1.OKClick(Sender: TObject);
var
Filename:String;
Reguser:TIniFile;
begin
Filename:=ExtractFilePath(paramstr(0))+'Reguser.ini';
Reguser:=TIniFile.Create(Filename);
IF Reguser.ReadString('程序参数','Password','')=Inputpassword.Text
then
begin
unlock;
Changepassword.Enabled:=True;
CloseApplication.Enabled:=True;
end
else
begin
Message.Text:='Sorry Your Password Not Right';
Message.ShowModal;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Changepassword.Enabled:=False;
PasswordNew.Enabled:=False;
CloseApplication.Enabled:=False;
Notes.Enabled:=False;
Savepassword.Enabled:=False;
lock;
end;
procedure TForm1.SavePasswordClick(Sender: TObject);
var
Filename:String;
Reguser:TIniFile;
begin
Filename:=ExtractFilePath(paramstr(0))+'Reguser.ini';
Reguser:=TIniFile.Create(Filename);
Reguser.WriteString('程序参数','Password',PasswordNew.Text);
Message.Text:='You Have Changed Password';
Message.ShowModal;
end;
procedure TForm1.CloseApplicationClick(Sender: TObject);
begin
close;
end;
procedure TForm1.ChangePasswordClick(Sender: TObject);
begin
Notes.Enabled:=True;
passwordNew.Enabled:=True;
SavePassword.Enabled:=True;
end;
end.
Reguser.ini
---------------------------------------------------------------------------------
[程序参数]
Password=administrators
---------------------------------------------------------------------------------
程序下载
CSDN审核中......................
XP下LockWorkStation函数的调用
Rundll32.exe USER32.dll ,LockWorkStation
本文地址:http://com.8s8s.com/it/it4318.htm