gpt4 book ai didi

powershell - 从 COM 方法检索 session ID

转载 作者:行者123 更新时间:2023-12-01 03:41:26 26 4
gpt4 key购买 nike

我有一个名为 GoLogon 的方法在名为 BS.Logon 的 COM 对象中这需要 5 个参数:

  • 用户名
  • 密码
  • 应用ID
  • XMLRoot
  • IP地址

  • 此方法使用用户名、密码和其他详细信息登录到 Web 服务器,并返回 session ID。

    我已经编写了 Powershell 脚本来调用方法 GoLogon如下。
    $obj=New-Object -ComObject BS.Logon
    $sessionid=$obj.GoLogon([ref]$bUsername,$bPassword,$appid,$xmlroot,[ref]$ipad)
    Write-Host $sessionid

    执行脚本时,该方法使登录成功。我可以在数据库中看到 session ID 详细信息,但无法通过脚本获取 session ID 详细信息。变量 $sessionid返回空值。脚本也抛出异常
    Exception calling "GoLogon" with "5" argument(s): "Invalid callee. (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))"
    At E:\Logon.ps1:18 char:1
    + $obj.Login([ref]$bUsername,$bPassword,$appid,$xmlroot,[ref]$ipad)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation`

    堆栈跟踪是:
    Exception             : System.Management.Automation.MethodInvocationException: Exception calling "GoLogon" with "5" argument(s): "Invalid callee. (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))" ---> System.Reflection.TargetInvocationException: 
    Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Invalid callee. (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))
    --- End of inner exception stack trace ---
    at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
    at System.Management.Automation.ComMethod.InvokeMethod(PSMethod method, Object[] arguments)
    --- End of inner exception stack trace ---
    at System.Management.Automation.ComMethod.InvokeMethod(PSMethod method, Object[] arguments)
    at System.Management.Automation.Adapter.BaseMethodInvoke(PSMethod method, PSMethodInvocationConstraints invocationConstraints, Object[] arguments)
    at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
    at System.Management.Automation.Interpreter.DynamicInstruction 7.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
    TargetObject :
    CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    FullyQualifiedErrorId : ComMethodTargetInvocation
    ErrorDetails :
    InvocationInfo : System.Management.Automation.InvocationInfo
    ScriptStackTrace : at <ScriptBlock>, E:\Logon.ps1: line 18
    PipelineIterationInfo : {}
    PSMessageDetails :

    请建议我如何从该方法中获取 session ID 值。

    最佳答案

    PowerShell 似乎对定义为 VARIANT 的 COM 参数有问题。

    正如 GoLogon 的 C++ 签名所暗示的那样,这里就是这种情况。

    STDMETHODIMP CLOG::GOLogon(VARIANT *pvEmailId, BSTR bsPassword, BSTR bsIPAddress, BSTR bsSoloBuildVer, VARIANT *pvXML, BSTR *bsSessionId)

    这篇文章中建议的答案 "Invalid callee" calling a com object是使用 VariantWrapper。

    在你的情况下,这应该可以解决问题。
    #define VariantWrapper for variables to be passesed as VARIANT
    $wrapbUservame = New-Object Runtime.InteropServices.VariantWrapper($bUsername)
    $wrappvXML = New-Object Runtime.InteropServices.VariantWrapper($pvXML)

    #pass a [ref]VariantWrapper to .COM method
    $sessionid=$obj.GoLogon([ref]$wrapbUservame,$bPassword,$appid,[ref]$wrappvXML,$ipad)

    关于powershell - 从 COM 方法检索 session ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30512785/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com