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

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
 
T

Truong Hong Thi

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
 
T

Truong Hong Thi

Opps, mistaken. You want to get the actual path, like "C:\Windows".
Discard it.
 
T

Truong Hong Thi

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
 
N

Noah Sham

You will need to PInvoke NetShareGetInfo() in NetApi32.dll (I don't think
there is a equivalent .net framework class).
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top