Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 表单应用程序注册表项_C#_.net_Windows_Forms - Fatal编程技术网

C# 表单应用程序注册表项

C# 表单应用程序注册表项,c#,.net,windows,forms,C#,.net,Windows,Forms,我有 它正在标记这行代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Media; usi

我有

它正在标记这行代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media;
using Microsoft.Win32;

namespace Just_play_sounds_2
{
    public partial class Form1 : Form
    {

        private SoundPlayer soundPlayer;
        private RegistryKey reg;

        public Form1()
        {
            InitializeComponent();

            this.WindowState = FormWindowState.Minimized;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Hide();

            reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurentVersion\\Run", true);
            reg.SetValue("Play sounds", Application.ExecutablePath.ToString());
        }
    }
}
我已经尽了一切努力让它工作,但它就是不工作。我已经搜索了所有我能找到的东西,我真的需要一些帮助。如果你回答这个问题,你能告诉我我的注册表代码有什么问题吗

错误代码

reg.SetValue("Play sounds", Application.ExecutablePath.ToString());

通过你的编辑,我现在可以看到你的问题是重复的。最有可能是因为
reg
变量为
null
,而这又很可能是由于我已经向您提到的印刷错误造成的彼得·杜尼霍(Peter Duniho)

“发疯”和“行不通”不是有用的问题描述。也就是说,我建议您再看一看正在传递的子键字符串。它似乎有一个印刷错误。通过你的编辑,我现在可以看到你的问题是重复的。很可能是因为
reg
变量是
null
,而这又很可能是由于我前面提到的印刷错误。
System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Just play sounds 2
  StackTrace:
   at Just_play_sounds_2.Form1.Form1_Load(Object sender, EventArgs e) in D:\Projects\Just play sounds 2\Just play sounds 2\Form1.cs:line 37
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, Int32 wParam, Int32 lParam)
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at Just_play_sounds_2.Program.Main() in D:\Projects\Just play sounds 2\Just play sounds 2\Program.cs:line 19