sharing variables between scripts with dynawrap case study #3
- From: omen999 <omen999z@xxxxxxxxx>
- Date: Fri, 08 Jun 2007 11:58:23 -0700
an old problem revisited...
two scripts:
server.vbs which set shared string and client.vbs which get shared
string
enjoy
server.vbs:
Option Explicit
Const INVALID_HANDLE_VALUE=-1
Const PAGE_READWRITE=4
Const FILE_MAP_WRITE=2
Function GetBSTRPtr(ByRef sData)
Dim pSource,pDest
pSource=oApi.lstrcat(sData,"")
pDest=oApi.lstrcat(GetBSTRPtr,"")
GetBSTRPtr=CLng(0)
oApi.RtlMoveMemory pDest+8,pSource+8,4
End Function
Sub SetShared(ByRef sVar)
oApi.RtlMoveMemory lMapView,GetBSTRPtr(sVar),LenB(sVar)
End Sub
Dim oApi,hFile,sSharedSpace,lMapView
Dim sTest
sSharedSpace="ACME"
Set oApi=CreateObject("DynamicWrapper")
oApi.Register
"kernel32.dll","CreateFileMappingA","f=s","i=hlllls","r=h"
oApi.Register "kernel32.dll","MapViewOfFile","f=s","i=hllll","r=l"
oApi.Register "kernel32.dll","UnmapViewOfFile","f=s","i=l","r=l"
oApi.Register "kernel32.dll","CloseHandle","f=s","i=h","r=l"
oApi.Register "kernel32.dll","lstrcat","f=s","i=ws","r=l"
oApi.Register "kernel32.dll","RtlMoveMemory","f=s","i=lll","r=l"
hFile=oApi.CreateFileMappingA(INVALID_HANDLE_VALUE,Null,PAGE_READWRITE,
0,4096,sSharedSpace&"")
lMapView=oApi.MapViewOfFile(hFile,FILE_MAP_WRITE,0,0,0)
sTest="This is an omen999 share test"
SetShared sTest
Msgbox "Server waiting... "
oApi.UnmapViewOfFile lMapView
oApi.CloseHandle hFile
client.vbs:
Option Explicit
Const INVALID_HANDLE_VALUE=-1
Const PAGE_READWRITE=4
Const FILE_MAP_WRITE=2
Function GetBSTRPtr(ByRef sData)
Dim pSource,pDest
pSource=oApi.lstrcat(sData,"")
pDest=oApi.lstrcat(GetBSTRPtr,"")
GetBSTRPtr=CLng(0)
oApi.RtlMoveMemory pDest+8,pSource+8,4
End Function
Function GetShared()
GetShared=String(58,chr(0))
oApi.RtlMoveMemory GetBSTRPtr(GetShared),lMapView,58
End Function
Dim oApi,hFile,sSharedSpace,lMapView
Dim sTest 'shared string variable
sSharedSpace="ACME"
Set oApi=CreateObject("DynamicWrapper")
oApi.Register
"kernel32.dll","CreateFileMappingA","f=s","i=hlllls","r=h"
oApi.Register "kernel32.dll","MapViewOfFile","f=s","i=hllll","r=l"
oApi.Register "kernel32.dll","UnmapViewOfFile","f=s","i=l","r=l"
oApi.Register "kernel32.dll","CloseHandle","f=s","i=h","r=l"
oApi.Register "kernel32.dll","lstrcat","f=s","i=ws","r=l"
oApi.Register "kernel32.dll","RtlMoveMemory","f=s","i=lll","r=l"
hFile=oApi.CreateFileMappingA(INVALID_HANDLE_VALUE,Null,PAGE_READWRITE,
0,4096,sSharedSpace&"")
lMapView=oApi.MapViewOfFile(hFile,FILE_MAP_WRITE,0,0,0)
sTest=GetShared
oApi.UnmapViewOfFile lMapView
oApi.CloseHandle hFile
Msgbox sTest
.
- Follow-Ups:
- Prev by Date: Re: WMI style folder delete
- Next by Date: Re: xcopy and vbscript
- Previous by thread: Finding the lowest OU a user is in
- Next by thread: Re: sharing variables between scripts with dynawrap case study #3
- Index(es):
Relevant Pages
|