第一个解决者,百分送上!改注册表,在一定时间内只能运行指定程序,知道用组策略管理器,可以实现,不过我想用编程的方法。
自由程序员 C#领域优质创作者 博客专家认证 2006-11-20 11:39:30 改注册表,在一定时间内只能运行指定程序,知道用组策略管理器,可以实现,不过我想用编程的方法。
以下是我的代码,但是不能达到目的,已经研究过N遍了,没有找到问题,请高手,指教。谢谢。第一个解决者,百分送上!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace restrict
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
RegistryKey hkcu = Registry.CurrentUser;
RegistryKey cu = hkcu.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\RestrictRun");
RegistryKey cu1 = hkcu.CreateSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\Policies\Explorer");
cu1.SetValue("RestrictRun", 1);
cu.SetValue("**delvals.", " ");
cu.SetValue("1", "notepad.exe");
cu.SetValue("2", "bitcomet.exe");
cu.SetValue("3", "gpedit.msc");
cu.SetValue("4", "regedit.exe");
cu.SetValue("5", "tmshell.exe");
cu.SetValue("6", "kav.exe");
cu.SetValue("7", "TTraveler.exe");
cu.SetValue("8", "iexplore.exe");
cu.SetValue("9", "mmc.exe");
cu.SetValue("10", "restrict.exe");
hkcu.Close();
}
int delflag = 1;
public void delres()//删除相关注册表项,清除限制
{
RegistryKey hkcu = Registry.CurrentUser;
RegistryKey hklm = Registry.LocalMachine;
RegistryKey cu = hkcu.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\Policies", true);
cu.DeleteSubKeyTree("Explorer");
hkcu.Close();
delflag = 0;
}
private void timer1_Tick(object sender, EventArgs e)
{
if ((DateTime.Now.Hour >= 12)&&(DateTime.Now.Hour <= 14)&&(delflag==1)) //中午12点到下午2点之间,取消限制
{
delres();
}
}
}
}