Finding a share's directory spec

N

NetworkElf

Hi all,

I'm writing a service that needs to discover the full directory path for a
given locally based share at startup. IOW, I need to have the service
running on someserver to take \\someserver\someshare and give me
c:\somedir\somedir\shareddir.

I'm not quite sure where to start reading about how to do this. Could
someone give me a push in the right direction, please?

Thank you.

ne.
 
Z

zacks

Hi all,

I'm writing a service that needs to discover the full directory path for a
given locally based share at startup. IOW, I need to have the service
running on someserver to take \\someserver\someshare and give me
c:\somedir\somedir\shareddir.

I'm not quite sure where to start reading about how to do this. Could
someone give me a push in the right direction, please?

Thank you.

ne.

A real kludgy way to do it would be to fire off a Command Prompt
Window process, feed it the "NET SHARE <sharename>" command and parse
the output for the path.
 
N

NetworkElf

A real kludgy way to do it would be to fire off a Command Prompt
Window process, feed it the "NET SHARE <sharename>" command and parse
the output for the path.

I had considered that, but decided I'd rather avoid that route if I can. I'm
certain the functionality is within vb.net, I've just not been able to find
what I need yet.

Thank you.
 
M

Matthias Tacke

NetworkElf said:
I had considered that, but decided I'd rather avoid that route if I can. I'm
certain the functionality is within vb.net, I've just not been able to find
what I need yet.
There is a wmi class win32_ShareToDirectory.

Found it with scriptomatic for wsh/vbs.

This is my untested try to convert to vb.net

' The wmi Win32_ShareToDirectory class allows you to get that information
' You need to add a reference to System.Management for this example.

Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher(_
"Select * from Win32_ShareToDirectory")

moReturn = moSearch.Get

For Each mo In moReturn
Debug.WriteLine(mo("Share"))
Debug.Indent()
Debug.WriteLine(mo("SharedElement"))
Debug.Unindent()
Next


HTH
 
N

NetworkElf

Matthias Tacke said:
There is a wmi class win32_ShareToDirectory.

Thank you. It seems as if I were on the correct track earlier, but I didn't
pursue it far enough. This is very helpful.

At the moment, I'm suffering from post-lunch malaise after being attacked by
an Indian buffet. I'll take a shot at it next week and post my results.
 
J

Jeffrey Tan[MSFT]

Hi,

Yes, you may query this information through WMI Win32_Share class. More
specific, Win32_Share.Path property contains the local path to this share.
The code snippet works well on my side:

Dim objClass As New Management.ManagementClass("Win32_Share")
Dim objShare As Management.ManagementObject
For Each objShare In objClass.GetInstances()
Console.WriteLine(String.Format("{0} -> {1}",
objShare.Properties("Name").Value, objShare.Properties("Path").Value))
Next objShare

Hope it helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

NetworkElf

"Jeffrey Tan[MSFT]" said:
Hi,

Yes, you may query this information through WMI Win32_Share class. More
specific, Win32_Share.Path property contains the local path to this share.
The code snippet works well on my side:

Dim objClass As New Management.ManagementClass("Win32_Share")
Dim objShare As Management.ManagementObject
For Each objShare In objClass.GetInstances()
Console.WriteLine(String.Format("{0} -> {1}",
objShare.Properties("Name").Value, objShare.Properties("Path").Value))
Next objShare

Thank you, Jeffrey.
 
J

Jeffrey Tan[MSFT]

Ok, if you still need any help or have any concern, please feel free to
tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

NetworkElf

----- Original Message -----
From: ""Jeffrey Tan[MSFT]"" <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
Sent: Monday, April 30, 2007 10:06 PM
Subject: Re: Finding a share's directory spec

Ok, if you still need any help or have any concern, please feel free to
tell me, thanks.

You shouldn't have asked... :D

I used the following code:

Dim VPHOMEpath As String = ""
Dim objClass As New Management.ManagementClass("Win32_Share")
Dim objShare As Management.ManagementObject

For Each objShare In objClass.GetInstances()

If objShare.Properties("Name").Value = "VPHOME" Then

VPHOMEpath = objShare.Properties("Path").Value

End If

Next objShare

