[code=C#]             
  exefileway = GetFileway("Downdata.exe");//获取exe文件的
        全路径(D:\Downdata\Downdata\bin\Debug\Downdata.exe)
                    RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
                    object str = key.GetValue("Downdata Flags");
                    if ((key.GetValue("Downdata Flags") == null))
                    {
                        key.CreateSubKey("Downdata Flags");//创建键值
                        key.SetValue("Downdata Flags", exefileway);
                    }
                    else
                    {
                        key.SetValue("Downdata Flags", exefileway);//修改键值
                    }
                    key.Flush();
                    key.Close();
code]
   windows启动后,运行我的程序 报错:System.formaException:输入字符串的格式不正确
   并且我发现 在文件夹D:\Downdata\Downdata\bin\Debug得浏览栏里面输入   D:\Downdata\Downdata\bin\Debug\Downdata.exe才不会报错,在其他路劲下输入就会报这个错误。
  
   迷惑中,请求解答

解决方案 »

  1.   

    帮忙找找问题
    在文件夹D:\Downdata\Downdata\bin\Debug下的浏览栏里面输入  D:\Downdata\Downdata\bin\Debug\Downdata.exe才不会报错,在其他路劲下输入就会报这个错误。 这是我疑问,,,  我知道程序有错误啊,就问这个错误错在哪,我认为 应该是 在修改注册表时, 设置键值的地方有错误,请帮忙检查下
      

  2.   

    是你的程序有问题,可能是你的程序中某些地方使用了相对路径,但是你将程序自动启动的时候,开始位置可能是c:\windows,无法通过相对路径找到你要操作的文件。
      

  3.   

    那个 GetFileway()是
            public string GetFileway(string Filename)//获取应用程序的当前工作目录
            {
                string CurrentDir = System.IO.Directory.GetCurrentDirectory();
                string Fileway = CurrentDir + "\\" + Filename;
                return Fileway;
            }
      

  4.   

    #region  开机启动项
    /// 
    /// </summary>
    /// <param name="Started">是否启动</param>
    /// <param name="name">启动值的名称</param>
    /// <param name="path">启动程序的路径</param>
    public static void RunWhenStart(bool Started, string name, string path)
    {
    RegistryKey HKLM = Registry.LocalMachine;
    RegistryKey Run = HKLM.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
    if (Started == true)
    {
    try
    {
    if (Run.GetValue(name) != null)
    {
    if (Run.GetValue(name).ToString().Trim() != path)
    {      Run.SetValue(name, path);
    }
    }
    else
    {
    Run.SetValue(name, path);
    }HKLM.Close();
    }
    catch (Exception Err)
    {
           MessageBox.Show(Err.Message.ToString(), "MUS", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    }
    else
    {
    try
    {
          Run.DeleteValue(name);
          HKLM.Close();
    }
    catch (Exception)
    {
    //
                    }
    }

    #endregion ======以上代码来自互联网
      

  5.   

    相对路劲我也想到 可是我是用GetCurrentDirectory()取得程序的路劲的,并非用".\"