You will find a few postings here about using a couple of
those (registered) net framework classes -- but in general
there has been a somewhat negative consensus about using
ALL the net framework classes.
I cam across a posting in the "BCX" (Basic to C Language
Translator) newsgroup (which made reference to a posting
in the PowerBASIC newsgroup) that opened things up a bit.
Although the postings suggest using the LASTEST version
of net framework, the attached script works perfectly
well for me with version 1.1.4322, (the last version
of net framework published by ms for win98 -- my system
of choice).
Although the attached script instantiates the WebClient
class, there is an entire (extensive) collection of
classes in system.dll, as you can see if you take a look
at system.tlb with a typelib browser. However, the
typelib browser will only give you the CLASSES in the
system.dll. For the methods and properties you will
have to go to msdn (or perhaps your vb.net help file).
Note that before you can run the script, you have to
have some version of net framework installed, and you
have to use regasm (NOT regsvr32) to register the
System.dll. There is also a "bat" file attached,
which I used to regasm the system.dll on my system.
On your system, you would need to change the path to
the net framework directory, to comply with the path
you chose.
cheers, jw
p.s. as usual, I changed the file extensions to "txt",
to avoid any AV programs from warning you about
downloading "malicious" scripts...
----------------------------------------------------------------------------
----
> ' ------------------------------------------------
> ' Calling .NET classes from VBS, jw 30Nov09
> ' ------------------------------------------------
> ' First, you must install the .Net Framework from Microsoft.
> ' then run [file path] regasm system.dll (to register the classes)
> '
> ' --- acknowledgment -----------------------------
> ' This code was originally developed by Jos� Roca (a PowerBASIC guru)
> '
http://www.jose.it-berater.org/smfforum/index.php?topic=3053.msg9447#msg9447
> '
> ' I found the code on the "BCX" (Basic to C Language Translator) ng, here:
> '
http://basic-compiler.com/forum/index.php?PHPSESSID=mjvdi6j7blfoda3p5qftvp5b
r7&topic=35.0
> ' ------------------------------------------------
>
> Dim wshShell : Set wshShell = WScript.CreateObject("WScript.Shell")
> Dim sCurDir : sCurDir = wshShell.CurrentDirectory
>
>
> DIM oWebClient ' as object
> DIM sURL ' as string
> DIM sFileSpec ' as string
>
> Set oWebClient = CreateObject("System.Net.WebClient")
>
> sURL = "http://www.bcxgurus.com/bcxlogo.jpg"
>
> sFileSpec = sCurDir & "\bcxlogo.jpg"
>
> oWebClient.DownloadFile sURL, sFileSpec
>
> MsgBox "Your File is here: " & sFileSpec, vbInformation, "vbs Script
Finished.. "
>
> Set oWebClient = nothing
> Set wshShell = nothing
> WScript.Quit
>
----------------------------------------------------------------------------
----
> rem batch file to regasm [net framework] system.dll
>
> cd C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
>
> regasm system.dll
But these limitations still apply:
http://msdn.microsoft.com/en-us/library/7fcfby2t.aspx
especially the one that .Net types must have a public parameterless
constructor to be activated from COM.
--
urkec