Markiert: System Tools

0

Convert .NET DateTime into Unix Time

The Unix calendar starts at 01/01/1970. This post will show you how to convert any DateTime value into a Unix time stamp. private const string InvalidUnixEpochErrorMessage = „Unix time starts January 1st, 1970“; ///...

0

Obtain IP and MAC Address in C#

There is no built-in way to discover the MAC address of your network adapter in .NET. Using the following function the MAC address that belongs to any IP address can be obtained. The functions...

0

Extending the Random Class

The following code contains extension methods for the random class. One method will create random dates between a given minimum and maximum. The second method creates boolean random values. public static class RandomNumbers {...

0

Strip BOM from a File or Text

The following code removes the BOM (Byte Order Mark) from texts. Some text editors add that while saving files. Sometimes this leads to problems while reading or converting text files (e.g. XML files). The...

0

Obtain information about the Executing Assembly

Path of the executing assembly: public static string GetExecutingAssemblyPath() { string codeBase = Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); return Path.GetDirectoryName(path); } Get title of executing assembly: /// <summary> ///...

0

Calendar tools and algorithms

Calculating a leap year The correct calculation of a leap year was first introduced by pope Gregor in 1582. The Gregorian Calendar is still commonly used in most parts of the world. Before that,...

0

Change String into a Valid File Name

Not all possible characters are suitable for file names. For example path separators cannot be used for file names. This changes any string into a valid file name by replacing the invalid characters with...

0

Check if Current User has Admin Rights and Restart Application with Elevated Rights

The following code snippet checks if the current user as administrator rights: /// <summary> /// Checks if user has administrator rights /// </summary> public static bool UserIsAdmin() {   WindowsIdentity identity = WindowsIdentity.GetCurrent();   WindowsPrincipal principal = new WindowsPrincipal(identity);   return principal.IsInRole(WindowsBuiltInRole.Administrator); } If the application requires administrator rights for an operation, the following function can...