WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Intercepting WinPopUp - Mailslot Tricks

Keywords: 	  mailslot

Question:

Is it possible to write a continuous running script to intercept and write to a text file the data sent by the Winpopup function on either a Win95 or WinNT40 box? This would be used by security personnel.

Answer:

Yes. See the following 2 files. One of them can send messages, the other can receive them.

You can't have winpopup run at the same time though.


SendMailSlot.WBT

;To write a message to a mailslot, a process uses the CreateFile function, specifying the mailslot name by using one of the following formats: 
;Format Usage 
;\\.\mailslot\name Retrieves a client handle to a local mailslot. 
;\\computername\mailslot\name Retrieves a client handle to a remote mailslot. 
;\\domainname\mailslot\name Retrieves a client handle to all mailslots with the specified name in the specified domain. 
;\\*\mailslot\name Retrieves a client handle to all mailslots with the specified name in the system's primary domain. 
;If CreateFile specifies a domain or uses the asterisk format to specify the system's primary domain, the application cannot write more than 424 bytes at a time to the mailslot. If the application attempts to do so, the WriteFile function fails and GetLastError returns ERROR_BAD_NETPATH. 
;An application must specify the FILE_SHARE_READ flag when using CreateFile to retrieve a client handle to a mailslot. 
DaDll=strcat(DirWindows(1),"kernel32.dll")
WaitForever = -1
mailslotname="\\.\mailslot\messngr"
GENERIC_WRITE = 1073741824; 0x40000000
FILE_SHARE_READ = 1
FILE_SHARE_WRITE = 2
CREATE_NEW = 1
FILE_ATTRIBUTE_NORMAL = 128

DesiredAccess = Generic_Write
ShareMode = FILE_SHARE_READ
HowCreate = CREATE_NEW ;?????
flags = FILE_ATTRIBUTE_NORMAL
handle=DllCall(DaDll,long:"CreateFileA",lpstr:mailslotname,long:DesiredAccess,long:ShareMode,lpnull, long:HowCreate, long:flags, lpnull)
msgbuf = BinaryAlloc(500)
teststring = "Testing this msg thingie. How are we doing this fine day?"
BinaryPokeStr(msgbuf, 0, teststring)
NumBytes = BinaryEODGet(msgbuf) + 1
NumBytesWritten = BinaryAlloc(10)
result = DllCall(DaDll,long:"WriteFile", long:handle, lpbinary:msgbuf, long:NumBytes, lpbinary:NumBytesWritten, lpnull)

DllCall(DaDll,long:"CloseHandle",long:handle)


MailSlot.WBT

DaDll=strcat(DirWindows(1),"kernel32.dll")

WaitForever = -1
mailslotname="\\.\mailslot\messngr"
handle=DllCall(DaDll,long:"CreateMailslotA",lpstr:mailslotname,long:0,long:WaitForever,lpnull)

bbnextsize=BinaryAlloc(4)
BinaryPoke4(bbnextsize,0,0)
bbmsgcount=BinaryAlloc(4)
BinaryPoke4(bbmsgcount,0,0)


while 1
   rslt=DllCall(DaDll,long:"GetMailslotInfo",long:handle,lpnull,lpbinary:bbnextsize,lpbinary:bbmsgcount,lpnull)
   nextsize=BinaryPeek4(bbnextsize,0)
   msgcount=BinaryPeek4(bbmsgcount,0)
   if msgcount!=0 then break
	TimeDelay(1)
;   Display(4,nextsize,msgcount)
endwhile

BinaryFree(bbnextsize)
BinaryFree(bbmsgcount)

bbread=BinaryAlloc(nextsize)
BinaryEODSet(bbread,nextsize)
bbbytes=BinaryAlloc(4)
BinaryPoke4(bbbytes,0,0)
rslt=DllCall(DaDll,long:"ReadFile",long:handle,lpbinary:bbread,long:nextsize,lpbinary:bbbytes,lpnull)
msg=BinaryPeekStr(bbread,0,nextsize)
BinaryFree(bbread)
BinaryFree(bbbytes)
DllCall(DaDll,long:"CloseHandle",long:handle)
Message("Msg",msg)

Article ID:   W14292
Filename:   Intercepting WinPopUp - Mailslot Tricks.txt
File Created: 1999:11:05:16:31:38
Last Updated: 1999:11:05:16:31:38