Tag: list

C#

List all subfolders in C#

Use the following code to list all subdirectories of a folder. try { String[] allfolders = System.IO.Directory.GetDirectories("C:\", "*", System.IO.SearchOption.TopDirectoryOnly); if (allfolders.Length == 0) Console.WriteLine("empty"); else foreach (String folder in allfolders) Console.WriteLine(folder.Substring(folder.LastIndexOf("\") + 1) ); } catch (Exception) { //… }try { String[] allfolders = System.IO.Directory.GetDirectories("C:\", "*", System.IO.SearchOption.TopDirectoryOnly); if (allfolders.Length == 0) Console.WriteLine("empty"); else foreach (String …

C#

Get system hard drives with C#

Retrieve the available disk drives with GetLogicalDrives function. try { foreach (String lodi in Environment.GetLogicalDrives()) if (lodi != String.Empty) Console.WriteLine(lodi); } catch (Exception) { //… }try { foreach (String lodi in Environment.GetLogicalDrives()) if (lodi != String.Empty) Console.WriteLine(lodi); } catch (Exception) { //… }

C#

Get system services with C#

To list system services, we are going to use ServiceController class. Add a reference to System.ServiceProcess namespace first. try { foreach (System.ServiceProcess.ServiceController s in System.ServiceProcess.ServiceController.GetServices()) Console.WriteLine(s.Status + " — " + s.ServiceName); } catch (Exception) { //… }try { foreach (System.ServiceProcess.ServiceController s in System.ServiceProcess.ServiceController.GetServices()) Console.WriteLine(s.Status + " — " + s.ServiceName); } catch (Exception) { …

C#

Get all system processes with C#

List all System running processes with the following code: public void GetAllProcesses() { foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcesses()) { try { Console.WriteLine( proc.Id + " " + proc.ProcessName + " " + proc.PriorityClass.ToString() + " " + proc.MainModule.FileName); } catch (Exception) { //… } } }public void GetAllProcesses() { foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcesses()) { …

C#

Get a list of opened windows C#

With the following method you can list all opened windows using C#. public void ListOpenedWindows() { IntPtr hwnd; foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcesses()) { if ((hwnd = proc.MainWindowHandle) != IntPtr.Zero) Console.WriteLine(hwnd.ToString() + " " + proc.MainWindowTitle); } }public void ListOpenedWindows() { IntPtr hwnd; foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcesses()) { if ((hwnd = proc.MainWindowHandle) != IntPtr.Zero) …

Microsoft Windows

List all TCP and UDP endpoints on your system

TCPView is a Windows program that will show you detailed listings of all TCP and UDP endpoints on your system, including the local and remote addresses and state of TCP connections. On Windows Server 2008, Vista, and XP, TCPView also reports the name of the process that owns the endpoint. TCPView provides a more informative …

Linux, Ubuntu

Ubuntu – List remote host shared folders

Usage: smbclient -U <username> -L <hostname>smbclient -U <username> -L <hostname> smbclient -U <username> -L <ip address>smbclient -U <username> -L <ip address> Example: smbclient -U test -L 192.168.10.5smbclient -U test -L 192.168.10.5 Results: Enter test’s password: Domain=[TESTING] OS=[Windows 7] Server=[Windows 7] Sharename Type Comment ——— —- ——- ADMIN$ Disk Remote Admin C$ Disk Default share E …