Author Topic: Test to see if "file in use"  (Read 3796 times)

stevengraff

  • Sr. Member
  • ****
  • Posts: 271
Test to see if "file in use"
« on: March 21, 2014, 05:22:31 am »
My script's installation script bombs out when using ExtractAttachedFile if there's an existing file currently in use. Is there a test I can run prior to ExtractAttachedFile that would allow me to tell the user that file "xyzzy.dll is in use, stop existiing related processes, and try again?"

I thought maybe if fileExist("xyzzy.dll") == 2, but that seems to be only for files that can't be read. Apparently fileExist(filename) == 3 is not an option in my version.

Thanks,
Steven

td

  • Tech Support
  • *****
  • Posts: 4094
    • WinBatch
Re: Test to see if "file in use"
« Reply #1 on: March 21, 2014, 06:47:12 am »
After checking for existence, attempt to open the file for unshared writing.  Trap any resulting error.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 4094
    • WinBatch
Re: Test to see if "file in use"
« Reply #2 on: March 21, 2014, 09:06:06 am »
As an alternative to throwing up an error when you can't extract a file, you could try to rename the existing unaccessible file instead.  Often, files locked because a process holds a module handle can still be renamed.  Once the file is renamed successfully, you could use IntControl 30 to mark the renamed file for deletion on the next reboot and extract your new file.

If the file cannot be renamed or marked for deletion, you could still fall back to an error.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stevengraff

  • Sr. Member
  • ****
  • Posts: 271
Re: Test to see if "file in use"
« Reply #3 on: March 21, 2014, 02:16:15 pm »
intcontrol 30 looks like a queer duck. Obviously the script is not auto-restarting upon fresh boot, so... does Windows maintain such a list of files to move internally? WinBatch just tells Windows, "here ya go, move these files next time 'round?"

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Test to see if "file in use"
« Reply #4 on: March 21, 2014, 03:26:54 pm »
intcontrol 30 looks like a queer duck. Obviously the script is not auto-restarting upon fresh boot, so... does Windows maintain such a list of files to move internally? WinBatch just tells Windows, "here ya go, move these files next time 'round?"

As I understand it, IntControl30 merely sets some registry keys that the system uses to complete the operations at restart in the same order that they were issued.
Deana F.
Technical Support
Wilson WindowWare Inc.

td

  • Tech Support
  • *****
  • Posts: 4094
    • WinBatch
Re: Test to see if "file in use"
« Reply #5 on: March 24, 2014, 06:51:06 am »
intcontrol 30 looks like a queer duck. Obviously the script is not auto-restarting upon fresh boot, so... does Windows maintain such a list of files to move internally? WinBatch just tells Windows, "here ya go, move these files next time 'round?"

Nothing 'queer' or 'ducky' about it.  IntControl 30 simply gives you access to a service provided by the OS.  The one caveat is that the IntControl  does require that the caller be a member of the administrative group or be the LocalSystem account.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 4094
    • WinBatch
Re: Test to see if "file in use"
« Reply #6 on: March 25, 2014, 08:15:55 am »
Neglected to add that while MSFT documentation  for the underlying API doesn't state so, the IntControl 30 caller needs to be an elevated admin on Vista/2008 and newer with UAC enabled.  This can be inferred from the registry location used to record the names of files to be moved or deleted. I imagine this inconvenience could be described as just 'ducky'...
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade