How to get the path of share folder "ADMIN$" on a remote machine?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

i'm writing a application that need to get the path of share folder "ADMIN$"
on a remote machine. for instance, if "ADMIN$" is maped to "C:\Windows", i
want to get the string "C:\Windows".

Thanks in advance.
-Zhilin
 
Hi,

I think the "\\MachineName\ADMIN$" should work.

string folderName = @"\\MachineName\ADMIN$";
string[] subFolderNames = Directory.GetDirectories(folderName);

Make sure the running user account has sufficient rights to access that
folder.

Hope it helps,
Thi
http://thith.blogspot.com
 
Because I already tried to answer, I will try again.
I tested and the following code should work:

using System.Management;

private static string GetAdminPath(string computerName)
{
if (computerName == null || computerName.Length == 0) computerName =
Environment.MachineName;
ManagementClass c = new
ManagementClass(String.Format(@"\\{0}\root\cimv2:Win32_Share",
computerName));

foreach (ManagementObject o in c.GetInstances())
{
if ((string) o["Name"] == "ADMIN$") return (string) o["Path"];
}

return null;
}

Note that it is likely that the running user must have admin right on
that machine, just as when you check this with Control Panel's Computer
Management.

Thi
http://thith.blogspot.com
 
You will need to PInvoke NetShareGetInfo() in NetApi32.dll (I don't think
there is a equivalent .net framework class).
..
 
Back
Top