-4

Is there a way to tell if a folder is shared For example I have folder D:/data1 I would like to know if it is shared or if is not.
Is this possible to do with golang or CMD commands? Is there a example on how to do this?
My goal is to be able to pass in a root folder D:/data2 and tell if is a shared folder.
Example of what i would like to do.

if shared("D:/data2") {
 //handle if it is shared
} else {
 //handle not shared folder
}

I just have not bin able to find a way to detect if the folder is shared. Thank you for your help!

Justin
  • 1,249
  • 1
  • 15
  • 37

2 Answers2

0

Disclaimer: I'm far from a windows cli expert.

You're on the right path in terms of os/exec.Cmd to execute OS specific commands on your target system.

You should be able to use the net share command to display all current local shares. Unfortunately while you can check a sharename with that command too, there doesn't appear to be any reverse lookup, so you'll probably have to write some code that can poke through the results of net share and look for the relevant path.

The output is formatted nicely enough, so it shouldn't be that difficult to write a function that uses net share to create a map of all windows shares for easy look up.

AndrewN
  • 425
  • 2
  • 6
-1

The C# solution to this problem is to use WMI. Since this is very Windows-specific, I don't believe anything out of the Go standard library will help you here.

We can see in this answer that a third-party package does exist for using WMI, as well as another package from Stack Exchange. You can try to make something out of the combination of the C# solution and the API available with those WMI packages.

Community
  • 1
  • 1
Lander
  • 3,369
  • 2
  • 37
  • 53