在vs.2005中打包时怎样写注册表,让程序下次开机时自动运行,还有安装完成后自动启动?--------很急--在线等.............. 如题, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 开机自动运行的话,可以在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run下面建一个string型value,值为你的可执行文件的路径至于“安装完成后自动启动”,我还真不知道这还能通过修改注册表来完成……你就让你的安装程序自己来启动不就成了么? 程序开机自动运行 string StartupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup); System.IO.File.Copy("应用程序路径(包括程序名)", StartupPath + "执行程序文件名称", true); //获得文件的当前路径 string dir = Directory.GetCurrentDirectory(); //获取可执行文件的全部路径 string exeDir = dir + "WindowsApplication1.exe"; //获取Run键 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"); //在Run键中写入一个新的键值 key6.SetValue("myForm",exeDir); key6.Close(); //如果要取消的话就将key6.SetValue("myForm",exeDir);改成 //key6.SetValue("myForm",false); 开机自动运行的话,可以在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run下面建一个string型value,值为你的可执行文件的路径这个方便 vainnetwork的对,也可以在runonce键值下,这样开机后只运行一次,以后开机就不运行了。如果放在run下的话,你可以设置安装完成后删除键值。 安装完自动运行: protected override void OnAfterInstall(System.Collections.IDictionary savedState) { base.OnAfterInstall(savedState); path = this.Context.Parameters["targetdir"] + "你的程序.exe"; System.Diagnostics.Process.Start(path); }写入注册表自启动:private void WriteReg() { RegistryKey KeyCon = Registry.LocalMachine.OpenSubKey( "Software\\Microsoft\\Windows\\CurrentVersion\\Run", true); string MyKey = "你的程序"; if ((string)KeyCon.GetValue(MyKey, "no") == "no")//指定的键不存在 { string Path = AppDomain.CurrentDomain.BaseDirectory + "你的程序.exe"; KeyCon.SetValue(MyKey, Path); //设置注册表中的启动键 } } class WingRegeditWork : IWingRegeditWork { public WingRegeditWork() { } /// <summary> /// 写入注册表 /// </summary> public void WriteToRegedit() { try { string MyString = Application.ExecutablePath; Microsoft.Win32.RegistryKey rootkey = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey Local = rootkey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); Local.SetValue("wing", MyString); } catch { } } /// <summary> /// 查询注册表里的值是否存在,是返回假,否返回真 /// </summary> /// <returns></returns> public bool SelectMySelfInRegedit() { try { string MyPath = Application.ExecutablePath; Microsoft.Win32.RegistryKey rootKey = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey LocalValue = rootKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); string[] theValue = LocalValue.GetValueNames(); foreach (string str in theValue) { if (LocalValue.GetValue(str).ToString() == MyPath) { return false; } } return true; } catch { return true; } } /// <summary> /// 删除注册表,成功返回假,不成功返回真 /// </summary> public void DeleteToRegedit() { Microsoft.Win32.RegistryKey rootkey = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey Local = rootkey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); Local.DeleteValue("wing"); } } 一个新手求教 关于如何实现二次检索的问题,请教各位大人了~~ 怎么添加双引号 一个感觉比较高深的问题 关于VS2010开始启动的问题 求multipart/form-data提交后台获取数据方法 一个主services服务的机子,几台数据库的机子。 C#如何实现这个 元旦到了,需要交差,请各位大侠帮帮忙!家人等着我回去过节呢。(在dataset中的datatable中添加一条记录,因改如何将其添加到数据库中) 原代码提供! GridView中,取所选行的某列数据的值的问题!50分! 如何设定TabPage头的宽度?
你就让你的安装程序自己来启动不就成了么?
System.IO.File.Copy("应用程序路径(包括程序名)", StartupPath + "执行程序文件名称", true);
//获得文件的当前路径
string dir = Directory.GetCurrentDirectory();
//获取可执行文件的全部路径
string exeDir = dir + "WindowsApplication1.exe";
//获取Run键
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");
//在Run键中写入一个新的键值
key6.SetValue("myForm",exeDir);
key6.Close();
//如果要取消的话就将key6.SetValue("myForm",exeDir);改成
//key6.SetValue("myForm",false);
这个方便
如果放在run下的话,你可以设置安装完成后删除键值。
protected override void OnAfterInstall(System.Collections.IDictionary savedState)
{
base.OnAfterInstall(savedState);
path = this.Context.Parameters["targetdir"] + "你的程序.exe";
System.Diagnostics.Process.Start(path);
}
写入注册表自启动:
private void WriteReg()
{
RegistryKey KeyCon = Registry.LocalMachine.OpenSubKey(
"Software\\Microsoft\\Windows\\CurrentVersion\\Run",
true);
string MyKey = "你的程序";
if ((string)KeyCon.GetValue(MyKey, "no") == "no")//指定的键不存在
{
string Path = AppDomain.CurrentDomain.BaseDirectory + "你的程序.exe";
KeyCon.SetValue(MyKey, Path); //设置注册表中的启动键
}
}
{
public WingRegeditWork()
{
}
/// <summary>
/// 写入注册表
/// </summary>
public void WriteToRegedit()
{
try
{
string MyString = Application.ExecutablePath;
Microsoft.Win32.RegistryKey rootkey = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey Local = rootkey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
Local.SetValue("wing", MyString);
}
catch { }
}
/// <summary>
/// 查询注册表里的值是否存在,是返回假,否返回真
/// </summary>
/// <returns></returns>
public bool SelectMySelfInRegedit()
{
try
{
string MyPath = Application.ExecutablePath;
Microsoft.Win32.RegistryKey rootKey = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey LocalValue = rootKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
string[] theValue = LocalValue.GetValueNames();
foreach (string str in theValue)
{
if (LocalValue.GetValue(str).ToString() == MyPath)
{
return false;
}
}
return true;
}
catch
{
return true;
}
} /// <summary>
/// 删除注册表,成功返回假,不成功返回真
/// </summary>
public void DeleteToRegedit()
{
Microsoft.Win32.RegistryKey rootkey = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey Local = rootkey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
Local.DeleteValue("wing");
}
}