自定义操作以管理特权和设置会话变量运行



我想运行一个自定义操作并进行重新启动,然后在此之后设置一些会话变量

HEALE是我的自定义动作功能

[CustomAction]
public static ActionResult RegistryDetails(Session session)
{
    try
    {
        CurrentSession = session;
        string registryPath = @"SOFTWAREXXXPrinters";
        int printerIndex = 1;
        RegistryKey prnKey = Registry.LocalMachine;
        prnKey = prnKey.OpenSubKey(registryPath);
        List<string> subKeyList = new List<string>();
        subKeyList.AddRange(prnKey.GetSubKeyNames());
        while(subKeyList.Contains(printerIndex.ToString()))
        {
            printerIndex++;
        }
        string newRegistryPath = registryPath + "\" + printerIndex.ToString();
        session["UtillRegKey"] = newRegistryPath;
        session["PrinterNo"] = printerIndex.ToString();
    }
    catch (Exception ex)
    {
        CurrentSession.Log(ex.Message);
        Record exceptionRec = new Record(0);
        exceptionRec[0] = "Errors -" + ex.StackTrace.ToString();
        return ActionResult.Failure;
    }
    return ActionResult.Success;
}

但是要运行此自定义操作,我需要管理员特权所以我设置了Execute="deferred"&amp;我的自定义操作定义的Impersonate="no"。这使session["PrinterNo"]&amp;session["UtillRegKey"]无法访问。因为访问会话变量应该是Execute="immediate"。但是我无法将其设置为Execute="immediate",这将阻止运行自定义操作作为管理员

任何人都可以帮助我克服这一点。

您无法在安装的递延(升高)阶段修改会话属性。您可以在延期自定义操作期间阅读会话属性,并且需要由另一个自定义操作设置的特殊属性并使用session.CustomActionData

看来您只是从注册表中阅读,因此可以立即采取行动没有问题。

最新更新