在学校机房的管理中,让老师和机房管理人员头痛的一个问题是,学生不按照老师的要求完成本节课的内容,而在玩游戏或运行一些非法程序(若大一个机房靠一两个教师是难与控制学生的)。 本人经过对策略编辑器的分析,与及对注册表的反复推敲,找出了WIN9X中控制对未授权用运行程序的限制,希望能对你有所帮助。
原理:在注册表中有一个关键字('Hkey_current_usersoftwaremicrosoftwindowscurrentversionpoliciesexplorerrestrictrun'),当此关键字存在,且此关键字中有一个二进制数(restrictrun),当把二进制数的值为设置为1时,表明可限制当前用使用权限,在注册表中还不一关键字('softwaremicrosoftwindowscurrentversionpoliciesexplorerrestrictrun'),此关键字中,存放有字符串值,字符串的值为授权可以使用的程序名(注、此名字只能是程序名,不能含路径),字符串名字可按数值序列新建,在WIN9X中,你只需要通过
“Regedit.exe”程序添加('softwaremicrosoftwindowscurrentversionpoliciesexplorer')关键字,然后在添加('softwaremicrosoftwindowscurrentversionpoliciesexplorerrestrictrun')关键字,在此关键字中添加相应的程序名就可以设置WIN9X中应用程序的使用权限。
在Delphi 实现
步骤:
1、新建一个窗口,在窗口中加入一个BUTTON,名字为BUTTON1功能为设置使用在WIN9X程序权限。在BUTTON1click中加入如下代码。
procedure TForm1. BUTTON1 Click(Sender: TObject);
var
myReg:TRegistry;
i:integer;
begin
myreg:=tRegistry.Create ;
myreg.RootKey:=HKEY_CURRENT_USER;
myreg.OpenKey('softwaremicrosoftwindowscurrentversionpoliciesexplorer',true);//如果没有这个关键字则新建并打开。
myreg.writeinteger('restrictrun',1);//把restrictrun的值设置为1。
myreg.OpenKey('softwaremicrosoftwindowscurrentversionpoliciesexplorerrestrictrun',true);
if opendialog1.Execute then
begin
assignfile(right_file, opendialog1.FileName );
reset(right_file);//通过权限文件设置WIN9X使用程序权限。
readln(right_file,s_r);
myreg.WriteString('1',s_r);//写入一个可以使用程序
//
例:myreg.WriteString('1',’winword.exe’)
i:=1;
while not eof(right_file) do
begin
i:=i+1;
readln(right_file,s_r);
myreg.WriteString(inttostr(i),s_r);
end;
i:=i+1;
while myreg.ValueExists(inttostr(i)) do
begin //删除在注册表中添加进的多余的程序。
myreg.DeleteValue(inttostr(i));
i:=i+1;
end;
end;
closefile(right_file);
myreg.CloseKey;
end;
2、可以在窗口(FORM)中加入另一个BUTTON,名字为BUTTON2,功能为取消使用在WIN9X程序权限。在BUTTON2click中加入如下代码。
procedure TForm1.BitBtn2Click(Sender: TObject);
var
myReg:TRegistry;
begin
myreg:=tRegistry.Create ;
myreg.RootKey:=HKEY_CURRENT_USER;
myreg.OpenKey('softwaremicrosoftwindowscurrentversionpoliciesexplorer',true);
myreg.writeinteger('restrictrun',0);
myreg.CloseKey;
end;
原理:在注册表中有一个关键字('Hkey_current_usersoftwaremicrosoftwindowscurrentversionpoliciesexplorerrestrictrun'),当此关键字存在,且此关键字中有一个二进制数(restrictrun),当把二进制数的值为设置为1时,表明可限制当前用使用权限,在注册表中还不一关键字('softwaremicrosoftwindowscurrentversionpoliciesexplorerrestrictrun'),此关键字中,存放有字符串值,字符串的值为授权可以使用的程序名(注、此名字只能是程序名,不能含路径),字符串名字可按数值序列新建,在WIN9X中,你只需要通过
“Regedit.exe”程序添加('softwaremicrosoftwindowscurrentversionpoliciesexplorer')关键字,然后在添加('softwaremicrosoftwindowscurrentversionpoliciesexplorerrestrictrun')关键字,在此关键字中添加相应的程序名就可以设置WIN9X中应用程序的使用权限。
在Delphi 实现
步骤:
1、新建一个窗口,在窗口中加入一个BUTTON,名字为BUTTON1功能为设置使用在WIN9X程序权限。在BUTTON1click中加入如下代码。
procedure TForm1. BUTTON1 Click(Sender: TObject);
var
myReg:TRegistry;
i:integer;
begin
myreg:=tRegistry.Create ;
myreg.RootKey:=HKEY_CURRENT_USER;
myreg.OpenKey('softwaremicrosoftwindowscurrentversionpoliciesexplorer',true);//如果没有这个关键字则新建并打开。
myreg.writeinteger('restrictrun',1);//把restrictrun的值设置为1。
myreg.OpenKey('softwaremicrosoftwindowscurrentversionpoliciesexplorerrestrictrun',true);
if opendialog1.Execute then
begin
assignfile(right_file, opendialog1.FileName );
reset(right_file);//通过权限文件设置WIN9X使用程序权限。
readln(right_file,s_r);
myreg.WriteString('1',s_r);//写入一个可以使用程序
//
例:myreg.WriteString('1',’winword.exe’)
i:=1;
while not eof(right_file) do
begin
i:=i+1;
readln(right_file,s_r);
myreg.WriteString(inttostr(i),s_r);
end;
i:=i+1;
while myreg.ValueExists(inttostr(i)) do
begin //删除在注册表中添加进的多余的程序。
myreg.DeleteValue(inttostr(i));
i:=i+1;
end;
end;
closefile(right_file);
myreg.CloseKey;
end;
2、可以在窗口(FORM)中加入另一个BUTTON,名字为BUTTON2,功能为取消使用在WIN9X程序权限。在BUTTON2click中加入如下代码。
procedure TForm1.BitBtn2Click(Sender: TObject);
var
myReg:TRegistry;
begin
myreg:=tRegistry.Create ;
myreg.RootKey:=HKEY_CURRENT_USER;
myreg.OpenKey('softwaremicrosoftwindowscurrentversionpoliciesexplorer',true);
myreg.writeinteger('restrictrun',0);
myreg.CloseKey;
end;
浙公网安备 33010602011771号