Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Re: Alternative to PowerShell...

Reply
 
Old 06-02-2008   #1 (permalink)
Andreas M.


 
 

Re: Alternative to PowerShell...

On 15.05.2008 19:13 Blue Streak wrote
Quote:

> This version of the script engine support C#, JScript.NET, VB.NET, and
> J#. It requires the .NET Framework 2.0 as well as the J# 2.0
Is it interoperable with the ActiveX/WSH stuff? For example, I tend to
prefer applications, that come with an ActiveX host (see klient.com,
zeusedit.com, SpeedCommander12, etc.) Now I would be glad to access .NET
from ActiveX hosts like these. Is that possible? Why not dispose your
scripting-host as a COM object to system? Or is it?

--
Bye,
Andreas M.

My System SpecsSystem Spec
Old 06-16-2008   #2 (permalink)
Blue Streak


 
 

Re: Alternative to PowerShell...

On Jun 2, 9:12*pm, "Andreas M." <unkn...@xxxxxx> wrote:
Quote:

> On 15.05.2008 19:13 Blue Streak wrote
>
Quote:

> > This version of the script engine support C#, JScript.NET, VB.NET, and
> > J#. It requires the .NET Framework 2.0 as well as the J# 2.0
>
> Is it interoperable with the ActiveX/WSH stuff? For example, I tend to
> prefer applications, that come with an ActiveX host (see klient.com,
> zeusedit.com, SpeedCommander12, etc.) Now I would be glad to access .NET
> from ActiveX hosts like these. Is that possible? Why not dispose your
> scripting-host as a COM object to system? Or is it?
>
> --
> Bye,
> Andreas M.
Andreas,

Yeah, I've been working on ActiveX / COM access.

The focus of this script engine is to run .NET code as a
"script". I have put quotes around the word script for a reason
because the code is not interpreted but compiled (in memory) then
executed. I'm not sure it would make much sense to access this as a
COM object because any advanced features (e.g. handling text files,
ADO, advanced / user-defined data structures) are really coming from
the .NET framework itself. The WSH script engine, on the other hand,
can be handy when you are manipulating text files from VB6, for
example.

However, you can access ActiveX / COM objects from .NET. If you
were using VS.NET you would simply select: Project >> Add Reference >>
(and check off the ActiveX object you want) then just reference that
in your code. It is not so simple from my (can I say "my"?) script
engine. I managed to dig an example of late binding from Microsoft
and make it work:

----Late Binding.ncs----
using System;
using System.Reflection;
using System.Windows.Forms;

namespace Test
{
class LateBinding
{
//This example uses late binding to call an ActiveX object

public static void Main(string[] args)
{
object objApp_Late;
object objBook_Late;
object objBooks_Late;
object objSheets_Late;
object objSheet_Late;
object objRange_Late;
object[] Parameters;

try
{
// Get the class type and instantiate Excel.
Type objClassType =
Type.GetTypeFromProgID("Excel.Application");
objApp_Late = Activator.CreateInstance(objClassType);

//Get the workbooks collection.
objBooks_Late =
objApp_Late.GetType().InvokeMember("Workbooks",
BindingFlags.GetProperty, null, objApp_Late, null);

//Add a new workbook.
objBook_Late =
objBooks_Late.GetType().InvokeMember("Add", BindingFlags.InvokeMethod,
null, objBooks_Late, null);

//Get the worksheets collection.
objSheets_Late =
objBook_Late.GetType().InvokeMember("Worksheets",
BindingFlags.GetProperty, null, objBook_Late, null);

//Get the first worksheet.
Parameters = new Object[1];
Parameters[0] = 1;
objSheet_Late =
objSheets_Late.GetType().InvokeMember("Item",
BindingFlags.GetProperty, null, objSheets_Late, Parameters);

//Get a range object that contains cell A1.
Parameters = new Object[2];
Parameters[0] = "A1";
Parameters[1] = Missing.Value;
objRange_Late =
objSheet_Late.GetType().InvokeMember("Range",
BindingFlags.GetProperty, null, objSheet_Late, Parameters);

//Write "Hello, World!" in cell A1.
Parameters = new Object[1];
Parameters[0] = "Hello, World!";
objRange_Late.GetType().InvokeMember("Value",
BindingFlags.SetProperty, null, objRange_Late, Parameters);

//Return control of Excel to the user.
Parameters = new Object[1];
Parameters[0] = true;
objApp_Late.GetType().InvokeMember("Visible",
BindingFlags.SetProperty, null, objApp_Late, Parameters);
objApp_Late.GetType().InvokeMember("UserControl",
BindingFlags.SetProperty, null, objApp_Late, Parameters);
}
catch (Exception ex)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage,
ex.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, ex.Source);

MessageBox.Show(errorMessage, "Error");
}

}

}

}
------

This opens up a copy of Excel and writes "Hello World!" into cell A1.
I'm still trying to get the example of early binding to work.

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Alternative to PowerShell... VB Script
Re: Alternative to PowerShell... VB Script
Alternative to Run Vista installation & setup
ADV-NEWS, Dell may offer Linux as alternative to Windows, OpenOffice as an alternative to M$ Office Vista General
An alternative console window for PowerShell PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46