Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing the root directory problem?

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
I have a routine that copies a file to a folder named "NewFolder" in number of workstations at a predetermined time each day.
All I get to know about the workstation in advance is it's IP address.
Eg Copy file to //123.456.789.123/c/NewFolder etc.

If NewFolder does not exist, it creates one first.

My problem is that sometimes the name of the root folder is not "C" but sometimes the user has given it a name like "TomsComputer" and I dont know this in advance.
In which case the destination has to be //123.456.789.123/TomsComputer/NewFolder

Is there a way of finding out what the name of each workstation root folder is - or else using something like a wildcard for the root folder name - or not having to state the name at all and just copying direct to the NewFolder?
 
>My problem is that sometimes the name of the root folder is not "C"

It never is. The root drive is never shared out as this by Windows. Best you'll get is C$, a hidden administrative share, which requires administrator rights to access. And whilst C$ share can temporarily be deleted (a reboot restores it, unless a manual registry change is made) it cannot be renamed.

If you have an environment where workstation or server C drives are shared out as C, then this is an administrative decision taken by the company; you certainly cannot rely on it, as you have found.

To be honest, it would be better if they shared the target folder out directly, as then you'd be able to use:

//123.456.789.123/NewFolder (or whatever the selected sharename was)

and then it wouldn't matter where it actually was.

However, if what you are really asking is how to get the Share name (or names) of any given folder on a remote PC, try this code I've put together for you as an example:
Code:
[blue]Public Function GetShareNames(Optional strComputer As String = "127.0.0.1", Optional strPath As String = "C:\") As String()
    Dim wmiSet As Object
    Dim wmiShare As Object
    Dim result As String
    
    result = "None found"
    strPath = Replace(strPath, "\", "\\")
    Set wmiSet = GetObject("WinMgmts:\\" & strComputer & "\root\cimv2").ExecQuery("SELECT * FROM Win32_Share WHERE Path = """ & strPath & """")
       For Each wmiShare In wmiSet
            result = IIf(result = "None found", "", result & Chr$(0)) & wmiShare.Name
    Next
    GetShareNames = Split(result, Chr$(0))
End Function[/blue]

 
Thanks
Yes I had forgotten that the "c" I see is just a share name.
All the computers have just their root folder shared as something and I wanted to access a sub folder of it irrespective of the share name given to it by the user.

Is it valid to use //123.456.789.123/C$/NewFolder even if the remote root folder had been shared out to another name?
 
\\123.456.789.123\C$\NewFolder

Is it valid? Yep (as long as some idiot hasn't tried to remove the Bypass Traverse Checking user right ...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top