0
点赞
收藏
分享

微信扫一扫

右键新建->你喜欢的文件


 大家都知道在桌面右键可以新建文件,但是谁知道如何新建自己喜欢的文件呢?

 本程序给你答案。

代码如下:

private void btnSure_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "" || textBox4.Text.Trim() == "")
{
MessageBox.Show("输入有误请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox4.Focus();
return;
}
RegistryKey key1 = Registry.ClassesRoot.CreateSubKey(textBox4.Text);
key1.SetValue("",textBox1.Text);
RegistryKey key2 = key1.CreateSubKey("ShellNew");
key2.SetValue("NullFile","");
key1.Close();
key2.Close();
key1 = Registry.ClassesRoot.CreateSubKey(textBox1.Text);
key1.SetValue("",textBox1.Text+"文件");
key2 = key1.CreateSubKey("DefaultIcon");
key2.SetValue("",textBox3.Text+",1");
key2.Close();
key2 = key1.CreateSubKey("shell//open//command");
key2.SetValue("",textBox2.Text);
MessageBox.Show("自定义文件添加完毕!", "ok", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void btnLogOff_Click(object sender, EventArgs e)
{
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";//调用cmd执行dos命令
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;//是否显示cmd窗口
process.Start();
process.StandardInput.WriteLine("shutdown.exe -l");
process.StandardInput.WriteLine("exit");
}

输入信息后,点击注销。重新登录到window后就可以新建你刚才输入的文件类型了。

其实本程序的实质是对注册表的操作。


 

举报

相关推荐

0 条评论