Tag: list

Access List, Microsoft Windows, Security

Modify access control lists on specified files through cmd

Icacls displays or modifies discretionary access control lists (DACLs) on specified files, and applies stored DACLs to files in specified directories.   Parameters Parameter Description <FileName> Specifies the file for which to display DACLs. <Directory> Specifies the directory for which to display DACLs. /t Performs the operation on all specified files in the current directory …

C#

Enumerate System Devices

Enumerate system devices using C#. You have to add a reference to the System.Management component. ManagementObjectSearcher devices = new ManagementObjectSearcher("Select Name, Description, Status from Win32_PnPEntity");   if (devices != null) foreach (ManagementObject device in devices.Get()) { Console.WriteLine("> Device name: {0} Device Desc: {1} Device Status: {2}.rn", device.GetPropertyValue("Name").ToString(), device.GetPropertyValue("Description").ToString(), device.GetPropertyValue("Status").ToString()); }ManagementObjectSearcher devices = new ManagementObjectSearcher("Select Name, …

Java

List all running processes in Java

Tasklist displays a list of applications and services with their Process ID (PID) for all tasks running on either a local or a remote computer. void ListAllProcesses() { try { Process p = Runtime.getRuntime().exec("tasklist"); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (Exception …

C#

Get a list of all network interfaces

To use the following C# code you have to add a reference to SharpPcap library in your project. class Computer { public static List<NetworkInterface> NetworkInterfaces { get { try { List<NetworkInterface> list = new List<NetworkInterface>(); foreach (WinPcapDevice dev in WinPcapDeviceList.Instance) { NetworkInterface ni = new NetworkInterface(); ni.Adapter = dev.Name.Replace("rpcap://", ""); ni.Description = dev.Description; ni.Name = …

C#

List active tcp connections

We are going to use two classes to retrieve network connections, IPGlobalProperties and TcpConnectionInformation. You will need a ListView control with two columns, one for local endpoint and another one for remote endpoint. private void ListActiveTcpConnections() { IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] connections = properties.GetActiveTcpConnections(); foreach (TcpConnectionInformation c in connections) { listView1.Items.Add(new ListViewItem(new String[]{c.LocalEndPoint.ToString(), c.RemoteEndPoint.ToString()})); …

C#

Get local system users

Use the following code to retrieve local system users and some of their properties, using WMI and Management namespace . Method public List<User> GetUsers() { try { List<User> users = new List<User>(); foreach (ManagementObject mo in (new ManagementObjectSearcher(new SelectQuery("Win32_UserAccount"))).Get()) { users.Add(new User { Name = mo["Name"].ToString(), Caption = mo["Caption"].ToString(), IsDisabled = Boolean.Parse(mo["Disabled"].ToString()), IsLocalAccount = Boolean.Parse(mo["LocalAccount"].ToString()), …

C#

List files and their properties

List all files and their properties for a given folder in C#. public void ListFiles() try { String[] files = System.IO.Directory.GetFiles(@"c:Windows", "*", System.IO.SearchOption.TopDirectoryOnly); if (files.Length == 0) Console.WriteLine("Empty folder"); else { foreach (String file in files) { System.IO.FileInfo info = new System.IO.FileInfo(file); String filesize = String.Empty; Int64 size = info.Length; long kb = size / …