views:

279

answers:

2

Hi, I'm need of some way of finding the UNC Path of a share via a script or command line or even a custom created program. I'm trying to automate deletion of users and the setup is a bit complicated.

Home folders are set up like this:

We create a folder on a Disk on a fileserver. When this folder is created, a share is automatically created on a lower level Then the DFS Links are set up towards the newly created share.

Now, when deleting a user, I could just delete the DFS Folder, meaning that the target folder is the one being deleted. But since it's a share, that cannot happen.

SO, I need to find out where this share is actually pointing at and then programtically delete THAT folder.

Any idea?

A: 

Here is a post on enumerating the shares on a given host using C#.

It uses the Win32_Share WMI class, which has the disk path of the share as one of its properties. It might be possible to use that class to search for a particular share, given a UNC path. Or if you knew the name of the share you can simply loop through the enumeration results until you find it.

Chris Tybur
A: 

I have done something similar in the past using the native call to netapi32.dll.

The method is called NetShareDel and there is some sample code here. Remember to release your memory properly.

Exist