Jump to content

Recommended Posts

  • 3 months later...
  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

This way of communication between processes very much resemble to the communication we do with our mail accounts. I would guess (smartly, no doubt) that was the key factor used for naming the function

I know this is pretty old now but i was trying to get comms accross local system, admin and limited users for months in windows 10 and was just not having any luck with anything at all. ended up

Data transfer between AutoIt and VBScript can be performed using ROT objects as demonstrated in this example. ROT objects also have the advantage that arrays can be transferred directly and that the i

Hey everyone!

I was hoping someone might be able to help me with this.  I am pretty sure this great UDF is going to be the solution to my current script problems.  Basically, I need to be able to have a central computer send a message to every computer in a workgroup.  I am using the given script examples, which are for locally testing on the same computer ("\\.\mailslot\Test") and it works great.  After reading up on it a bit, I saw that in order to broadcast to everything in a workgroup, you would simply need to replace "." with the name of the workgroup ("\\Workgroup\mailslot\Test").  However, when I do this, the Sender comes up fine, but the Receiver will not start, citing that it's unable to create the mailslot because it likely already exists.

Does anyone have any ideas on why this might be?  I am still pretty new to this whole thing, so apologies if it's something extremely simple that I'm overlooking.  Is there more than one change here that I need to make to the script for it to function over a network?

Thanks in advance for any advice!

Link to post
Share on other sites

