Creates or opens a shared memory instance.
SharedMemOpen(mem-name, global)
(s) mem-name specifies the identifying name of a new or existing shared memory instance.
(i) global set to @True to allow other user processes to read and write to theI shared memory.
(i) @True on success: otherwise, @False.
SharedMemOpen creates a new shared memory instance when the passed in name does not exist. If another script has already created a shared memory instance with the same name, the calling script gains access to that shared memory by calling the SharedMemOpen function. WinBatch supports a maximum of 8 shared memory instances per script (system process).
After this function is called the SharedMemRead and SharedMemWrite functions can use the shared memory name (mem-name) to read from and write to the shared memory instance.
Mem-name
The shared memory name string is limited 126 characters. The name can contain any character except the backslash character (\) and is case sensitive.
Global
This parameter controls whether or processes in other user sessions on the current system can gain access to the named memory. If set to @True (1) other sessions will be able to access the shared memory. Setting to @False (0) prevents other sessions from accessing the named memory.
Note: Set this parameter to the same value for all scripts using the same mem-name instance.
;;------------ ;; GetUpTime.WBT ;;------------ IntControl(12,5,0,0,0);Terminate quietly CmdName = "UptimeCmd" ; Case sensitive DataName = "UptimeData" ; Case sensitive WriteTimeout = 30 ReadTimeout = 60 Notice = @crlf:@crlf:"[ Press CTRL+BREAK to exit script ]" BoxOpen("Uptime Client","Initializing connection to shared memory...") OK = SharedMemOpen(CmdName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory command creation/open failed') OK = SharedMemOpen(DataName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory data creation/open failed') ; Send a request for the server up time. Response = "nothing" Request = "SEND_UPTIME" ReqWait = 1 ;Wait for a response. While ReqWait ReqTimeout = SharedMemWrite(CmdName, Request, WriteTimeout) If !ReqTimeout BoxText(Request:" timed out without response.") Break EndIf BoxText("Waiting for a respones to request: ":Request:Notice) Response = SharedMemRead(DataName, ReadTimeout) If Response != "*NODATA*" || Response != "*TIMEOUT*" Request = "EXIT" SharedMemWrite(CmdName, Request, WriteTimeout) ReqWait = 0 EndIf EndWhile SharedMemClose(CmdName) SharedMemClose(DataName) Message("Uptime Example","Sever up time is ":Response:" exiting") Exit ;;------------ ;; ServerUpTime.WBT ;;------------ IntControl(12,5,0,0,0) ;Terminate quietly WriteTimeout = 30 ReadTimeout = -1 ; Forever. Starttime = GetTickCount64() CmdName = "UptimeCmd" ; Case sensitive DataName = "UptimeData" ; Case sensitive Request = "GET_UPTIME" Notice = @crlf:@crlf:"[ Press CTRL+BREAK to exit script ]" BoxOpen("Get Uptime Example","Initializing connection to shared memory...") OK = SharedMemOpen(CmdName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory command creation/open failed') OK = SharedMemOpen(DataName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory data creation/open failed') BoxOpen("Uptime Server","Initializing - Awaiting request ":Notice) ReqWait = 1 While ReqWait ; Wait for a request Request = SharedMemRead(CmdName, ReadTimeout) BoxText("Request received: ":Request) If Request == "*NODATA*" || Request == "*TIMEOUT*" Continue ; Not likely to ever get here ElseIf Request == "SEND_UPTIME" Uptime = GetTickCount64() - Starttime Response = Uptime/1440000:' days ':Uptime/60000:' min. ' Response := (Uptime mod 60000)/1000.0:' sec.' bWriteOk = SharedMemWrite(DataName, response, WriteTimeout) If !bWriteOk Then ReqWait = 0 Else BoxText("Sent uptime ":Response) ElseIf Request == "EXIT" ReqWait = 0 EndIf EndWhile SharedMemClose(CmdName) SharedMemClose(DataName) Message("Uptime Example","Exit command received. Server exiting") Exit