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

Functions

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

FileOpen and Share Violations

Keywords:  intcontrol(39 intcontrol(40 intcontrol (39 intcontrol (40  

Question:

I'm trying to use the IntControl 39 and 40 to share files. I try to share file in the same or different application, but am still receiving an error message on FileOpen command.

When I execute the IntControl, it returns the last sharing state, but didn't seem to do anything else. Any ideas?

Answer:

Some applications will not let you look at the files thay have open. Nothing can be done about it. Some applications will let you look at their open files *IF* you access the file with the proper sharing mode. This is what IntControl 39 and Intcontrol 40 are for.

If is very rare that applications that have a file open for writing allow anyone else to look at it.

Here's an example of how to test whether a file is open, without causing a sharing violation


;----------------------------------------

file = "h:\test.xls"

;----------------------------------------

If FileItemize(file) == ""
  Message(file, "File does not exist")
  Exit
Endif

dll = DllLoad("krnl386.exe")
DllCall(dll, word:"SetErrorMode", word:1)  ; SEM_FAILCRITICALERRORS
ofstruct = BinaryAlloc(150)
hFile = DllCall(dll, word:"OpenFile", lpstr:file, lpbinary:ofstruct, word:16384)  ; OF_EXIST
errcode = BinaryPeek(ofstruct, 2)
ofstruct = BinaryFree(ofstruct)
DllFree(dll)

If hFile == 65535
  If errcode == 32  ; Sharing violation
    Message(file, "File is in use by another application")
  Else	; other error
    Message(file, "File could not be opened")
  Endif
  Exit
Endif

Message(file, "File is accessible")


Article ID:   W13086
Filename:   Intcontrol 39-40 and Share Violations.txt
File Created: 1999:04:15:16:51:40
Last Updated: 1999:04:15:16:51:40