Visual Studio Code – How to run PowerShell or AutoIT

July 25, 2018

What is Visual Studio Code (VSCode) ?

Visual Studio Code is a cross platform source code editor for Windows, Linux and macOS, that support a multitude of programming and scripting languages.




And more using extension …


More then 1700 extensions available, only for Code language alone …


Install VSCode :


VSCode Architecture ?

VS Code is fully decoupled from the specific debugger and this architecture allows VS Code to debug anything, as long as there’s a Debug Adapter available, as illustrated here:



Why using VSCode ?

If you don’t want to use the full blown Visual Studio, which is a ton of software on you computer !

But still want to have the syntax highlighting, code intellisense, and more then VSCode is the real deal for you.

Big community and training videos


Extensions ?

There are many extensions available that gives VSCode extra functionality…

On of them is running code inside VSCode, like PowerShell and AutoIT, and hundreds of many more !

So you don’t need to use the PowerShell ISE or SciTE anymore, keeping all different code development & debugging in 1 tool Smile


Solution :

1. install the PS Code extension:


2. Restart VS Code


3. Test a PS Script

Open a PS1 script and press F5.


See here for more info :


The same goes for AutoIT Smile

1. Install the extension, this one seems to be the most extensive …


2. Restart VSCode

3. Test a au3 Script


Keyboard Shortcuts :

  • Run Script: F5
  • AutoIt Check: Ctrl+F5
  • Compile Script: Ctrl+F7
  • Build Script: F7
  • Run AutoIt Help: Ctrl+F1
  • Run Au3Info: Ctrl+F6
  • Debug to MsgBox: Ctrl+Shift+D
  • Debug to Console: Alt+D
  • Run Koda: Alt+M



More info on how to Configure VSCode :



AutoIT – Meets PowerShell using .NET Common Language Runtime (CLR) Framework

August 9, 2017

Since AutoIT has got access the to the .NET Common Language Runtime (CLR) Framework 

We can access the PowerShell Automation Classes as well.

This is really powerfull stuff … because we can reuse .NET code as well as all the native CMDlet’s and scripts.

As you can see the script runs an PowerShell command that lists all running processes on your machine. And return the Output to a .NET Grid.


Which runs inside our Unmanaged Host, isn’t that cool …Smile

We can access native .NET Classes as well because PS runs on top off it.

Next is that you could access any kind of Cloud Web Service using the multitude of PS Modules that are available.

As well as accessing Custom Build Assemblies.

How to :

For more information on how to access .NET Classes see the above post about .NET Common Language CLR Framework.

Or Join the most friendly and helpful AutoIT Community on the net Smile

See here for some Examples and use cases :

Download the full story here : NET CLR Framework for AutoIT

I will post some more examples in the AutoIT Forum, so stay tuned …

AutoIT – Meets .NET Common Language Runtime (CLR) Framework

April 27, 2017

CLR : The Common Language Runtime (CLR) is a an Execution Environment .

Common Language Runtime (CLR)’s main tasks are to convert the .NET Managed Code to native code, manage running code like a Virtual Machine, and also controls the interaction with the Operating System.

As part of Microsoft’s .NET Framework, the Common Language Runtime (CLR) is managing the execution of programs written in any of several supported languages.

Allowing them to share common object-oriented classes written in any of the languages.


Appdomain : To access the CLR environment you need to create an Appdomain Object.

An AppDomain provides an isolated region in which code runs inside of an existing process.

Application domains provide an isolation boundary for security, reliability, and versioning, and for unloading assemblies.

Application domains are typically created by runtime hosts, which are responsible for bootstrapping the common language runtime before an application is run.


CLR Runtime Hosts : When would you use CLR Runtime Hosts.

1. To access .NET Class Libraries :

  • System
  • System.Collections
  • System.Data
  • System.Drawing
  • System.IO
  • System.Text
  • System.Threading
  • System.Timers
  • System.Web
  • System.Web.Services
  • System.Windows.Forms
  • System.Xml

2. Accessing custom build .Net Assemblies :

Some Examples (but there are a ton out there)

  • AutoItX3 – The .NET Assembly for using AutoItX
  • JSonToXML libr.
  • XMLRPC Libr.
  • .NETPDF libr.
  • .NETOCR Libr
  • WInSCP Libr.

    3. To Compile .Net Code into an Assembly at Runtime

    4. To Run C# or Code at Runtime

    5. To Mix AU3 and .Net functionality in your Application


