Tag: programming

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 …

C

Suppress all error messages in C

SetErrorMode function controls whether the system will handle the specified types of serious errors or whether the process will handle them. #include <Windows.h>   SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);#include <Windows.h> SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);

C

Create a process in C

#include <stdlib.h> #include <stdio.h> #include <windows.h>     int main() { STARTUPINFO startInfo; PROCESS_INFORMATION procInfo;   //lock user WCHAR cmd[50] = L"rundll32.exe user32.dll, LockWorkStation\0";   SecureZeroMemory(&startInfo, sizeof(startInfo)); startInfo.cb = sizeof(startInfo); SecureZeroMemory(&procInfo, sizeof(procInfo));   if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &startInfo, &procInfo) != 0) return GetLastError();   CloseHandle(procInfo.hProcess); CloseHandle(procInfo.hThread);   return EXIT_SUCCESS; }#include …

CakePHP, PHP

List table columns in cakephp 3

List table columns $db = \Cake\Datasource\ConnectionManager::get(’default’); $collection = $db->schemaCollection(); $table= $collection->describe(’tablename’); $columns = $table->columns();$db = \Cake\Datasource\ConnectionManager::get(‘default’); $collection = $db->schemaCollection(); $table= $collection->describe(‘tablename’); $columns = $table->columns();