Thanks for any suggestion!

This all depends on the security settings you use. The functions that create shared objects (such as files or memory mapped files)Inf0Byt3 wrote:I needed this advice too. I've noticed so far that you need administrator priviledges to use meory mapped files. Even it the service (that was started and installed by an admin) was creating a file, the lower priviledged process that needed to communicate with it via readfilemapping also needed admin privs. That's bad... At the end i started using network commands and made a local server and a client.
@Freak, I don't have Vista around. Would a simple client/sever based on local networking work?
Tried this. Made a service with PBOSL libs and used the code from the forum to create some procedures to syncronize fixed strings.I'm using mapped files on all my applications from longtime, and no problems with user privileges on NT, 2K and XP.
Yes, I'm using always:freak wrote:This all depends on the security settings you use. The functions that create shared objects (such as files or memory mapped files)
usually take a SECURITY_ATTRIBUTES pointer as parameters. Thats what determines the access rights.
Code: Select all
MAPfile = CreateFileMapping_($FFFFFFFF,0,#PAGE_READWRITE,0,filesize,filename)
The lpSecurityDescriptor member of this structure specifies a security descriptor for a new file mapping object. If lpAttributes is NULL, the file mapping object gets a default security descriptor. The access control lists (ACL) in the default security descriptor for a file mapping object come from the primary or impersonation token of the creator. For more information, see File Mapping Security and Access Rights.
Code: Select all
Structure StringIPC
s.s{#MAX_PATH}
EndStructure
#SDDL_REVISION_1 = 1
#SDDL_STRING = "S:(ML;;NW;;;LW)"
SecAttr.SECURITY_ATTRIBUTES
SecDesc.s = Space(#SECURITY_DESCRIPTOR_MIN_LENGTH)
SecAttr\nLength = SizeOf(SECURITY_ATTRIBUTES)
SecAttr\bInheritHandle = #False
SecAttr\lpSecurityDescriptor = 0
If InitializeSecurityDescriptor_(@SecAttr, #SECURITY_DESCRIPTOR_REVISION)
If SetSecurityDescriptorDacl_(@SecAttr, #True, 0, #False)
If OpenLibrary(0,"Advapi32.dll")
pSD.SECURITY_DESCRIPTOR
CallFunction(0,"ConvertStringSecurityDescriptorToSecurityDescriptor",#SDDL_STRING,#SDDL_REVISION_1,@SecAttr\lpSecurityDescriptor,#Null)
pSacl = #Null
fSaclPresent = #False
fSaclDefaulted = #False
GetSecurityDescriptorSacl_(pSD,@fSaclPresent,@pSacl,@fSaclDefaulted)
SetSecurityDescriptorSacl_(@SecAttr, #True, @pSacl, #False)
Else
MessageRequester("Error","Could not open Advapi32.dll. Please install the required file.",#MB_ICONSTOP):End
EndIf
EndIf
Else
MessageRequester("Error","Could not initialize the security descriptor.",#MB_ICONSTOP):End
EndIf
*hfm = CreateFileMapping_($FFFFFFFF,0,#PAGE_READWRITE,0,SizeOf(StringIPC),"map")
*ptr.StringIPC = MapViewOfFile_(*hfm,#FILE_MAP_ALL_ACCESS,0,0,0)
OpenConsole()
Repeat
Delay(500)
If *ptr\s <> ""
PrintN(*ptr\s)
EndIf
ForEver
Code: Select all
;Receiver
Structure StringIPC
s.s{#MAX_PATH}
EndStructure
*hfm = CreateFileMapping_($FFFFFFFF,0,#PAGE_READWRITE,0,SizeOf(StringIPC),"map")
*ptr.StringIPC = MapViewOfFile_(*hfm,#FILE_MAP_WRITE,0,0,0)
Repeat
Debug *ptr\s
ForEver
Code: Select all
;Sender
Structure StringIPC
s.s{#MAX_PATH}
EndStructure
*hfm = CreateFileMapping_($FFFFFFFF,0,#PAGE_READWRITE,0,SizeOf(StringIPC),"map")
*ptr.StringIPC = MapViewOfFile_(*hfm,#FILE_MAP_ALL_ACCESS,0,0,0)
*ptr\s = "test test test"
Code: Select all
Structure StringIPC
s.s{#MAX_PATH}
EndStructure
#SERVICE_BOOT_START = $00000000
#SERVICE_SYSTEM_START = $00000001
#SERVICE_AUTO_START = $00000002
#SERVICE_DEMAND_START = $00000003
#SERVICE_DISABLED = $00000004
;
Global ServiceName.s = "ASrv"
Global ServiceDisplayName.s = "A Service"
Global ServiceExplanation.s = "A - this service is a simple test"
;
Procedure MyServiceFunction()
sd.SECURITY_DESCRIPTOR
InitializeSecurityDescriptor_(@sd, #SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl_(@sd, #True, #Null, #False)
sa.SECURITY_ATTRIBUTES
sa\nLength = SizeOf(SECURITY_ATTRIBUTES);
sa\bInheritHandle = #False;
sa\lpSecurityDescriptor = @sd;
*m_MapHandle = CreateFileMapping_(#INVALID_HANDLE_VALUE, @sa, #PAGE_READWRITE, 0, SizeOf(StringIPC),"map")
*ptr.StringIPC = MapViewOfFile_(*m_MapHandle,#FILE_MAP_ALL_ACCESS,0,0,0)
OpenConsole()
Repeat
Delay(500)
If *ptr\s <> ""
PrintN(*ptr\s)
EndIf
ForEver
EndProcedure
Select LCase(ProgramParameter())
Case "/i"
Installservice(ServiceName,ServiceDisplayName,ProgramFilename(),ServiceExplanation,#SERVICE_AUTO_START)
End
Case "/r"
RemoveService(ServiceName)
End
EndSelect
Service(ServiceName.s,@MyServiceFunction(),0)
Code: Select all
Structure StringIPC
s.s{#MAX_PATH}
EndStructure
*m_MapHandle = CreateFileMapping_(#INVALID_HANDLE_VALUE, @sa, #PAGE_READWRITE, 0, SizeOf(StringIPC),"map")
*ptr.StringIPC = MapViewOfFile_(*m_MapHandle,#FILE_MAP_ALL_ACCESS,0,0,0)
*ptr\s = "Alex"
Code: Select all
How to install and remove:
BEAMSrv.exe /i OR BEAMSrv.exe /r
How to start/stop:
net start ASrv OR net stop ASrv