Documentation : Where to find info about CLR hosting

First of all you can find a lot on MSDN relating to .Net CLR Hosting and of course here :

AutoIt .NET CLR Framework


Examples : All examples are included in the above thread of the AutoIt forum.

1. To access .NET Class Libraries :

Example : “System.Text.UTF8Encoding”


Example : “System.IO.FileInfo”


Example : “System.Windows.Forms”



2. Accessing custom build .Net Assemblies :

Example : AutoItX3 .NET Assembly using AutoItX



3. To Compile .Net Code into an Assembly at Runtime

Example : Compile Code C# and Code VB



4. To Run C# or Code at Runtime

Example : Compile Code C# at Runtime



5. To Mix AU3 and .Net functionality in your Application

All of the above Examples have a mix of au3 functionality and .Net CLR code


This CLR.au3 UDF makes a bridge between .Net and Au3, which give a new dimension to our scripting experience.

Enjoy !

AutoIT – Accessing PowerShell using COM Object

January 23, 2017

AutoIT is COM enabled and more … so we can use the the SAPIEN ActiveXPosh COM Object to run Powershell code.

Or even to access .NET Assemblies …

You can use this COM object to run in any COM Compatible scripting host, like VBScript, Word, Excel, Etc …


First you need to download the FREE PS Com object here :

Look at the bottom of the site after login for SUPPORT next SUPPORT DOWNLOADS, Next see folder FREE COMPONENTS


Here are some examples translated to AU3

; Copyright (c) SAPIEN Technologies, Inc. All rights reserved
; This file is part of the PrimalScript 2007 Code Samples.
; File: ActiveXposh.vbs
; Comments:
; Disclaimer: This source code is intended only as a supplement to
;   SAPIEN Development Tools and/or on-line documentation.
;   See these other materials for detailed information
;   regarding SAPIEN code samples.


Dim $ActiveXPosh


Func CreateActiveXPosh()
Dim $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)
Consolewrite( "PowerShell not installed" & @CR)
; Set the output mode
$ActiveXPosh.OutputMode = $OUTPUT_CONSOLE

Func DownloadFile($URL,$Destination)
Local $Return
Dim $Command
Dim $FSO

;Download a file with PowerShell
$ActiveXPosh.Execute("$Client = new-object System.Net.WebClient")
;Note that variables are preserved between calls
; Construct a $Command
$Command = "$Client.DownloadFile('" & $URL & "','" & $Destination & "')"
ConsoleWrite ("Downloading ..." & @CR)

$FSO = ObjCreate("Scripting.FileSystemObject")
If $FSO.FileExists($Destination) Then
ConsoleWrite ("File transfer complete" & @CR)
ConsoleWrite ("File Transfer failed" & @CR)
Return $Return

Func ListServices()
Dim $outtext
; Set the $OUTPUT mode to $BUFFER
$ActiveXPosh.OutputMode = $OUTPUT_BUFFER
$ActiveXPosh.Execute("Get-WmiObject -class Win32_Service | Format-Table -property Name, State")

; Get the $OUTPUT line by line and add it to a variable
For $str In $ActiveXPosh.OUTPUT()
$outtext = $outtext & $str
$outtext = $outtext & @CRLF

; Alternatively you can get the $OUTPUT as a single String
; $outtext = $ActiveXPosh.OutputString

ConsoleWrite ($outtext & @CR)
$ActiveXPosh.ClearOutput() ; Empty the $OUTPUT $BUFFER

; Create the actual Object

$Status = $ActiveXPosh.GetValue("(Get-Service UPS).Status")
if($Status = "Stopped") then
ConsoleWrite ("UPS Service is stopped" & @CR)
ConsoleWrite ("UPS Service is " & $Status & @CR)

; List all running processes using PowerShell

; Check if WinWord is running using PowerShell
if $ActiveXPosh.Eval("get-process winword") = 1 Then
ConsoleWrite ("Microsoft Word is running" & @CR)
ConsoleWrite ("Microsoft Word is not running" & @CR)

DownloadFile ("[url="","C:\Temp\activexposh.pdf"]","C:\Temp\activexposh.pdf[/url]")

; Use ListServices to show all services in this machine using PowerShell()

ConsoleWrite ("Version " & $ActiveXPosh.GetValue("$PSHOME") & @CR)

$ActiveXPosh = ""


Enjoy !

Windows Core IoT -Developing a Console App for running on a Raspberry PI3 – Without Visual Studio

December 31, 2016

