This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Exclusively locking a file
Started by
kirann_hegde
, Nov 03 2009 12:50
11 replies to this topic
Posted 03 November 2009 - 12:50
I have a file in support directory which i need to lock exclusively for the time of the installation.The contents of this file should not be compromised with nor the file to be deleted.
I have not come across any function in Installscript yet which allows me to get an exclusive lock to a file.
The C runtime library does provide functions to accomplish the same. However when i try loading the C runtime library dll's using UseDll, i get the following runtime error:
R6034
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.
I googled about the same and it suggests that the manifest files are missing. However even with the manifest files, i cannot get the runtime library msvcr90.dll to load.
Has anybody ever tried calling runtime library functions before?
Any help would be very much appreciated.
I am trying to use the C runtime library function void _lock_file(
FILE* file
);
How do i use this?I guess to use this i need to load the C runtime libraries. This function is contained in msvcr90.dll . I have been unsucessful trying to load it.
Any ideas?
I have not come across any function in Installscript yet which allows me to get an exclusive lock to a file.
The C runtime library does provide functions to accomplish the same. However when i try loading the C runtime library dll's using UseDll, i get the following runtime error:
R6034
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.
I googled about the same and it suggests that the manifest files are missing. However even with the manifest files, i cannot get the runtime library msvcr90.dll to load.
Has anybody ever tried calling runtime library functions before?
Any help would be very much appreciated.
I am trying to use the C runtime library function void _lock_file(
FILE* file
);
How do i use this?I guess to use this i need to load the C runtime libraries. This function is contained in msvcr90.dll . I have been unsucessful trying to load it.
Any ideas?
Posted 04 November 2009 - 16:04
The dependencies with the Visual C++ runtime libraries aren't really obvious, so you end up needing more of the files than you would expect.
For this and other reasons, such a practice isn't the recommended approach and instead I would go with deploying Microsoft's packaged redistributable (e.g. 2008 RTM [x86], 2008 SP1 [x86]).
With that in place, you certainly should be able to successfully load the required DLL.
For this and other reasons, such a practice isn't the recommended approach and instead I would go with deploying Microsoft's packaged redistributable (e.g. 2008 RTM [x86], 2008 SP1 [x86]).
With that in place, you certainly should be able to successfully load the required DLL.
Edited by Taco Bell, 04 November 2009 - 16:04.
Posted 05 November 2009 - 12:48
Thanks for the response.
However i dont want to install the runtimes.
I want to accomplish this without having to install the runtimes.
I can get utilities to execute by having specific runtime dll's in their folder. So if utilities could launch, why cant we do it in InstallScript? There should be a way(though i cant get it to work)
However i dont want to install the runtimes.
I want to accomplish this without having to install the runtimes.
I can get utilities to execute by having specific runtime dll's in their folder. So if utilities could launch, why cant we do it in InstallScript? There should be a way(though i cant get it to work)
Posted 05 November 2009 - 16:03
In that case, you should use Microsoft's Dependency Walker to confirm that the DLL can be properly loaded outside of IS.
If that's successful, then I would recommend posting those portions of your IS code, so we can review it and try to work through the problem.
If that's successful, then I would recommend posting those portions of your IS code, so we can review it and try to work through the problem.
Edited by Taco Bell, 05 November 2009 - 16:04.
Posted 05 November 2009 - 17:53
Have you tried creating your own .dll and loading the libraries in that?
Posted 11 November 2009 - 08:30
Firstly in reply to Taco Bell's question,
I am able to open the file in dependency walker.
The code i am trying to use is as follows:
prototype cdecl _lock_file(NUMBER);
UseDll(SUPPORTDIR^msvcr90.dll)
I get the following error trying to do this:
R6034
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.
_lock_file - This is a function in the C runtime library.
I am able to open the file in dependency walker.
The code i am trying to use is as follows:
prototype cdecl _lock_file(NUMBER);
UseDll(SUPPORTDIR^msvcr90.dll)
I get the following error trying to do this:
R6034
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.
_lock_file - This is a function in the C runtime library.
Posted 11 November 2009 - 20:51
I spent some time with this and was able to duplicate the problem, but was unable to resolve the issue. I'll also be out-of-town after tomorrow. Therefore, at this point, my suggestion would be to instead try making/using your own DLL entry point that calls this C++ function.
By the way, in learning more about this C++ function, I came across your original posting from the MSDN forum.
By the way, in learning more about this C++ function, I came across your original posting from the MSDN forum.
Posted 12 November 2009 - 07:17
Thanks Taco Bell. Really appreciate you having provided your inputs.
Using this function from an external dll is an option, but as a last resort.
I will keep everyone posted in case i can crack this.
Thanks again.
Using this function from an external dll is an option, but as a last resort.
I will keep everyone posted in case i can crack this.
Thanks again.
Posted 13 November 2009 - 20:39
This InstallScript code may do what you want:
CODE |
OpenFileMode(FILE_MODE_BINARY); OpenFile(nFile, strPath, strFileName); SeekBytes(nFile, 1, FILE_BIN_START); MessageBox("File is now open and locked for writing.", INFORMATION); CloseFile(nFile); |
This will lock the file for writing, but not reading. So far, I haven't found a way to lock read.
I tried importing kernel32.dll, but CreateFile function is also used by InstallScript and I would have to figure out how to alias the function name. I wrote a simple call in C++ that will lock a file for reading too, but you would have to import the customized dll.
Pat
Posted 13 November 2009 - 21:27
Ha! I got it. This code will lock the file for read as well:
CODE |
prototype NUMBER kernel32.CreateFileA(STRING, NUMBER, NUMBER, NUMBER, NUMBER, NUMBER, NUMBER); prototype NUMBER kernel32.CloseHandle(NUMBER); function OnBegin() NUMBER nFile; STRING strFile; begin strFile = "C:\\empty\\test.txt"; UseDLL("kernel32.dll" ); nFile = CreateFileA(strFile, 1073741824, 0, 0, 3, 128, 0); MessageBox("File is now open.", INFORMATION); CloseHandle(nFile); UnUseDLL("kernel32.dll" ); end; |
Pat
Posted 27 November 2009 - 07:36
Thanks phood.
I am going to try this and let you know about the results.
I am going to try this and let you know about the results.