Jump to content

net framework objects and scripts


Recommended Posts

I found this article

net framework and vbscript (sorry, it is in italian).

The meaning is that you can use some classes of the net framework in your script.

So i tried to do something like that:

Func F_test()
    ConsoleWrite("test: "&$list.count&@crlf)
    for $i=0 to $list.count-1
        ConsoleWrite($list.GetKey($i)&" - "&$list.Getbyindex($i)&@crlf)

IT works. It could be very helpful.

Someone knows something about that?

Someone knows other net classes we can use in scripting?

Link to comment
Share on other sites

Link to comment
Share on other sites


I like this one. I am constantly looking for new objects myself, and this one I didn't have yet.

Good job.

Better next time is to post your examples in the EXAMPLE SCRIPT section of the forum.

Ciao !!


OKS ptrex.

You are right, It is better. I don't want to duplicate the post, maybe the admin can move it.

I would like to know which net classes we can use in scripting.

if someone find something please reply...

Link to comment
Share on other sites

This is FANTASTIC!!! I wish I'd known about this a year ago!

It looks like .Net members in registered DLLs with the COMVisible(True) attribute or an assigned GUID are available for scripting. This includes the following potentially useful items:

  • System.Collections.ArrayList
  • System.Collections.HashTable
  • System.Collections.SortedList
  • System.Collections.Stack
  • System.Collections.Queue
  • System.Diagnostics.Debugger
  • System.Diagnostics.StackFrame
  • System.Diagnostics.StackTrace
  • various calendars and Info classes in System.Globalization
  • System.IO.MemoryStream
  • System.IO.StringWriter
  • System.Random
  • a LOT of things in System.Runtime.InteropServices and System.Runtime.Remoting
  • System.Text.ASCIIEncoding
  • System.Text.StringBuilder
  • System.Text.UnicodeEncoding
  • System.Threading.Mutex
  • System.Threading.OverLapped
  • System.Threading.ReaderWriterLock
I just did a bit of experimenting to see if SortedList would handle AutoIt-style arrays and DLLStruct variables. It turns out, Arrays work great, but DLLStructCreate seems to return something that can't be stored. One way around that is to use Assign() and Eval():

#include <array.au3>
;~  MsgBox(0,"DLLStructCreate errorlevel", @error)
;~  MsgBox(0,$rect & "[ 3 ]", DllStructGetData($rect,3))

    ; Assign the structure to a named variable. The DLLStruct can't be serialized effectively with this technique, but it can be dereferenced using Eval.
    ConsoleWrite("test: " & $list.count & @crlf)
    for $i=0 to $list.count-1
        If Not IsArray($value) Then 
            ConsoleWrite($key & " - " & $value & @crlf)
            ConsoleWrite($key & " - ")
            For $j=0 to UBound($value)-1
                ConsoleWrite($value[$j] & "    ")
ConsoleWrite("Rect structure with reference stored in sorted list:" & @CRLF)
ConsoleWrite("x1: " & DllStructGetData(Eval($list("rectstruct")),1) & @CRLF)
ConsoleWrite("y1: " & DllStructGetData(Eval($list("rectstruct")),2) & @CRLF)
ConsoleWrite("x2: " & DllStructGetData(Eval($list("rectstruct")),3) & @CRLF)
ConsoleWrite("y2: " & DllStructGetData(Eval($list("rectstruct")),4) & @CRLF)

This outputs:

test: 6
a - dfdsappa
autoitarray - 1 2   3   4   a   b   c   d   
f - asa
h - qqwrtsappa
rectstruct - rectstructure
z - sappa
Rect structure with reference stored in sorted list:
x1: 10
y1: 20
x2: 64
y2: 48
+>AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 10.077

(Yes, I know, the time on that is ridiculous - I think it is counting the compilation time from AU3Wrapper, though. A message box at the start of the script gives a reference point from which execution is almost instantaneous. Has anyone else noticed this?)

I look forward to hearing others' experiences with this. This is an incredible discovery, gadzail!

Edited by sohfeyr
Link to comment
Share on other sites

  • 2 weeks later...


this is awesome !!

i like to have hashtables in auto it , now i can :-))

; http://msdn2.microsoft.com/en-us/library/system.collections.hashtable.aspx

$hash = ObjCreate("System.Collections.Hashtable")
$hash.add ("txt", "notepad.exe")
$hash.add ("bmp", "paint.exe")
$hash.add ("dib", "paint.exe")
$hash.add ("rtf", "wordpad.exe")

ConsoleWrite("For key = 'bmp', value = " & $hash ("bmp") & @CRLF)
ConsoleWrite("For key = 'rtf', value = " & $hash ("rtf") & @CRLF)
Link to comment
Share on other sites

  • 7 years later...

Good find thanks guys!

This is an example that don't think has been discussed before. I had a need to add items to a specific index within the collection and came up with this.


Global $Collection = ObjCreate("System.Collections.ArrayList")
$Collection.Insert(0, "Hello")
ConsoleWrite($Collection.Item(0) & @CRLF)
Link to comment
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...