Sign in to follow this  
Followers 0
Seeker

Using mailslot?

5 posts in this topic

http://www.autoitscript.com/forum/index.php?showtopic=11144

But still I want to read/write to the mailslot. In VBS you can do it like this:

'Setup some variables
sText = "Here is a message" & vbCrLf & "with a linefeed."
sFrom = "Administrator"

'Create a File System Object
Set oFS = WScript.CreateObject("Scripting.FileSystemObject")

'Send the message to everyone
Call SendMsg(sText, "YourComputer", "YourName", sFrom)


Wscript.Quit
'--- End of Script ----

Sub SendMsg(sMsg, sTo, sGrp, sUser)
    'Define Mailslot name:
    sFN = "\\" + sTo + "\MAILSLOT\messngr"
    'Object Text Stream:
    Set oTS = oFS.CreateTextFile(sFN, True)
    oTS.Write sUser + Chr(0) + sGrp + Chr(0) + sMsg & Chr(0)
    oTS.Close
    Set oTS = Nothing
End Sub

But in autoscript I didn't manage to use those object nor to write directly to malslot:

Func SendMsg($sMsg, $sTo, $sGrp, $sUser)
   ; 'Define Mailslot name:
; $aCallReturn = DllCall('kernel32.dll', 'str', 'CreateMailslot', '\\.\MAILSLOT\messngr', 0, 'MAILSLOT_WAIT_FOREVER', 0)
; MsgBox(0, "test",$aCallReturn)
    $sFN = FileOpen("\\" & $sTo & "\MAILSLOT\messngr", 2)
     MsgBox(0, "test",$sFN)
    FileWrite($sFN, $sUser & Chr(0) & $sGrp & Chr(0) & $sMsg & Chr(0))
EndFunc

Func SendMsg2($sMsg, $sTo, $sGrp, $sUser)
    
   ; $sFN = "\\" & $sTo & "\MAILSLOT\messngr"
    $sFN = "c:\_test.txt"
    $oTS = $oFS.CreateTextFile($sFN, True)
    $oTS.Write($sUser & Chr(0) & $sGrp & Chr(0) & $sMsg & Chr(0))
    $oTS.Close
    
EndFunc

I even tried to use 'kernel32.dll' -call like this:

$sFH = DllCall('kernel32.dll', 'str', 'CreateMailslot', '\\.\MAILSLOT\messngr', 0, 'MAILSLOT_WAIT_FOREVER', 0)

Yes. I do something wrong. But what?

Share this post


Link to post
Share on other sites



AutoIt's FileOpen function uses the low-level fopen() function to do its job, and I'm guessing fopen() doesn't understand NT kernel pseudofiles like \\.\mailslot and \\.\pipe .

By using the COM functions in the AutoIt beta you might be able to make a direct translation of your VBS script.


Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

By using the COM functions in the AutoIt beta you might be able to make a direct translation of your VBS script.

As you can see I even tried that. Didn't work... Next please B)

Share this post


Link to post
Share on other sites

Here is the full code I used to test mailslots. What am I doing wrong?

I've tested so far:

  • Write straight to mailslot pseudofile
  • Converted VBS to AU3 (tried to use these COM-calls)
  • Tried to call kernel32.dll
$sText = "Here is a message"; & @LF & "with a linefeed."
$sFrom = "Administrator"

$oFS = ObjCreate("Scripting.FileSystemObject")

; 'Send the message to everyone
SendMsg($sText, ".", "Administrator", $sFrom)

Func SendMsg($sMsg, $sTo, $sGrp, $sUser)
; $aCallReturn = DllCall('kernel32.dll', 'str', 'CreateMailslot', '\\.\MAILSLOT\messngr', 0, 'MAILSLOT_WAIT_FOREVER', 0)
; MsgBox(0, "test",$aCallReturn)
    $sFN = FileOpen("\\" & $sTo & "\MAILSLOT\messngr", 2)
    FileWrite($sFN, $sUser & Chr(0) & $sGrp & Chr(0) & $sMsg & Chr(0))
EndFunc

Func SendMsg2($sMsg, $sTo, $sGrp, $sUser)
    $sFN = "\\" & $sTo & "\MAILSLOT\messngr"
; $sFN = "c:\_test.txt"
    $oTS = $oFS.CreateTextFile($sFN, True)
    $oTS.Write($sUser & Chr(0) & $sGrp & Chr(0) & $sMsg & Chr(0))
    $oTS.Close
EndFunc

; DllCall("kernel32.dll", "int", "SetConsoleTitle", "str", $NewTitle)
; CreateMailslot(lpszSlotName, 0, MAILSLOT_WAIT_FOREVER, (LPSECURITY_ATTRIBUTES) NULL);
; $sFH = DllCall('kernel32.dll', 'str', 'CreateMailslot', '\\.\MAILSLOT\messngr', 0, 'MAILSLOT_WAIT_FOREVER', 0)
; MsgBox(0, "test",$sFH)

Share this post


Link to post
Share on other sites

As you can see I even tried that. Didn't work... Next please B)

I could see that how? From code you didn't post until today? :o

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
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
Sign in to follow this  
Followers 0