开机自从运行写的C#程序
我查到一个方法是这样写的,有些地方不太明白,希望有经验的给讲解一下
我的应用程序包的名称为:数据转送,程序的名字为:frmStockCheck
第一个问题:RegistryKey用什么样的命名空间,使用什么样的参照。我运行时,出错
第二个问题 :倒数第二句话,key6.SetValue("frmStockCheck",exeDir); 里面用frmStockCheck这个名字对不?
顺便看看代码里面有没有写错的地方。在这里先谢谢大家
[align=left]
string StartupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
System.IO.File.Copy(AppDomain.CurrentDomain.BaseDirectory,StartupPath+"frmStockCheck.cs",true);
string dir = Directory.GetCurrentDirectory();
string exeDir = dir+"frmStockCheck.exe";
RegistryKey key1=Registry.LocalMachine;
RegistryKey key2=key1.CreateSubKey("SOFTWARE");
RegistryKey key3=key2.CreateSubKey("Microsoft");
RegistryKey key4=key3.CreateSubKey("Windows");
RegistryKey key5=key4.CreateSubKey("CurrentVersion");
RegistryKey key6=key5.CreateSubKey("Run");
key6.SetValue("frmStockCheck",exeDir);
key6.Close();[/align]
我查到一个方法是这样写的,有些地方不太明白,希望有经验的给讲解一下
我的应用程序包的名称为:数据转送,程序的名字为:frmStockCheck
第一个问题:RegistryKey用什么样的命名空间,使用什么样的参照。我运行时,出错
第二个问题 :倒数第二句话,key6.SetValue("frmStockCheck",exeDir); 里面用frmStockCheck这个名字对不?
顺便看看代码里面有没有写错的地方。在这里先谢谢大家
[align=left]
string StartupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
System.IO.File.Copy(AppDomain.CurrentDomain.BaseDirectory,StartupPath+"frmStockCheck.cs",true);
string dir = Directory.GetCurrentDirectory();
string exeDir = dir+"frmStockCheck.exe";
RegistryKey key1=Registry.LocalMachine;
RegistryKey key2=key1.CreateSubKey("SOFTWARE");
RegistryKey key3=key2.CreateSubKey("Microsoft");
RegistryKey key4=key3.CreateSubKey("Windows");
RegistryKey key5=key4.CreateSubKey("CurrentVersion");
RegistryKey key6=key5.CreateSubKey("Run");
key6.SetValue("frmStockCheck",exeDir);
key6.Close();[/align]
解决方案 »
- C#中using(){}是什么意思?
- sql 求查询语句:表的某列的不相同值的明细
- 先来先得 存储过程中,我要得到当天的短日期GetDate().ShortDate
- 请问为什么我用ado以text方式执行创建函数的代码执行后的函数报错
- 如何设定TxtBox的焦点?
- 关于listbox的加载问题
- 为何在Webform中把水晶报表倒到excel后没有线?
- C#中的接口和Java中的接口有什么不同吗?
- gof模式。谁有这方面的照料。。。(UP的有分)
- 使用DATASET读取XML时,如何包含读取注释节点信息?等待大侠出手!
- 如何在CS里面动态添加AutoCompleteExtender控件(不好意思,没分了,希望大家帮帮忙看看)
- 页面传值问题大家帮帮我啊!!!!!1
帖子上是这样说的System.IO.File.Copy("应用程序路径(包括程序名)", StartupPath + "执行程序文件名称", true);
RegistryKey ms_run = Registry.LocalMachine.OpenSubKey(strPath, true);
ms_run.SetValue("runApp", Application.ExecutablePath.ToString());
你可以打开注册表中这个位置
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
里面每一项都是自动运行的.RegistryKey key1=Registry.LocalMachine;
RegistryKey key2=key1.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
key2.SetValue(名字,路径);
麻烦大家了。
这里有一个例子,
http://laiwen.cnblogs.com/archive/2005/09/29/246528.html