Unfortunately same message is coming up no matter how I try :( I'm attempting to look up how to use it over a network, but everything I'm finding basically gets summed up as "yeah it's super easy" and never actually elaborates on it.  Is anyone out there using this over their local network, and if so, how??

Thank you for your help!

Link to post
Share on other sites

Sure thing @dmob:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include "MailSlot.au3"

Global Const $sMailSlotName = "\\WORKGROUP\mailslot\Test"

Global $hMailSlot = _MailSlotCreate($sMailSlotName)
;MsgBox(48, "MailSlot demo", $hMailSlot, 0)
;Global $hMailSlot = $sMailSlotName
If @error Then
    MsgBox(48 + 262144, "MailSlot", "Failed to create new account!" & @CRLF & "Probably one using that 'address' already exists.")
    Exit
EndIf

Global $iNumberOfMessagesOverall

Global $hGUI = GUICreate("MailSlot Demo Receiver", 450, 400, 3 * @DesktopWidth / 4 - 225, -1, -1, 8) ; $WS_EX_TOPMOST

GUICtrlCreateLabel("Message text:", 10, 22, 100, 25)
GUICtrlSetColor(-1, 0x0000CC)
GUICtrlSetFont(-1, 11)

Global $hEdit = GUICtrlCreateEdit("", 15, 50, 300, 340)

Global $hButtonRead = GUICtrlCreateButton("Read &Mail", 330, 50, 100, 25)

Global $hButtonCheckCount = GUICtrlCreateButton("&Check Mail Count", 330, 100, 100, 25)

Global $hButtonCloseAccount = GUICtrlCreateButton("Close Mail &Account", 330, 150, 100, 25)

Global $hButtonRestoreAccount = GUICtrlCreateButton("&Restore Account", 330, 200, 100, 25)

Global $hButtonCloseApp = GUICtrlCreateButton("&Exit", 330, 350, 100, 25)

GUISetState()


While 1

    Switch GUIGetMsg()
        Case - 3, $hButtonCloseApp
            Exit
        Case $hButtonRead
            If $hMailSlot Then
                _ReadMessage($hMailSlot)
            Else
                MsgBox(48, "MailSlot demo", "No account is available!", 0, $hGUI)
            EndIf
        Case $hButtonCheckCount
            If $hMailSlot Then
                _CheckCount($hMailSlot)
            Else
                MsgBox(48, "MailSlot demo", "No account is available!", 0, $hGUI)
            EndIf
        Case $hButtonCloseAccount
            If $hMailSlot Then
                _CloseMailAccount($hMailSlot)
            Else
                MsgBox(64, "MailSlot demo", "No account is available!", 0, $hGUI)
            EndIf
        Case $hButtonRestoreAccount
            If $hMailSlot Then
                MsgBox(64, "MailSlot demo", "This account already exists!", 0, $hGUI)
            Else
                _RestoreAccount($sMailSlotName)
            EndIf
    EndSwitch

WEnd


; Wrapper functions:

Func _ReadMessage($hHandle)

    Local $iSize = _MailSlotCheckForNextMessage($hHandle)

    If $iSize Then
        Local $sData = _MailSlotRead($hMailSlot, $iSize, 1)
        $iNumberOfMessagesOverall += 1
        GUICtrlSetData($hEdit, "Message No" & $iNumberOfMessagesOverall & " , Size = " & $iSize & " :" & @CRLF & @CRLF & $sData)
    Else
        MsgBox(64, "Nothing read", "MailSlot is empty", 0, $hGUI)
    EndIf

EndFunc   ;==>_ReadMessage


Func _CheckCount($hHandle)

    Local $iCount = _MailSlotGetMessageCount($hHandle)
    Switch $iCount
        Case 0
            MsgBox(64, "Messages", "No new messages", 0, $hGUI)
        Case 1
            MsgBox(64, "Messages", "There is 1 message waiting to be read.", 0, $hGUI)
        Case Else
            MsgBox(64, "Messages", "There are " & $iCount & " messages waiting to be read.", 0, $hGUI)
    EndSwitch

EndFunc   ;==>_CheckCount


Func _CloseMailAccount(ByRef $hHandle)

    If _MailSlotClose($hHandle) Then
        $hHandle = 0
        MsgBox(64, "MailSlot demo", "Account succesfully closed.", 0, $hGUI)
    Else
        MsgBox(48, "MailSlot demo error", "Account could not be closed!", 0, $hGUI)
    EndIf

EndFunc   ;==>_CloseMailAccount


Func _RestoreAccount($sMailSlotName)

    Local $hMailSlotHandle = _MailSlotCreate($sMailSlotName)

    If @error Then
        MsgBox(48, "MailSlot demo error", "Account could not be created!", 0, $hGUI)
    Else
        MsgBox(64, "MailSlot demo", "New account with the same address successfully created!", 2, $hGUI)
        $hMailSlot = $hMailSlotHandle ; global var
    EndIf

EndFunc   ;==>_RestoreAccount

 

Link to post
Share on other sites
On 9/16/2019 at 11:09 AM, maloysius said:

Global Const $sMailSlotName = "\\WORKGROUP\mailslot\Test" Global $hMailSlot = _MailSlotCreate($sMailSlotName)

why, oh, why. What's wrong with declaring on your PC a mailslot ?, why the workgroup ? :mad2:

On your PC you'd use "\\.\" and if you wanna broadcast to the workgroup, use the same everything but start with "\\*\", that is all ;) 

Link to post
Share on other sites
  • 2 weeks later...
  • 5 months later...

Quick note to anyone who knows nothing about MailSlots (like me)... make sure to name the MailSlot like this "\\.\mailslot\" then whatever you want... Otherwise it will fail. Repeatedly. :mad2:

On the other hand, thank you very much for this UDF, it's very helpful! (Once I understand it)

Edit: Hmm... maybe I should read the function documentation better 😐

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites
  • 8 months later...

@trancexx

There is a tiny little typo in your demo: MailSlot_Reciever.au3.

Thanks for sharing your code! 👍

 

I am desperately looking for a two way communication between VBScript and AutoIt. With your code, the direction from VBScript to AutoIt works, but I haven't found a way to set up the other direction, which is from AutoIt to VBScript. It seems that you can't create a mailslot receiver (server) in VBScript.

Can you or someone else help there? Is there any chance to receive messages from AutoIt in VBScript?

 

Link to post
Share on other sites
20 hours ago, Professor_Bernd said:

It seems that you can't create a mailslot receiver (server) in VBScript.

'MailSlot_Sender.vbs

'An very simple Mailslot client with VBScript
'No error checking
'Just demonstrates sending a single line

Set FSO = CreateObject("Scripting.FileSystemObject")

FileName = "\\.\mailslot\RandomNameForThisTest"
set SlotFile = fso.CreateTextFile(FileName)

'use Write, not Writeline
'Null-terminate strings, if that is what mailslot server "expects"

SlotFile.Write("A message from VBScript" & chr(0))

SlotFile.Close
WScript.Quit

hmm, no clue. This is the sender I'm sure you have. Did find a receiver ready made but it may be possible looping but I'm not into it as to thinker one.
In any case I wanted to have the code in the post. Maybe based on this someone can think of a SlotFile.Read or something.

Link to post
Share on other sites

Data transfer between AutoIt and VBScript can be performed using ROT objects as demonstrated in this example. ROT objects also have the advantage that arrays can be transferred directly and that the internal data type of array elements and other variables is preserved during the data transfer.

Link to post
Share on other sites

@argumentum

You guessed right, that's almost exactly the code I use to send messages via MailSlot from VBScript to AutoIt. :) I also appreciate your note about using "write" instead of "writeline" because that confirms what I also found out.

Currently I am still testing out if the communication with MailSlot is fast enough. Right now there is a significant delay, but it's just initial testing. There is still a lot of rebuilding to be done before a statement can be made.

Thanks a lot for your answer!

Edited by Professor_Bernd
"@" tag corrected
Link to post
Share on other sites

@LarsJ Your suggestion sounds good!

I've tried a lot of things, including Access AutoIt with AutoItObject, but none of them were fast enough and the main program (PSPad) was slowed down a lot by the communication.

I looked at the code you linked a bit and it looks really promising!

I'd like to ask you for further help to add the communication to PSPad's VBScript and my CallTipViewer (AutoIt). For this I will study your code first and see how far I understand it. This may take a little time, because my knowledge about ROT and COM is not very big. ;)

Since this is another topic and I don't want to disturb the thread here, I have opened an own thread where we can discuss. :graduated:

Edited by Professor_Bernd
"@" tag corrected
Link to post
Share on other sites
  • 1 year later...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...