如何使用Qt安装程序框架在系统变量路径(而不是用户变量)中添加环境变量(目录C:/test1 1/bin)?我试过这样做,
component.addOperation ("EnvironmentVariable","PATH","C:/testl/bin",true);
但是这增加了用户变量路径,请帮助我修改这一点,以便将值添加到系统变量路径中。
发布于 2022-03-08 08:09:49
我用这个方法来解决:
if(installer.isInstaller())
{
var pathText = "D:\\test"
var reg = installer.environmentVariable("SystemRoot") + "\\System32\\reg.exe";
var RegV="HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\SessionManager\\Environment"
component.addOperation("Execute", reg, "ADD", RegV , "/v", "pathText", "/t", "REG_SZ", "/d", pathText,"/f");
}您可以使用"REG ADD /?“在powershell中找到帮助。
请注意,此安装程序需要调用gainAdminRights():
function Component()
{
component.loaded.connect(this, this.installerLoaded);
installer.installationStarted.connect(this,Component.prototype.onInstallationStarted);
}
Component.prototype.onInstallationStarted = function()
{
installer.gainAdminRights();
installer.execute("cmd.exe", ["/c", "timeout " + "5"]);
}https://stackoverflow.com/questions/69557258
复制相似问题