This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (!string.IsNullOrEmpty(multiLineString)) | |
| { | |
| using (var reader = new StringReader(multiLineString)) | |
| { | |
| string line; | |
| while ((line = reader.ReadLine()) != null) | |
| { | |
| Console.WriteLine(line); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal static string UppercaseWords(string value) | |
| { | |
| if (string.IsNullOrEmpty(value)) return value; | |
| value = value.ToLower(); | |
| var array = value.ToCharArray(); | |
| if (array.Length >= 1) | |
| { | |
| if (char.IsLower(array[0])) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal class HdLogo | |
| { | |
| private static string _hdLogo = ""; | |
| internal static string GetLogo() | |
| { | |
| if (string.IsNullOrEmpty(_hdLogo)) Initialise(); | |
| return _hdLogo; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (object.InvokeRequired) return (bool)object.Invoke(new Func<bool>(() => FunctionName(optionalParameter))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [DllImport("advapi32.dll", SetLastError = true)] | |
| private static extern bool OpenProcessToken(IntPtr ProcessHandle, uint DesiredAccess, out IntPtr TokenHandle); | |
| [DllImport("kernel32.dll", SetLastError = true)] | |
| [return: MarshalAs(UnmanagedType.Bool)] | |
| private static extern bool CloseHandle(IntPtr hObject); | |
| internal static string GetProcessUser(Process process, bool includeDomain = false) | |
| { | |
| var processHandle = IntPtr.Zero; | |
| try |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Diagnostics; | |
| var counters = new List<PerformanceCounter>(); | |
| using (var proc = Process.GetCurrentProcess()) | |
| { | |
| var processorTimeCounter = new PerformanceCounter("Process", "% Processor Time", proc.ProcessName); | |
| processorTimeCounter.NextValue(); | |
| counters.Add(processorTimeCounter); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const string userRoot = "HKEY_CURRENT_USER"; | |
| const string subkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce"; | |
| const string keyName = userRoot + "\\" + subkey; | |
| var location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase); | |
| var fileInfo = new FileInfo(location.AbsolutePath); | |
| var fileLoc = fileInfo.FullName; | |
| var fileDesc = Path.GetFileNameWithoutExtension(fileInfo.Name); | |
| Registry.SetValue(keyName, fileDesc, fileLoc, RegistryValueKind.String); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using (var s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp)) | |
| { | |
| s.Bind(new IPEndPoint(IPAddress.Any, 0)); | |
| s.Connect("google.com", 0); | |
| var ipaddr = s.LocalEndPoint as IPEndPoint; | |
| var addr = ipaddr?.Address?.ToString() ?? ""; | |
| Console.WriteLine(addr); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal static bool CheckForInternetConnection() | |
| { | |
| try | |
| { | |
| using (var client = new WebClient()) | |
| using (client.OpenRead("http://google.com/generate_204")) | |
| { | |
| return true; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.DirectoryServices.AccountManagement; | |
| using (var pc = new PrincipalContext(ContextType.Machine)) | |
| { | |
| var up = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, "gebruiker2"); | |
| var userExists = (up != null); | |
| if (userExists) Console.WriteLine("user exists"); | |
| else Console.WriteLine("user not found"); | |
| } |