Devo sapere se Pippo.wav è in esecuzione e lo sta usando un altro programma!
Come posso Fare?
Grazie!
Devo sapere se Pippo.wav è in esecuzione e lo sta usando un altro programma!
Come posso Fare?
Grazie!
Si può?
O non mi sapete rispondere.
Grazie
1) non è una chat, se nessuno risponde vuol dire che nessuno sa o nessuno che sa ha letto
2) devi usare la createfile delle windows api che ti restituisce un intptr nullo se il file è loccato
ecco un esempio in c# però:
codice:public const uint GENERIC_READ = 0x80000000; public const uint GENERIC_WRITE = 0x40000000; public const uint FILE_SHARE_READ = 0x1; public const uint FILE_SHARE_WRITE = 0x2; public const uint FILE_ATTRIBUTE_NORMAL = 0x80; public const uint OPEN_EXISTING = 0x3; public const uint CREATE_ALWAYS = 0x2; [DllImport("kernel32.dll", SetLastError = true)] internal static extern IntPtr CreateFile(String lpFileName, UInt32 dwDesiredAccess, UInt32 dwShareMode, IntPtr lpSecurityAttributes, UInt32 dwCreationDisposition, UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile); public static bool FileIsLocked(string FileName) { bool res = false; IntPtr hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero); if (hFile.ToInt32() > 0) { res = false; } else { res = true; } CloseHandle(hFile); return res; }
Grazie Stoicenko,scusa ma ho solecitato per motivi di urgenza scusate!
Vediamo se riesco a portarlo in vb grazie
attenzione che nel forum l'urgenza non esiste..ma ho solecitato per motivi di urgenza scusate!
allora ho provato a convertirlo e mi funziona soltanto che il file e inleggibile dopo che faccio il test se e read o no!
codice:Public Const GENERIC_READ As Integer = &H80000000 Public Const GENERIC_WRITE As UInteger = &H40000000 Public Const FILE_SHARE_READ As UInteger = &H1 Public Const FILE_SHARE_WRITE As UInteger = &H2 Public Const FILE_ATTRIBUTE_NORMAL As UInteger = &H80 Public Const OPEN_EXISTING As UInteger = &H2 <DllImport("kernel32.dll", SetLastError:=True)> _ Friend Shared Function CreateFile(ByVal lpFileName As [String], ByVal dwDesiredAccess As Int32, ByVal dwShareMode As UInt32, ByVal lpSecurityAttributes As IntPtr, ByVal dwCreationDisposition As UInt32, ByVal dwFlagsAndAttributes As UInt32, _ ByVal hTemplateFile As IntPtr) As IntPtr End Function <DllImport("kernel32.dll", SetLastError:=True)> _ Public Shared Function CloseHandle(ByVal hObject As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean End Function Public Shared Function FileIsLocked(ByVal FileName As String) As Boolean Dim res As Boolean = False Dim hFile As IntPtr = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero) If hFile.ToInt32() > 0 Then res = False Else res = True End If CloseHandle(hFile) Return (res) End Function
sicuro sia colpa di quella funzione? perchè non fa nulla al file... controlla meglio
Si il file è un file mp3 o wav e quando lo riavvio con windows media player mi dice che il file è daneggiatto!!
Non riesco a capire perchè!
Allora è colpa della conversione da c a vb.
Cavolaccio come faccio?
Grazie comunque Stoicenko!