如何编写代码立即生效而无需重启pc [英] how to write a code to take immediate effect without restart pc

查看:100
本文介绍了如何编写代码立即生效而无需重启pc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void Button10_Click(object sender, EventArgs e)
{
    Counter = 60;            
    try
    {
        if (voldis.Checked)
        {
            RegistryKey systemRegistry = Registry.CurrentUser.CreateSubKey("\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer");
            systemRegistry.SetValue("NoDrives", 0x3ffffff);
        }
        else if (volena.Checked)
        {
            RegistryKey systemRegistry = Registry.CurrentUser.CreateSubKey("\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer");
            systemRegistry.SetValue("NoDrives", 0);
        }
    }
    catch (Exception)
    {
        MessageBox.Show("Run this application as Admin to Enable or Disable", "@Need Administrator@");
    }
    DialogResult dialogResult = MessageBox.Show("PC have to reboot for effective", "Attention", MessageBoxButtons.YesNo);
    if (dialogResult == DialogResult.Yes)
    {
        Process.Start("shutdown", "-R -t 00"); //>>>how to write a code to take immediate effect without restart pc
    }
}

推荐答案

您的更改设置最好使用组策略设置,而不是您的代码。



此外,我认为您无法更改该设置并在不重新启动资源管理器的情况下生效。这只是意味着杀死Explorer.exe进程并重新启动它作为登录的人,而不是管理员。
The setting your changing is best set using Group Policy, not your code.

Also, I don't think you can change that setting and have it take effect without restarting Explorer. That just means killing the Explorer.exe process and restarting it as the person who logged in, not as an admin.


这篇关于如何编写代码立即生效而无需重启pc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