locked
Using VB.net objects from VB script? RRS feed

  • Question

  • Hi,
    I'm using an email server program that allows you to plug code in event handlers that you write in VB script event handlers provided by the mail server.  (E.G when a new mail item arrives the VBScript method "NewMailEvent" mail runs, and you can put custom code in the event handler when that happens.

    I have a fairly heavy process that I want to trigger within these event handlers, which I have authored in VB.net as a class library, but I can't quite figure out how to call the instantiate and call the VB.net object methods from within the VBScript event handler.
    I suspect it is "GetObject" or CreateObject or something, but I'm not sure how I actually specify the Prog.ID or whatever.

    I would prefer not to install anything in GAC or have to register the .dll on the server -- if I could just refer to the path name for the dll, or even access an VB.net windows forms application that is running on the same machine at the same time that work as well.  

    (I don't need remoting or anything like that.  The class library is present on the same machine that hosts this email server.)

    Thursday, July 23, 2009 5:21 AM

Answers

  • if you want to get an application using vbscript you can use something like this

    Dim shell
    set shell = WScript.CreateObject( "WScript.Shell" )

    'run an application using this
    shell.Run "path to file"

    'activate an open application using this
    Shell.AppActivate("application process name")

    'send strokes to application
    shell.sendkeys "OK"

    WScript.Quit



    you can also start the application and then use a loop and sleep to activate the application before doing anything with it.


    FREE DEVELOPER TOOLS, CODE & PROJECTS at www.srsoft.us Database Code Generator and Tutorial
    • Marked as answer by Yichun_Feng Wednesday, July 29, 2009 6:44 AM
    Saturday, July 25, 2009 12:04 AM

All replies

  • Hi,

    The only way I know to do this would be if you made the class COM aware. Now the thing is as I know it you would need to install to the GAC and register the DLL (the fact you specifically stated you don't want to do this means you've looked at COM) but there may be another option but it's an unknown and you'll need to try it.

    There is a way to deploy COM without needing to register the DLL, it's used by ClickOnce and it's called Registration-Free COM.

    http://msdn.microsoft.com/en-us/magazine/cc188708.aspx



    There is another option, write a console application that accepts command line arguments and then call the exe from VBScript. The command might be called Shell, if not then it will called that, i.e. a search for shelling an application from VBScript might give you example code.
    www.dsmyth.net | www.dsmyth.net/wiki
    Friday, July 24, 2009 9:38 PM
  • if you want to get an application using vbscript you can use something like this

    Dim shell
    set shell = WScript.CreateObject( "WScript.Shell" )

    'run an application using this
    shell.Run "path to file"

    'activate an open application using this
    Shell.AppActivate("application process name")

    'send strokes to application
    shell.sendkeys "OK"

    WScript.Quit



    you can also start the application and then use a loop and sleep to activate the application before doing anything with it.


    FREE DEVELOPER TOOLS, CODE & PROJECTS at www.srsoft.us Database Code Generator and Tutorial
    • Marked as answer by Yichun_Feng Wednesday, July 29, 2009 6:44 AM
    Saturday, July 25, 2009 12:04 AM