Tag: programming

C#

A full implementation of the VirusTotal 2.0 API

VirusTotal.NET – A full implementation of the VirusTotal 2.0 API. Here you will find project’s source code. Features Based on RestSharp (http://restsharp.org) to deserialize the VirusTotal JSON into objects Scan, rescan and get report of scanned files Scan websites and files Support for HTTP and HTTPS Support for checking if files have been scanned before …

C#

Get Windows Users with C# and WMI

class SystemUser { public enum AccountType { DUPLICATE_ACCOUNT = 256, NORMAL_ACCOUNT = 512, INTERDOMAIN_TRUST_ACCOUNT = 2048, WORKSTATION_TRUST_ACCOUNT = 4096, SERVER_TRUST_ACCOUNT = 8192 };   public AccountType Type { get; set; } public string Caption { get; set; } public string Description { get; set; } public bool Disabled { get; set; } public string Domain …

C#

Update NoIP Host with c#

More about NoIP dynamic dns update request click here. private void UpdateNoIPHost() { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create( string.Format("http://dynupdate.no-ip.com/nic/update?hostname={0}", "<NoIP Hostname>")); request.Method = "GET"; request.Proxy = null; request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64)"; request.Timeout = 10000; request.Headers.Add(HttpRequestHeader.Authorization, string.Format("Basic {0}", Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "<NoIP username>", "<NoIP password>")))));   using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { } } …

C#

Check if user is Idle with C#

GetLastInputInfo function – Retrieves the time of the last input event. LASTINPUTINFO structure – Contains the time of the last input. public bool IsUserIdle() { uint idleTime = (uint)Environment.TickCount – GetLastInputEventTickCount(); idleTime = ((idleTime > 0) ? (idleTime / 1000) : 0); //user is idle for 5 min return (idleTime >= 5 * 60); } …

General

Get System Uptime with C#

public string GetSystemUptime() { try { string systemUpTime = string.Empty; string query = "SELECT * FROM Win32_OperatingSystem WHERE Primary=’true’";   using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) { foreach (ManagementObject mObject in searcher.Get()) { DateTime LastBootUpTime = ManagementDateTimeConverter.ToDateTime(mObject["LastBootUpTime"].ToString()); TimeSpan systemUpTimeSpan = TimeSpan.FromTicks((DateTime.Now – LastBootUpTime).Ticks);   systemUpTime = string.Format("{0}d : {1}h : {2}m : {3}s", systemUpTimeSpan.Days, systemUpTimeSpan.Hours, …

C#

Is64BitOperatingSystem for C# and .Net 2.0

public bool Is64BitOperatingSystem() { try { string osArch = string.Empty; string query = String.Format("SELECT * FROM Win32_OperatingSystem");   using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) { foreach (ManagementObject mObject in searcher.Get()) { osArch = mObject["OSArchitecture"].ToString(); break; } }   return (osArch != "64-bit") ? false : true; } catch { }   return false; }public bool …

C#

Get MAC Address with C#

public string GetLocalIPAddress() { foreach (NetworkInterface NetI in NetworkInterface.GetAllNetworkInterfaces()) { if (NetI.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || NetI.NetworkInterfaceType == NetworkInterfaceType.Ethernet && NetI.OperationalStatus == OperationalStatus.Up) { foreach (UnicastIPAddressInformation UniIpAddrInfo in NetI.GetIPProperties().UnicastAddresses) { if (UniIpAddrInfo.Address.AddressFamily != AddressFamily.InterNetwork || UniIpAddrInfo.AddressPreferredLifetime == UInt32.MaxValue) continue;   return UniIpAddrInfo.Address.ToString(); } } }   return "Unknown"; }   public string GetMacAddress() { foreach (NetworkInterface …

C#

Get local IP address with C#

public string GetLocalIPAddress() { foreach (NetworkInterface NetI in NetworkInterface.GetAllNetworkInterfaces()) { if (NetI.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || NetI.NetworkInterfaceType == NetworkInterfaceType.Ethernet && NetI.OperationalStatus == OperationalStatus.Up) { foreach (UnicastIPAddressInformation UniIpAddrInfo in NetI.GetIPProperties().UnicastAddresses) { if (UniIpAddrInfo.Address.AddressFamily != AddressFamily.InterNetwork || UniIpAddrInfo.AddressPreferredLifetime == UInt32.MaxValue) continue;   return UniIpAddrInfo.Address.ToString(); } } }   return "Unknown"; }public string GetLocalIPAddress() { foreach (NetworkInterface NetI in …

C#

How to get bios identifier with C#

public string GetBiosId() { try { string bios = ""; using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS")) { foreach (ManagementObject mObject in searcher.Get()) { bios = mObject["Manufacturer"].ToString(); break; } } return (!string.IsNullOrEmpty(bios)) ? bios : "Unknown"; } catch { } return "Unknown"; }public string GetBiosId() { try { string bios = ""; using …

C#

Explorer theme for ListView control

[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)] public extern static int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);   //overwrite control’s OnHandleCreated method protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6) { SetWindowTheme(this.Handle, "explorer", null); } }[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)] public extern static int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList); //overwrite control’s …