[DllImport("kernel32.dll", EntryPoint = "_lopen")] static extern IntPtr Lopen(string lpPathName, int iReadWrite);
[DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr hObject);
public static bool IsOpened(string filename) { const int OF_READWRITE = 2; const int OF_SHARE_DENY_NONE = 0x40; IntPtr HFILE_ERROR = new IntPtr(-1);
IntPtr handle = Lopen(filename, OF_READWRITE | OF_SHARE_DENY_NONE); if (handle == HFILE_ERROR) { return true; } CloseHandle(handle); return false; } |