Now, if I use it in a standard vb.net app and run it, VPHOMEpath gets the
proper path returned and everything runs fine. If I take the exact same code
and paste it into another project that's running as a service, the wheels
fly off the wagon. Apparently, objShare.Properties("Path").Value returns a
null value when running as a service.

Now, the only difference I can think of is that the standard app is running
under my credentials and the service is running on the local service
account. I would prefer not to run it under a userID if I can avoid it...

Does anyone have any thoughts?

Thank you.
 
N

NetworkElf

NetworkElf said:
Now, the only difference I can think of is that the standard app is
running under my credentials and the service is running on the local
service account. I would prefer not to run it under a userID if I can
avoid it...

This was the problem. When I switched it from running under NT
AUTHORITY\LocalService to Log on as: Local System account, the problem went
away. I'm still not totally clear as to why.

Any insights would be welcome.

Thanks,

ne.
 
J

Jeffrey Tan[MSFT]

Hi,

Sorry for the late response, I am out of office these 2 days.

Ok, I will perform research on this problem and get back to you ASAP.
Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi,

By writting a sample in Windows Service, I can reproduce your problem. It
seems that the code works well under LocalService account while failed to
get "Path" property. I am suspecting it is a security problem. I will spend
more time to dig into it. Thanks for your patient.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi,

Sorry for letting you wait.

I am currently contacting the WMI team for collaborating troubleshoot this
issue now, and I finally got response from a developer from WMI team. I
have passed the sample Windows Service project to them for local reproduce
and my OS version information. Once we got any findings, I will feedback
here ASAP. Thanks for your patient.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi,

Sorry for letting you wait.

Further discussion with the WMI team shows that LocalService account does
not have permission to access the path for shares. You may view the DACL on
shared folders in Computer Management->System Tools -> Shared Folders ->
Shares. You may right click any share folder in right panel and view the
"Security" tabpage.

As you can see, LocalSystem and Administrators will be granted full control
access to them, while LocalService does not have an ACE entry, which means
the LocalService will have no access to them.

Currently, due to the constraint DACL setting on the shared folder, we have
to run the service under Administrators account or LocalSystem account.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

NetworkElf

"Jeffrey Tan[MSFT]" said:
Hi,

Sorry for letting you wait.

Not a problem. Thanks for finding out.
Further discussion with the WMI team shows that LocalService account does
not have permission to access the path for shares. You may view the DACL
on
shared folders in Computer Management->System Tools -> Shared Folders ->
Shares. You may right click any share folder in right panel and view the
"Security" tabpage.

As you can see, LocalSystem and Administrators will be granted full
control
access to them, while LocalService does not have an ACE entry, which means
the LocalService will have no access to them.

Currently, due to the constraint DACL setting on the shared folder, we
have
to run the service under Administrators account or LocalSystem account.

That certainly explains what was going on. I'm going to do some reading
today to find out how to make my service install and use LocalSystem by
default, rather than LocalService.

Otherwise, the service is running like a charm. I appreciate everyone's help
in getting it going. It was a great first project to write. I'm now making a
list of refinements to roll into it at a later time.

Thanks.

ne.
 
J

Jeffrey Tan[MSFT]

Hi,

Thanks for your kindly feedback.

To configure your .Net Windows Service project to run under LocalSystem
account, you may follow the steps below:
1. Double click "ProjectInstaller.cs" in the Solution Explorer to open its
designer in left panel
2. Select "serviceProcessInstaller1" component in the designer
3. In the right side of the Property Browser, there is an item named
"Account", you may click this item dropdown list and select "LocalSystem".
4. Rebuild this project.

Finally, actually, there is another way to obtain the local file share
information without using WMI. That is using NetShareGetInfo Win32 API.
However, you have to p/invoke this API to use it.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi,

Have you reviewed my last reply to you? Does it make sense to you? If you
still need any help or have any concern, please feel free to feedback,
thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

NetworkElf

"Jeffrey Tan[MSFT]" said:
Hi,

Have you reviewed my last reply to you? Does it make sense to you? If you
still need any help or have any concern, please feel free to feedback,
thanks.

Jeffrey,

Thanks for the info. I'll try it as soon as I can.

ne.
 

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