Jump to content
Sign in to follow this  

using ActivexPosh to run Powershell statements problem

Recommended Posts


Hi Guys

I have recently found that autoit can now link into Powershell which is great news. 

However things are never simple and i have found a flaw which im hoping someone can solve for me.

I have a problem with any dll compiled from .net 4. For example the following script work fine with .net 2 dll but doesn't work .net 4.

#include <GUIConstants.au3>
#include <Array.au3>
#include <File.au3>

Dim $ActiveXPosh


$File = FileOpen('result.txt',10)
    $dll = "C:\Windows\system32\mfcm100.dll"
        $sPSCmd = '[Reflection.Assembly]::LoadFrom("' & $dll &'").ImageRuntimeVersion'
        $val = ExecuteCMD($sPSCmd)
        Filewrite($File,$Dll & '    ' & $val & @CRLF)
    $dll = "C:\Windows\system32\dnscmmc.dll"
        $sPSCmd = '[Reflection.Assembly]::LoadFrom("' & $dll &'").ImageRuntimeVersion'
        $val = ExecuteCMD($sPSCmd)
        Filewrite($File,$Dll & '    ' & $val & @CRLF)

Func CreateActiveXPosh()
 Local $success
 ; Create the PowerShell connector object
 $ActiveXPosh = ObjCreate("SAPIEN.ActiveXPoSH")
 $success = $ActiveXPosh.Init(False) ;Do not load profiles
 If $success <> 0 then
  Consolewrite( "Init failed" & @CR)
 If $ActiveXPosh.IsPowerShellInstalled Then
  Consolewrite( "Ready to run PowerShell commands" & @CR & @CR)
  Consolewrite( "PowerShell not installed" & @CR & @CR)
 ; Set the output mode
 $ActiveXPosh.OutputMode = $OUTPUT_CONSOLE
 $ActiveXPosh.OutputWidth = 250

Func ExecuteCMD($sPSCmd)
 Local $outtext = ''
 ; Set the $OUTPUT mode to $BUFFER
 $ActiveXPosh.OutputMode = $OUTPUT_BUFFER
 $outtext = $ActiveXPosh.OutputString
 Return $outtext

By trawling the internet I have found to interigate .net4 dll's with powershell you need to add a config file (Powershell.exe.config)

<?xml version="1.0"?> 
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
        <supportedRuntime version="v4.0.30319"/> 
        <supportedRuntime version="v2.0.50727"/> 

However adding this doesn't work from a autoit script. Can anyone help?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.