Reputation: 3304
In vb6 i want to differentiate between shared folder and shared drive.
If in PC1 D:\ is shared as with share name myshare
then shared folder
And in PC1 if D:\myfiles shared with share name myshareddrive
then it is shared drive.
I mean I will be getting inputs like \\pc1\\myshare
amd \\pc1\\myshareddrive
. So now i am not able to find whether they are shared foder or a shared drive.
Upvotes: 1
Views: 439
Reputation: 1040
Presuming that you are using the SMB protocol (used for Windows file shares), there is no portable way to achieve this as the protocol does not communicate the remote path name. There is normally no use for such a feature and it could provide potentially useful information for would-be attackers.
If this is on Windows and you have administrative access, it is possible to query the remote path name via WMI which can be accessed remotely (with authentication).
The simplest way to do this would be to parse the output from wmic.exe
which is available on all Windows platforms since Windows XP (excl. Home Edition) (related superuser.com question):
wmic /node:pc1 share where "name like 'myshare'" get path
Which should produce output along the lines of:
Path
D:\myfiles
To make this work within VB6 (without running other programs), you will need to use COM to query WMI:
Dim results As Object
results = GetObject("winmgmts:\\pc1").ExecQuery("SELECT * FROM Win32_Share WHERE Name LIKE ""myshare""")
Dim pathName As String
If Len(results) > 0 Then
pathName = results(0).Path
Else
' Throw exception instead? Could not find the share.
pathName = ""
End If
I have handled neither authentication (for remote use etc.) nor error checking.
Disclaimer: I have only tested the VBScript equivalent of the above code and not itself.
Upvotes: 4