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


摘要

如果有这样的需求,需要软件开机自启动,该如何做呢?开机自启动的做法,就是修改注册表,将你的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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM