Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Finding a share's directory spec

2 views
Skip to first unread message

NetworkElf

unread,
Apr 27, 2007, 10:39:58 AM4/27/07
to
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.


za...@construction-imaging.com

unread,
Apr 27, 2007, 10:54:27 AM4/27/07
to

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.

NetworkElf

unread,
Apr 27, 2007, 10:59:42 AM4/27/07
to

<za...@construction-imaging.com> wrote in message
news:1177685666.9...@r35g2000prh.googlegroups.com...

> On Apr 27, 10:39 am, "NetworkElf" <Network...@nospam.nospam> wrote:

>> 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?
>

> 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.


Matthias Tacke

unread,
Apr 27, 2007, 1:31:20 PM4/27/07
to
NetworkElf wrote:
>
> 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

--
Greetings
Matthias

NetworkElf

unread,
Apr 27, 2007, 1:36:27 PM4/27/07
to

"Matthias Tacke" <Matt...@Tacke.de> wrote in message
news:f0tc19$7ie$1...@news.albasani.net...

> NetworkElf wrote:
>>
>> 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.
>

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.


Jeffrey Tan[MSFT]

unread,
Apr 30, 2007, 6:02:09 AM4/30/07
to
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.

NetworkElf

unread,
Apr 30, 2007, 8:43:36 AM4/30/07
to

""Jeffrey Tan[MSFT]"" <je...@online.microsoft.com> wrote in message
news:HLHTm6wi...@TK2MSFTNGHUB02.phx.gbl...

> 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.


Jeffrey Tan[MSFT]

unread,
Apr 30, 2007, 10:06:18 PM4/30/07
to
Ok, if you still need any help or have any concern, please feel free to
tell me, thanks.

NetworkElf

unread,
May 2, 2007, 3:33:40 PM5/2/07
to
----- Original Message -----
From: ""Jeffrey Tan[MSFT]"" <je...@online.microsoft.com>
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.


NetworkElf

unread,
May 3, 2007, 9:25:28 AM5/3/07
to

"NetworkElf" <Netwo...@nospam.nospam> wrote in message
news:eOloiDPj...@TK2MSFTNGP05.phx.gbl...

>
> 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.


Jeffrey Tan[MSFT]

unread,
May 7, 2007, 12:03:19 AM5/7/07
to
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.

Jeffrey Tan[MSFT]

unread,
May 7, 2007, 5:17:43 AM5/7/07
to
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.

Jeffrey Tan[MSFT]

unread,
May 8, 2007, 10:08:16 PM5/8/07
to
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.

Jeffrey Tan[MSFT]

unread,
May 10, 2007, 5:59:29 AM5/10/07
to
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.

NetworkElf

unread,
May 10, 2007, 8:09:03 AM5/10/07
to

""Jeffrey Tan[MSFT]"" <je...@online.microsoft.com> wrote in message
news:u1fYvnuk...@TK2MSFTNGHUB02.phx.gbl...

> 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.


Jeffrey Tan[MSFT]

unread,
May 10, 2007, 10:46:43 PM5/10/07
to
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.

Jeffrey Tan[MSFT]

unread,
May 14, 2007, 11:22:44 PM5/14/07
to
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.

NetworkElf

unread,
May 17, 2007, 2:10:18 PM5/17/07
to

""Jeffrey Tan[MSFT]"" <je...@online.microsoft.com> wrote in message
news:XA9TXBql...@TK2MSFTNGHUB02.phx.gbl...

> 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.


0 new messages