卸载所有用户的自动运行注册表项 [英] Uninstall auto-run registry entries for all users

查看:79
本文介绍了卸载所有用户的自动运行注册表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下情况:

  • Inno Setup将名为XYZ的程序安装到程序文件中,以供所有用户访问.
  • 程序XYZ中的配置选项允许按用户将注册表值安装到HKCU\Software\Microsoft\Windows\CurrentVersion\Run,以允许用户根据自己的喜好配置应用程序自动启动.
  • 卸载XYZ时,如果当前用户以外的任何用户都设置了自动运行的注册表项,则它们将被保留下来,并在下次登录时引起错误.
  • Inno Setup installs program named XYZ to Program Files, to be accessed by all users.
  • A configuration option within program XYZ allows installation of a registry value to HKCU\Software\Microsoft\Windows\CurrentVersion\Run on a per-user basis, to allow users to configure application auto-start to their own preferences.
  • When uninstalling XYZ, if any user other than the current user has auto-run registry keys set, they will be left over and cause errors next time they log-in.

问题

  • 从Inno Setup中的所有用户帐户中删除适当的注册表值的正确方法是什么?
  • 枚举HKU中的配置文件并检查密钥并删除它们是否合适?如何在Inno Setup中完成此操作?
  • 最后,这可能导致漫游配置文件出现什么问题?

有问题的程序XYZ是用C#编写的,可以使用以下代码枚举HKU,但我想通过Inno Setup完全处理卸载,而不必在卸载时调用单独的可执行文件.

The program XYZ in question is in C#, and can enumerate through the HKU's with the following code, but I'd like to handle the uninstallation completely via Inno Setup and not have to call into a separate executable on uninstall.

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();
}

推荐答案

要从所有用户中删除自动运行条目,请使用:

To delete an autorun entry from all users, use:

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;


不确定漫游配置文件.


Not sure about the roaming profiles.

您是否考虑过将自动运行项添加到HKEY_LOCAL_MACHINE,但是根据HKEY_CURRENT_USER中的设置(根据用户喜好)使应用程序立即退出?

Did you consider adding the autorun entry to the HKEY_LOCAL_MACHINE, but make the application to exit immediately based on a setting in the HKEY_CURRENT_USER (per user preference)?

这样,您可以只卸载一个HKEY_LOCAL_MACHINE值. HKEY_CURRENT_USER中的设置可能会遗留下来.

This way you could just uninstall a single HKEY_LOCAL_MACHINE value. The setting in HKEY_CURRENT_USER might be left behind.

这篇关于卸载所有用户的自动运行注册表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