none
How do the executing environment differs between PowerShell_ISE.exe and PowerShell.exe?

    Question

  • Hi,

    Does anyone know how the “executing environment” differs
    between PowerShell_ISE.exe and PowerShell.exe?

    I recently discovered I needed –STA for some code to function correctly (http://gallery.technet.microsoft.com/scriptcenter/Set-UserTileFromAD-99029716) but I’ve just written some code which makes use of a 3’rd party dll and found it works fine in the PowerShell_ISE.exe but not in PowerShell.exe (running both
    as administrator)

    The code I'm using looks like this ...

    [void][System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\3CX PhoneSystem\Bin\3cxpscomcpp2.dll")
    
    [TCX.Configuration.PhoneSystem]::set_cfgserverhost("127.0.0.1")
    [TCX.Configuration.PhoneSystem]::set_cfgserverport("5485")
    [TCX.Configuration.PhoneSystem]::set_ApplicationName("CallViewer")
    
    $3CX = [TCX.Configuration.PhoneSystem]::get_Root()
    

    It works fine as administrator from %windir%\sysWOW64\WindowsPowerShell\v1.0\PowerShell_ISE.exe but not from %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe ... I get this error ...

    Exception calling "get_Root" with "0" argument(s): "Config server is not connected"
    At line:1 char:50
    + $3CX = [TCX.Configuration.PhoneSystem]::get_Root <<<< ()
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    I'd appreicate any words of wisdom :o)

    Thanks,

    John

    Friday, March 30, 2012 3:28 PM

Answers

  • I'm daft!

    I had tried STA but shelled out from and existing powershell.exe session. Started on from cmd and it works.

    Is there any additional reading you could recommend to get my head around the requirement for STA?

    Thanks Kazun.


    Some WinApi,WPF,Windows Forms,some Com. For future tests try in both mode Sta and Mta =).
    • Marked as answer by John Grenfell Friday, March 30, 2012 5:06 PM
    Friday, March 30, 2012 5:02 PM

All replies

  • This error ocur if you run powershell with param -Sta?

    %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe -STA

    Friday, March 30, 2012 4:18 PM
  • I'm daft!

    I had tried STA but shelled out from and existing powershell.exe session. Started on from cmd and it works.

    Is there any additional reading you could recommend to get my head around the requirement for STA?

    Thanks Kazun.

    Friday, March 30, 2012 4:42 PM
  • I'm daft!

    I had tried STA but shelled out from and existing powershell.exe session. Started on from cmd and it works.

    Is there any additional reading you could recommend to get my head around the requirement for STA?

    Thanks Kazun.


    Some WinApi,WPF,Windows Forms,some Com. For future tests try in both mode Sta and Mta =).
    • Marked as answer by John Grenfell Friday, March 30, 2012 5:06 PM
    Friday, March 30, 2012 5:02 PM
  • That's great.

    Thanks Kazun :o)

    Friday, March 30, 2012 5:06 PM