Windows Vista Forums

Re: Alternative to PowerShell...

  1. #1


    Andreas M. Guest

    Re: Alternative to PowerShell...

    On 15.05.2008 19:13 Blue Streak wrote

    > 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

  2. #2


    Blue Streak Guest

    Re: Alternative to PowerShell...

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

    > On 15.05.2008 19:13 Blue Streak wrote
    >

    > > 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

Re: Alternative to PowerShell...

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Alternative to PowerShell... Blue Streak VB Script 4 24 May 2008
Re: Alternative to PowerShell... Alex K. Angelopoulos VB Script 0 24 May 2008
ADV-NEWS, Dell may offer Linux as alternative to Windows, OpenOffice as an alternative to M$ Office Cymbal Man Freq. Vista General 4 07 Mar 2007
Wab or WAB alternative? Photubias Vista mail 1 06 Oct 2006
An alternative console window for PowerShell =?Utf-8?B?ZHJlZXNjaGtpbmQ=?= PowerShell 0 29 Aug 2006