Get Logged In User while Impersonate or Run as Admin

Sometimes when a program is run as Administrator, using the System.Security.Principal.WindowsIdentity.GetCurrent().Name will return always System or NT Authority\System. This happens while running the exe under windows service or by Installer class in the windows application. The below code will solve this issue. Code Snippet public static string GetParentUser(int pid)         {             string parentUserAccount = null;             string... Continue Reading →

C# Enum To String Using Attributes

There are certain situation we need to have custom string value to a Enum and later need to retrieve the string value. The string value should be independent of the enum constant. The below example will use the system.attribute class to achieve this. Step 1: Declare a Enum public enum GameConsole{    PSP=0,    PS2=1,    XBOX=2,    Nitendo=3}... Continue Reading →

Create a website or blog at WordPress.com

Up ↑