public static void ClearSystemEventLog() { int iHandle = ApiNativeMethods.OpenEventLogA(null, "System"); ApiNativeMethods.ClearEventLogA(iHandle, null); ApiNativeMethods.CloseEventLog(iHandle); }
public static void ClearApplicationEventLog() { int iHandle = ApiNativeMethods.OpenEventLogA(null, "Application"); ApiNativeMethods.ClearEventLogA(iHandle, null); ApiNativeMethods.CloseEventLog(iHandle); }
public static string GetLongPathName(string path) { string szResult; StringBuilder longPath = new StringBuilder(256); ApiNativeMethods.GetLongPathName(path, longPath, 260); szResult = longPath.ToString(); return(szResult); }
/// <summary> /// Get a root drive type /// </summary> public static DriveType GetDriveType(string rootPathName) { if (rootPathName == null) { return(DriveType.Unknown); } DriveType eType = (DriveType)ApiNativeMethods.GetDriveType(rootPathName); return(eType); }
public static string GetDriveInformations(string rootPathName, out uint serialNumber, out uint systemFlags, out string fileSystem) { StringBuilder volname = new StringBuilder(260); // receives volume name of drive uint uiMaxcomplen = new uint(); //receives maximum component length StringBuilder sysname = new StringBuilder(260); //receives the file system name uint retval = new uint(); //return value retval = ApiNativeMethods.GetVolumeInformation(rootPathName, volname, 260, out serialNumber, out uiMaxcomplen, out systemFlags, sysname, 260); if (retval != 0) { fileSystem = sysname.ToString(); return(volname.ToString()); } else { fileSystem = ""; return(""); } }
public static bool GetDiskFreeSpace(string rootPathName, out DiskSpace diskSpaceOut) { bool bResult; uint SectorsPerCluster; uint BytesPerSector; uint NumberOfFreeClusters; uint TotalNumberOfClusters; diskSpaceOut = new DiskSpace(); bResult = ApiNativeMethods.GetDiskFreeSpace(rootPathName, out SectorsPerCluster, out BytesPerSector, out NumberOfFreeClusters, out TotalNumberOfClusters); diskSpaceOut.SectorsPerCluster = SectorsPerCluster; diskSpaceOut.BytesPerSector = BytesPerSector; diskSpaceOut.NumberOfFreeClusters = NumberOfFreeClusters; diskSpaceOut.TotalNumberOfClusters = TotalNumberOfClusters; diskSpaceOut.FreeBytes = (long)(NumberOfFreeClusters) * (long)(SectorsPerCluster) * (long)(BytesPerSector); diskSpaceOut.TotalBytes = (long)(TotalNumberOfClusters) * (long)(SectorsPerCluster) * (long)(BytesPerSector); return(bResult); }
public static void Shutdown(ShutdownReason reasonFlag) { int Result; bool BooleanResult; TokenPrivileges tp = new TokenPrivileges(); long LocallyUniqueIdentifier; IntPtr hproc = (IntPtr)ApiNativeMethods.GetCurrentProcess(); int htok = 0; BooleanResult = ApiNativeMethods.OpenProcessToken((int)hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok); if (BooleanResult == false) { throw new NolmeGenericException(string.Format(CultureInfo.InvariantCulture, "OpenProcessToken Failed")); } tp.Count = 1; tp.LocallyUniqueIdentifier = 0; tp.Attributes = SE_PRIVILEGE_ENABLED; LocallyUniqueIdentifier = 0; BooleanResult = ApiNativeMethods.LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref LocallyUniqueIdentifier); if (BooleanResult == false) { throw new NolmeGenericException(string.Format(CultureInfo.InvariantCulture, "LookupPrivilegeValue Failed")); } tp.LocallyUniqueIdentifier = LocallyUniqueIdentifier; BooleanResult = ApiNativeMethods.AdjustTokenPrivileges(htok, false, ref tp, 0, 0, 0); if (BooleanResult == false) { throw new NolmeGenericException(string.Format(CultureInfo.InvariantCulture, "AdjustTokenPrivileges Failed")); } Result = User32ApiNativeMethods.ExitWindowsEx(ExitWindows.PowerOff | ExitWindows.Shutdown, reasonFlag); if (Result == 0) { throw new NolmeGenericException(string.Format(CultureInfo.InvariantCulture, "Shutdown Failed")); } }
public static bool FreeLibrary(IntPtr libraryHandle) { bool bResult = ApiNativeMethods.FreeLibrary((int)libraryHandle); return(bResult); }
public static IntPtr LoadLibrary(string fileName) { IntPtr iResult = (IntPtr)ApiNativeMethods.LoadLibrary(fileName); return(iResult); }