public static NT_FILE_STANDARD_INFORMATION GetFileInfo_standard(IntPtr file_handle) { IntPtr ret_ptr = IntPtr.Zero; try { IO_STATUS_BLOCK status_block = new IO_STATUS_BLOCK(); int ret_len = Marshal.SizeOf(typeof(NT_FILE_STANDARD_INFORMATION)); ret_ptr = Marshal.AllocHGlobal(ret_len); uint res = ntApiFS.NtQueryInformationFile (file_handle, ref status_block, ret_ptr, ret_len, FILE_INFORMATION_CLASS.FileStandardInformation); NTSTATUS_helper.ThrowOnError(res, status_block, NTSTATUS_severity.Warning); NT_FILE_STANDARD_INFORMATION ret = (NT_FILE_STANDARD_INFORMATION)Marshal.PtrToStructure (ret_ptr, typeof(NT_FILE_STANDARD_INFORMATION)); return(ret); } finally { if (ret_ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ret_ptr); } } }
public static NT_FILE_STANDARD_INFORMATION GetFileInfo_standard(string file_name) { IntPtr file_handle = IntPtr.Zero; try { file_handle = WinApiFS.CreateFile_intptr (file_name, Win32FileAccess.GENERIC_READ, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, CreateFileOptions.None, IntPtr.Zero); if (file_handle.ToInt32() == WinApiFS.INVALID_HANDLE_VALUE) { int win_err = Marshal.GetLastWin32Error(); Exception ex = new Win32Exception(win_err); throw ex; } NT_FILE_STANDARD_INFORMATION ret = GetFileInfo_standard(file_handle); return(ret); } finally { if ((file_handle != IntPtr.Zero) && (file_handle.ToInt32() != WinApiFS.INVALID_HANDLE_VALUE)) { WinApiFS.CloseHandle(file_handle); } } }