编程语言
首页 > 编程语言> > c#-检测用户是在“自定义操作”中选择了“所有用户”还是“仅我”

c#-检测用户是在“自定义操作”中选择了“所有用户”还是“仅我”

作者:互联网

我正在尝试检测用户在安装程序期间是否选择了“所有用户”或“仅我”单选.我有一个自定义操作设置,它覆盖了几种方法(OnCommit,OnBeforeInstall等).现在,我正在尝试在OnCommit期间查找此信息.

我已经读到我想获取的属性是ALLUSERS属性,但是我没有运气找到它在实例/本地数据中的存储位置.

有人知道一种实现方法吗?

-本

解决方法:

要在这里回答我自己的问题.

解决方案是在安装项目的属性gui中查看自定义操作.从那里开始,选择一个自定义动作使我可以编辑CustomActionData,在这种情况下,我可以输入:

/AllUsers=[ALLUSERS]

从那里,我可以通过自定义操作CS代码检测是否为所有用户安装:

private bool IsAllUsersInstall()
    {
        // An ALLUSERS property value of 1 specifies the per-machine installation context.
        // An ALLUSERS property value of an empty string ("") specifies the per-user installation context.

        // In the custom action data, we have mapped the parameter 'AllUsers' to ALLUSERS.
        string s = base.Context.Parameters["AllUsers"];

        if (s == null)
            return true;
        else if (s == string.Empty)
            return false;
        else
            return true;
    }

希望这可以帮助某人:)

标签:custom-action,action,allusersprofile,c
来源: https://codeday.me/bug/20191106/2000816.html