using System;
// Add a reference to System.Management
// Note: the #pragma comment( lib ) is highly missed in C# 😀
using System.Management;

namespace WmiListShares
{
class Program
{
static void Main( string[] args )
{
var machineName = "svr-test";
var path = string.Format( @"\\{0}\root\cimv2", machineName );
var query = "select * from win32_share";
   var worker = new ManagementObjectSearcher( path, query );
var shares = worker.Get();
foreach( ManagementObject share in shares )
   {
      Console.WriteLine( "{0}", share[ "Name" ] );
}
}
}
}
Advertisements