I was wondering wondering If we could create an App for running on our Rasberry PI3, where Windows 10 Core IoT is installed.

As you might know regular EXE files don’t run on this windows version, because a RPI3 uses an ARM Architecture.

While a normal Windows is based on x86 or x64 Architecture.


Solution :

Some years back I created a wrapper for the DotNet Compiler and called it Visual Studio Light

I modified this version that was created in AU3 to compile for ARM architecture.

(Just added the PLATFORM Switch for ARM)


So next I compiled this simple Console Application :

class HelloCsharp
static void Main()
System.Console.WriteLine (“Hello World from C#. on ARM Architecture like Raspberry PI3 running Windows 10 Core IoT”);




There where some errors popping up, but they seem to be normal.

Because I compiled the exe on a x64 Machine, and the EXE was compiled for and ARM Archtecture.

So it started complaining about this, but don’t worry  Winking smile

Next I copied the EXE for ARM to my RPI3.


Logged into a PS session on the RPI3, and it ran without any problems Smile





Windows Core IoT – Accessing Raspberry PI3 – WMI Classes remotely using WBEM

December 30, 2016

Start using Powershell on Windows IoT on a Raspberry PI3

If you check all the available COM objects that are installed on the Windows 10 Core IoT, we see that WMI and WBEM is installed.

List all COM Objects like this.


This enables opportunities for Scripters to connect remote to access all available WMI classes Smile.

But unfortunately I always got an error message like this :

The RPC server is unavailable 0x800706BA

Solution :

First connect using WSMAN to connect to the RPI3 using PS

See my previous post Running Powershell Scripts on Windows 10 Core IoT installed on a Raspberry PI3



Once the Firewall is set correct, you have the way open to access the WMI classes remotely, without having to first access the local PI3 using WSMAN Winking smile

So let’s test it accessing the EventLogs on Windows IoT


Now that we have remote access we can use PS to list all EventLog Errors in a GRID to check what is going wrong.



All log files are located here :


You can also use other Scripting languages like VBScript

strComputer = “rpi3”
Set objSWbemLocator = CreateObject(“WbemScripting.SWbemLocator”)
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, _
“Root\CIMv2”, _
“rpi3\administrator”, _

Set colItems = objSWbemServices.ExecQuery(“Select * from Win32_ComputerSystem”,,48)

For Each objItem in colItems
Wscript.Echo strComputer & ” responded.”
Wscript.Echo “Manufacturer: ” & objItem.Manufacturer
WScript.Echo “Model: ” & objItem.Model
Wscript.Echo “Status ” & objItem.Status
Wscript.Echo “SystemType: ” & objItem.SystemType


Or AU3 to remotely access the WMI Classes on the PI3 Smile



$StrCmp = "rpi3"
$StrUser = "rpi3\administrator"
$StrPswd = "P@ssW0rd"

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

$strComputer = "rpi3"
$objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
$objSWbemServices = $objSWbemLocator.ConnectServer($StrCmp, "root\cimv2", $StrUser, $StrPswd)

$colItems = $objSWbemServices.ExecQuery("Select * from Win32_ComputerSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

For $objItem in $colItems
          ConsoleWrite($strComputer & " responded." & @CRLF)
          ConsoleWrite("Manufacturer: " & $objItem.Manufacturer & @CRLF)
          ConsoleWrite("Model: " & $objItem.Model & @CRLF)
          ConsoleWrite("Status " & $objItem.Status & @CRLF)
          ConsoleWrite("SystemType: " & $objItem.SystemType & @CRLF)

Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

Build your first Console App for an ARM Architecture:

If you are interested in taking it a few steps further, you can here how to build a Console App EXE for IoT.

Happy Scripting !

Windows – WMI to access devices over SNMP – Error Invalid Namespace

January 20, 2015

I wanted to run an old script of mine to read out some network printer information using WMI – SNMP.

But I got an error saying that “Invalid Namespace“ Sad smile

Solutions :

You need to add the SNMP WMI providers to your machine.

1. Go to the Control Panel
2. Next select Programs and Features
3. Select Simple Network Management Protocol (SNMP)
4. Select WMI SNMP Provider


Once installed all errors are gone Smile

; Initialize error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")   $iIP = 31   For $iIP = 31 To 45 ; IP range   $strTargetSnmpDevice = "10.0.0." & $iIP
 ConsoleWrite("Target Device : " & $strTargetSnmpDevice & @CRLF)
 ConsoleWrite("-------------" & @CRLF)   $objWmiLocator = ObjCreate("WbemScripting.SWbemLocator")
 $objWmiServices = $objWmiLocator.ConnectServer("", "root\snmp\localhost")   $objWmiNamedValueSet = ObjCreate("WbemScripting.SWbemNamedValueSet")
 $objWmiNamedValueSet.Add ("AgentAddress", $strTargetSnmpDevice)
 $objWmiNamedValueSet.Add ("AgentReadCommunityName", "public")   $colIfTable = $objWmiServices.InstancesOf("SNMP_RFC1213_MIB_ifTable",Default , $objWmiNamedValueSet)   For $objInterface In $colIfTable
    ConsoleWrite ("ifIndex [Key]:        " & $objInterface.ifIndex  & @CRLF & _
        "   ifAdminStatus:     " & $objInterface.ifAdminStatus 		& @CRLF & _
        "   ifDescr:           " & $objInterface.ifDescr         	& @CRLF & _
        "   ifInDiscards:      " & $objInterface.ifInDiscards    	& @CRLF & _
        "   ifInErrors:        " & $objInterface.ifInErrors      	& @CRLF & _
        "   ifInNUcastPkts:    " & $objInterface.ifInNUcastPkts   	& @CRLF & _
        "   ifInOctets:        " & $objInterface.ifInOctets      	& @CRLF & _
        "   ifInUcastPkts:     " & $objInterface.ifInUcastPkts 		& @CRLF & _
        "   ifInUnknownProtos: " & $objInterface.ifInUnknownProtos 	& @CRLF & _
        "   ifLastChange:      " & $objInterface.ifLastChange     	& @CRLF & _
        "   ifMtu:             " & $objInterface.ifMtu            	& @CRLF & _
        "   ifOperStatus:      " & $objInterface.ifOperStatus     	& @CRLF & _
        "   ifOutDiscards:     " & $objInterface.ifOutDiscards 		& @CRLF & _
        "   ifOutErrors:       " & $objInterface.ifOutErrors      	& @CRLF & _
        "   ifOutNUcastPkts:   " & $objInterface.ifOutNUcastPkts  	& @CRLF & _
        "   ifOutOctets:       " & $objInterface.ifOutOctets      	& @CRLF & _
        "   ifOutQLen:         " & $objInterface.ifOutQLen        	& @CRLF & _
        "   ifOutUcastPkts:    " & $objInterface.ifOutUcastPkts   	& @CRLF & _
        "   ifPhysAddress:     " & $objInterface.ifPhysAddress 		& @CRLF & _
        "   ifSpecific:        " & $objInterface.ifSpecific       	& @CRLF & _
        "   ifSpeed:           " & $objInterface.ifSpeed          	& @CRLF & _
        "   ifType:            " & $objInterface.ifType           	& @CRLF)
		ConsoleWrite("" & @CRLF)
ConsoleWrite("" & @CRLF)

Output is like this :


For Powershell it looks a bit different:


For ($iIP=32; $iIP -le 45; $iIP++){

    $CommunityString = "public"
    $IPAddress     = "10.0.0."+$iIP
    write-host $IPAddress

    $Opt = new-object Management.ConnectionOptions
    $Opt.Impersonation = 'Impersonate'

    $context = new-object management.ManagementNamedValueCollection
    $context.Add("AgentAddress", $IPAddress)
    $context.Add("AgentReadCommunityName", $CommunityString)

    $ogo =  new-object management.ObjectGetOptions($context, (new-object TimeSpan(0,0,0,5)), $true)

    $scope = new-object management.ManagementScope("root\snmp\localhost", $Opt)

    $query = new-object Management.ObjectQuery("select * from SNMP_RFC1213_MIB_system")

    $searcher = new-object Management.ManagementObjectSearcher($scope,$query)
    $searcher.Options.Context = $context



Output is like this :


If you want to access devices like routers, switches, printers etc. using Native SNMP protocol.

You will need some tools to get hold of their public or private MIB Object ID’s.

Once of the many tools out there is Softperfect Network scanner.


Maybe I will address this later how to access the network Devices using native SNMP protocol Winking smile

Enjoy !

Windows – Install TTF Barcode Fonts

August 28, 2014

I had to install some barcode fonts to be used in Word and Excel for Label printing.

After installing it will look like this.


Some of the fonts are free to download from then net, like (Barcode 39 TTF), others are not.

Installing is normally a piece of cake. Right click the font file and choose Install.


But in some PC’s the file association has changed because of other applications being installed.

So there is no Install Sad smile


To find the associated application on the machine, use assoc.exe


Indeed you see it here :



To find what was the original file association, have a look here.

You see it was associated with Windows Fonts Viewer.

Being here : C:\Windows\System32\Fontview.exe

Solution :

Let fix it using AutoIT


FileExtAssoc("ttf", "Fontview.exe")

func FileExtAssoc($sExt, $sApplication)
    RunWait(@COMSPEC & " /c ASSOC ." & $sExt & "=ExTest", "", @SW_HIDE)
    RunWait(@COMSPEC & " /c FTYPE ExTest=" & $sApplication , "", @SW_HIDE)
    MsgBox(0,"File Extension Application Association",'"' & $sExt & '"is now asscoiated with "' & $sApplication & '"',3)

Or using the GUI way like this.




Enjoy !

AutoIT – Visual Studio Light

August 24, 2014

Sometime you find some nice code on the internet like VB.Net or C#.

But it is of no use if it is not compiled Sad smile

As explained in this post you can compile you own .NET COM objects on the fly.

But if you want to do it using a GUI interface without installing the full blown Visual Studio. You can use this GUI Wrapper – Visual Studio Light


The first option is for compiling GUI Applications EXE’s.

The second one is to create DLL’s (Libraries) which you can use later on in a .Net application.

The third one is for compiling Console Applications EXE’s.

You can download it here

PS :  This wrapper is for VB.Net but can easily be changed to use C# replace the vbc.exe by csc.exe

If you run it you get an EXE or DLL



This is the code :

imports System.Windows.Forms

' The name of the module must match the name of the code item
' created in the hosting application via CreateItem.
module Script
  sub Main()
    MessageBox.Show("hi From DotNET !!")
  end sub
end module

How to run .Net Assemblies in Powershell see here

How to run .Net Assemblies form Memory in Powershell see here

Enjoy !

AutoIT – How to compile your own .NET COM Object

August 24, 2014

Wouldn’t it be nice to compile your own .NET COM DLL and use it on AutoIT.

Well we don’t need much to do this. Everything is available on your system.

Let’s see :

First we need of course some VB.Net code or C# that will exposes some methods or properties.

Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices

Namespace myDotNetLibrary
  &amp;lt;classinterface   (CLASSINTERFACETYPE.AUTODUAL)&amp;gt; _
  Public Class myDotNetClass
    Private myProperty As String

    Public Sub New()
    End Sub

    Public Function myDotNetMethod(input As String) As String
      Return &amp;quot;Hello &amp;quot; &amp;amp;amp; input
    End Function

    Public Property myDotNetProperty() As String
        Return myProperty
      End Get
      Set(ByVal value As String)
        myProperty = value
      End Set
    End Property

  End Class
End Namespace

Next we need a .Net compiler ? Ha but that is default available on each system that has a .Net Framework installed Smile

Go and have a look here : C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc.exe

The vbc.exe is the compiler for the .Net 2.0 framework. But you will find as well the compiler for .NET 3.0 and 4.0 if you have that framework installed.

So now we need to compile the code to a DLL and register it.


; Framework 2.0
;$vbc = "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc.exe" ;  ; check the path of your version
;$RegAsm = "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe" ; check the path of your version
; Framework 4.0
$vbc = "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\vbc.exe" ;  ; check the path of your version
$RegAsm = "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" ; check the path of your version

RunWait($vbc & " /target:library hello.vb", @ScriptDir, @SW_HIDE) ; compile the .net DLL
RunWait($RegAsm & " /codebase hello.dll", @ScriptDir, @SW_HIDE) ; register the .net DLL

$obj = ObjCreate("myDotNetLibrary.myDotNetClass")
$obj.myDotNetProperty = " ... from DotNet to the AutoIt World !"

MsgBox(0,"My Own DotNet Object " , $obj.myDotNetMethod($obj.myDotNetProperty) & @CRLF)

RunWait($RegAsm & " /unregister hello.dll", @ScriptDir, @SW_HIDE) ; unregister the .net DLL

Ones you run the code it will compile the code to a DLL and register it in the GAC

Or if you want don’t want to register the COM Assembly to the GAC, you can use this approach 😉



And run it as a COM object, where AU3 will access it’s methods and properties.


You can see if the COM object registered correctly here :


For a C# compiler you need to look for the csc.exe instead of the vbc.exe