码迷,mamicode.com
首页 > Windows程序 > 详细

[Winform]setupfactory打包时添加开机自启动的脚本

时间:2017-08-23 14:59:47      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:系统   exe   eth   完成   factor   numbers   alt   程序   color   

摘要

如果有这样的需求,需要软件开机自启动,该如何做呢?开机自启动的做法,就是修改注册表,将你的exe注册到注册表Run节点下。

setupfactory

在安装的时候需要以管理员身份运行,这样可以保证你的操作有足够的权限。

在程序安装完成时,添加下面的脚本

 

技术分享

脚本如下

isExist = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
-- An if ... else statement that compares two numbers

if (isExist) then
    -- Do something here
    Registry.SetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "test",
SessionVar.Expand("%AppFolder%\\test.exe"), REG_SZ); else -- Do something else here Registry.CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); Registry.SetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "test",
SessionVar.Expand("%AppFolder%\\test.exe"), REG_SZ);
end

查看注册表

技术分享

注意 如果你的系统是x64的 则再下面的key下能找到,你添加的注册项

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run

[Winform]setupfactory打包时添加开机自启动的脚本

标签:系统   exe   eth   完成   factor   numbers   alt   程序   color   

原文地址:http://www.cnblogs.com/wolf-sun/p/7417654.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!