Jump to content

Comunication COM Object


torels
 Share

Recommended Posts

Hi there!

I made this COM object to create a communication between 2 apps using files... a very simple VBScript, but I liked the idea i could comunicate between 2 scripts (or 2 programs written in different languages too) without having to set up tcp servers/clients or writing/deleting files all the time :D

I hope you like it :D

Here is the COM bject

<component>
<registration progid="Comunication.Object"/>
<public>
     <method name="GetMessage"/>
     <method name="SetMessage">
        <PARAMETER name="text"/>
     </method>
</public>
<script language="VBScript">
Set WshShell = CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Process")
Dim objFSO, objOutputFile
Dim strOutputFile
Dim out
strOutputFile = objEnv("Temp") & "\tmpmsg.txt"
Set objFSO = CreateObject("Scripting.fileSystemObject")

Function SetMessage(text)
    Set objOutputFile = objFSO.CreateTextFile(strOutputFile, TRUE)
    objOutputFile.Write(text)
    objOutputFile.Close
End Function

Function GetMessage()
    Set objFile = objFSO.OpenTextFile(strOutputFile, 1)
    out = objFile.ReadAll
    objFile.Close
    GetMessage=out
End Function
</script>
</component>

Save this as AnythingYouWant.wsc then run("@comspec & ' /C RegSvr32 /s YourWscFile.wsc'") . This is because you need to register you WSC file. You just have to do it Once.

More info HERE.

here are 2 example scripts:

Script 1

$com = ObjCreate("Comunication.Object");Create the object
$com.SetMessage("hello world");Send the message

Script 2

$com = ObjCreate("Comunication.Object");Create the object
MsgBox(0,"",$com.GetMessage());Get the message

comments, bug reports and suggestions are welcome :o

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

This allows you to comunicate between different programming languages too :D

To do that with a UDF you would have to compile the au3 file and pass parameters to it to use it in other languages, or call autoit3.exe

btw... I had some Doubts weather this was the right section or not. If it isn't could you please move it to chat, or whatever you think is the appropriate section ?

thanks :o

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

While I thank you for showing just how easy it is to create COM objects, I also have to question the usefulness of an entire object to write to/read from a file. We do have functions to do that already, that don't have the additional overhead of Creating and managing COM objects.

Link to comment
Share on other sites

as said in the first post, this is to avoid writing several lines of code to write/read from the file (just take a look at what it takes in vbs) or create a tcp server and client (that is a discrete amount of code, compared to 4 lines :o)

by the way... creating and managing COM objects is very simple and easily accessible :D

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

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
 Share

  • Recently Browsing   0 members

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