考虑这种情况:
- Inno Setup 将名为 XYZ 的程序安装到 Program Files 中,供所有用户访问。
- 程序 XYZ 中的配置选项允许安装注册表值
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
基于每个用户,允许用户根据自己的喜好配置应用程序自动启动。
- 卸载 XYZ 时,如果当前用户以外的任何用户设置了自动运行注册表项,这些注册表项将被遗留下来并在下次登录时导致错误。
问题
- 从 Inno Setup 中的所有用户帐户中删除适当的注册表值的正确方法是什么?
- 枚举 HKU 中的配置文件并检查密钥并将其删除是否合适?在 Inno Setup 中这将如何完成?
- 最后,这样做可能会导致漫游配置文件出现哪些问题?
有问题的程序 XYZ 是用 C# 编写的,可以使用以下代码枚举 HKU,但我想通过 Inno Setup 完全处理卸载,而不必在卸载时调用单独的可执行文件。
private static string GetSIDFromUserName(string userName)
{
var account = new System.Security.Principal.NTAccount(userName);
var identifier = (System.Security.Principal.SecurityIdentifier)account.Translate(typeof(System.Security.Principal.SecurityIdentifier));
var sid = identifier.Value;
return sid;
}
private static string[] GetAllSystemUsers()
{
List<string> names = new List<string>();
SelectQuery query = new SelectQuery("Win32_UserAccount");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject envVar in searcher.Get())
{
names.Add((string)envVar["Name"]);
}
return names.ToArray();
}
要从所有用户中删除自动运行条目,请使用:
procedure DeleteAutoRunEntryFromAllUsers(AutoRunValueName: string);
var
Names: TArrayOfString;
UserKey: string;
AutoRunKey: string;
I: Integer;
begin
Log('Enumerating user keys');
RegGetSubkeyNames(HKEY_USERS, '', Names);
Log(Format('Found %d user keys', [GetArrayLength(Names)]));
for I := 0 to GetArrayLength(Names)-1 do
begin
UserKey := Names[I];
Log(Format('User %s', [UserKey]));
AutoRunKey := Format('%s\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', [UserKey]);
if RegValueExists(HKEY_USERS, AutoRunKey, AutoRunValueName) then
begin
Log(Format('Deleting auto-run entry from user %s', [UserKey]));
if RegDeleteValue(HKEY_USERS, AutoRunKey, AutoRunValueName) then
begin
Log(Format('Deleted auto-run entry from user %s', [UserKey]));
end
else
begin
Log(Format('Failed to delete auto-run entry from user %s', [UserKey]));
end;
end;
end;
end;
不确定漫游配置文件。
您是否考虑过将自动运行条目添加到HKEY_LOCAL_MACHINE
,但根据中的设置使应用程序立即退出HKEY_CURRENT_USER
(根据用户偏好)?
这样你就可以只卸载一个HKEY_LOCAL_MACHINE
价值。设置在HKEY_CURRENT_USER
可能会被抛在后面。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)