2017-04-01 64 views
0

几年前,我编写了一个C程序,该程序可以用0x0像素调色板打开Microsoft Paint。它在产生Paint之前在注册表中写入了值。我创建了一个C#版本:MS Paint注册表设置不起作用

using System; 
using Microsoft.Win32; 

namespace PaintZeroCanvas 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      const string userRoot = "HKEY_CURRENT_USER"; 
      const string subkey = "Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"; 
      const string keyName = userRoot + "\\" + subkey; 

      Registry.SetValue(keyName, "BMPWidth", 0); 
      Registry.SetValue(keyName, "BMPHeight", 0); 
      Registry.CurrentUser.Flush(); 

      System.Diagnostics.Process.Start(Environment.SystemDirectory + "\\mspaint.exe"); 
     } 
    } 
} 

注册表被修改,但Paint以前面保存的大小打开。这些键名也出现在HKEY_USERS中,但是也不在那里工作。我拥有管理权限,拥有对两个位置的FullControl访问权限,并尝试使用管理权限运行应用程序。

如果我手动启动画图,更改调色板大小并关闭它,这些值将写入这两个位置。

我正在运行64位Windows 10并使用Visual Studio 2015社区版本,并使用.NET Framework 4.5.2。

+0

您以前使用Paint program的实现的未公开的方面。该程序自那时以来一直在更新,现在使用不同的方案,也没有记录,用于存储用户配置。似乎仍然有一些旧的注册表位置的使用,但这并不意味着这些是决定性的因素。在任何情况下,Stack Overflow都是关于编程的问题,而你的问题其实是一个关于如何使用Paint的问题,伪装成一个关于编程的问题。 –

+0

如果我是Paint,我肯定不会接受这个设置,因为它对我的用户完全没用。 – TaW

+0

“Stack Overflow是程序员学习,分享知识,推动事业发展的最大的在线社区。”我想每个社区都有他们的邻居...... –

回答

0

我认为你需要打开注册表64位,喜欢这里:

Registry access with C# and "BUILD x86" on a 64bit machine

注意:下面的代码是未经测试!

using System; 
using Microsoft.Win32; 

namespace PaintZeroCanvas 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      const string userRoot = "HKEY_CURRENT_USER"; 
      const string subkey = "Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Paint\\View"; 
      const string keyName = userRoot + "\\" + subkey; 

      RegistryKey registryKey = 
      RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, 
      RegistryView.Registry64).OpenSubKey(keyName); 


      registryKey.SetValue("BMPWidth", 0); 
      registryKey.SetValue("BMPHeight", 0); 

      System.Diagnostics.Process.Start(Environment.SystemDirectory + "\\mspaint.exe"); 
     } 
    } 
}