speedy6 Posted October 17, 2007 Share Posted October 17, 2007 Can i check if a file is being used? Link to comment Share on other sites More sharing options...
martin Posted October 17, 2007 Share Posted October 17, 2007 Can i check if a file is being used?There might be simpler ways to do it so see what other replies you get, but here is a link to a way to do it with WMIpage 548 on. Looks like this could be done in AutoIt quite easily. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 18, 2007 Share Posted October 18, 2007 This version of it works, but only if it's open via a CIFS share, because it accesses the object via LanManServer, not the local FileSystemObject: $varFile= "C:\Temp\Test.txt" $objFS = ObjGet("WinNT://" & @ComputerName & "/lanmanserver", "fileservice") $varFoundNone = True $sMsg = "" For $objRes in $objFS.Resources If $objRes.Path = $varFile Then $varFoundNone = False $sMsg &= $objRes.User & ", " EndIf Next If $varFoundNone Then MsgBox(64, "No Result", "Didn't find that file opened by anyone.") Else MsgBox(64, "Result", "Found file in use by: " & StringTrimRight($sMsg, 2)) EndIf Third party apps can tell if a file is in use, but I don't see how to get that in the scripting environment without doing something that will CHANGE the file, like attempting to open it for append then closing it immediately. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
speedy6 Posted October 18, 2007 Author Share Posted October 18, 2007 So there's no other way... Beacause i wanne check if an other application is using a xml file, if so, stay away from it... Is that possible with you're code? Link to comment Share on other sites More sharing options...
Glyph Posted October 18, 2007 Share Posted October 18, 2007 without doing something that will CHANGE the file, like attempting to open it for append then closing it immediately.try that..? tolle indicium Link to comment Share on other sites More sharing options...
speedy6 Posted October 18, 2007 Author Share Posted October 18, 2007 try that..?Whill do thx Link to comment Share on other sites More sharing options...
dabus Posted October 18, 2007 Share Posted October 18, 2007 Try this: I think it's from larry, do a search and figure out the things you need to know... $a = _RealFileOpen("D:\Daten\Text\UltimateFAQ.cc3") MsgBox(4096,"",$a) _RealFileClose($a) Func _RealFileOpen( $szFile ) Local $GENERIC_READ = 0x80000000 Local $OPEN_EXISTING = 3 Local $FILE_ATTRIBUTE_NORMAL = 0x00000080 Local $RFO_h $RFO_h = DllCall( "kernel32.dll", "hwnd", "CreateFile", _ "str", $szFile, _ "long", $GENERIC_READ, _ "long", 0, _ "ptr", 0, _ "long", $OPEN_EXISTING, _ "long", $FILE_ATTRIBUTE_NORMAL, _ "long", 0 ) Return $RFO_h[0] EndFunc Func _RealFileClose( $hFile ) Local $RFC_r $RFC_r = DllCall( "kernel32.dll", "int", "CloseHandle", _ "hwnd", $hFile ) Return $RFC_r[0] EndFunc Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 18, 2007 Share Posted October 18, 2007 (edited) Try this: I think it's from larry, do a search and figure out the things you need to know... $a = _RealFileOpen("D:\Daten\Text\UltimateFAQ.cc3") MsgBox(4096,"",$a) _RealFileClose($a) Func _RealFileOpen( $szFile ) Local $GENERIC_READ = 0x80000000 Local $OPEN_EXISTING = 3 Local $FILE_ATTRIBUTE_NORMAL = 0x00000080 Local $RFO_h $RFO_h = DllCall( "kernel32.dll", "hwnd", "CreateFile", _ "str", $szFile, _ "long", $GENERIC_READ, _ "long", 0, _ "ptr", 0, _ "long", $OPEN_EXISTING, _ "long", $FILE_ATTRIBUTE_NORMAL, _ "long", 0 ) Return $RFO_h[0] EndFunc Func _RealFileClose( $hFile ) Local $RFC_r $RFC_r = DllCall( "kernel32.dll", "int", "CloseHandle", _ "hwnd", $hFile ) Return $RFC_r[0] EndFunc This will tell you if it doesn't exist, is ReadOnly, or is already opened exclusively by another app. Notepad.exe opening a file isn't detected because it only works with an memory image of the file and doesn't hold it in an open state. Edit: Corrected note about Notepad.exe. Edited October 18, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Siao Posted October 18, 2007 Share Posted October 18, 2007 (edited) Note this will not tell you if the file is opened non-exclusively for Read (i.e. Notepad is viewing it). But will tell you if it doesn't exist, is ReadOnly, or is already opened exclusively by another app.Not exactly. That CreateFile should return error if a file already has a handle opened in any access mode and any share rights, because you specify that you don't want to share it, which makes unimportant which share rights the other app has opened it with.Notepad in this case is a bad test subject, because it does not keep the file open. It opens the file, reads it into memory and then closes the file. So technically the file is not open = unused. Edited October 18, 2007 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 18, 2007 Share Posted October 18, 2007 Not exactly. That CreateFile should return error if a file already has a handle opened in any access mode and any share rights, because you specify that you don't want to share it, which makes unimportant which share rights the other app has opened it with.Notepad in this case is a bad test subject, because it does not keep the file open. It opens the file, reads it into memory and then closes the file. So technically the file is not open = unused.Fair enough... it still works! Thanks for the correction, I edited the post. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Champak Posted March 22, 2008 Share Posted March 22, 2008 I am having a problem with this. I'm trying to detect if an audio file is being used by another app and this isn't working....at least with the particular apps I have that are using the audio file. Not all audio apps show that they are using an audio file it seems, maybe they are operating like notepad...although I can't see why an audio app would do that. I even tried to see if they are creating temp copies and using those, but that isn't the case. Are there any other solutions or workarounds? Is there a way to see if a file is in memory? But along with that question comes, if it is read to memory to play back, is it deleted from memory after playback?...which is what I would need for that scenario. So anything? Thanks. Link to comment Share on other sites More sharing options...
Squirrely1 Posted March 22, 2008 Share Posted March 22, 2008 (edited) @speedy6 - tell us more about the situation: are you writing a script for general use or only for you? If it is more certainly another audio player the name of which is known, you could check for the the existence of its process, and nest some code that would check its "playlist now-playing" file using some COM objects: If ProcessExists("wmplayer.exe") Then If COM_Code() Then ;... EndIf EndIf Edited March 22, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
Champak Posted March 27, 2008 Share Posted March 27, 2008 bump Link to comment Share on other sites More sharing options...
ptrex Posted March 28, 2008 Share Posted March 28, 2008 @all Go to Google type : Unlocker Perfect tool for this. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now