Finding a share's directory spec

Discussion in 'Microsoft VB .NET' started by NetworkElf, Apr 27, 2007.

  1. NetworkElf

    NetworkElf Guest

    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.
     
    NetworkElf, Apr 27, 2007
    #1
    1. Advertisements

  2. NetworkElf

    Guest

    On Apr 27, 10:39 am, "NetworkElf" <> wrote:
    > 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.
     
    , Apr 27, 2007
    #2
  3. NetworkElf

    NetworkElf Guest

    <> wrote in message
    news:...
    > On Apr 27, 10:39 am, "NetworkElf" <> 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.
     
    NetworkElf, Apr 27, 2007
    #3
  4. 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
     
    Matthias Tacke, Apr 27, 2007
    #4
  5. NetworkElf

    NetworkElf Guest

    "Matthias Tacke" <> wrote in message
    news:f0tc19$7ie$...
    > 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.
     
    NetworkElf, Apr 27, 2007
    #5
  6. 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.
     
    Jeffrey Tan[MSFT], Apr 30, 2007
    #6
  7. NetworkElf

    NetworkElf Guest

    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    > 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.
     
    NetworkElf, Apr 30, 2007
    #7
  8. 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.
     
    Jeffrey Tan[MSFT], May 1, 2007
    #8
  9. NetworkElf

    NetworkElf Guest

    ----- Original Message -----
    From: ""Jeffrey Tan[MSFT]"" <>
    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, May 2, 2007
    #9
  10. NetworkElf

    NetworkElf Guest

    "NetworkElf" <> wrote in message
    news:...
    >
    > 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.
     
    NetworkElf, May 3, 2007
    #10
  11. 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.
     
    Jeffrey Tan[MSFT], May 7, 2007
    #11
  12. 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.
     
    Jeffrey Tan[MSFT], May 7, 2007
    #12
  13. 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.
     
    Jeffrey Tan[MSFT], May 9, 2007
    #13
  14. 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.
     
    Jeffrey Tan[MSFT], May 10, 2007
    #14
  15. NetworkElf

    NetworkElf Guest

    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    > 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.
     
    NetworkElf, May 10, 2007
    #15
  16. 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.
     
    Jeffrey Tan[MSFT], May 11, 2007
    #16
  17. 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.
     
    Jeffrey Tan[MSFT], May 15, 2007
    #17
  18. NetworkElf

    NetworkElf Guest

    ""Jeffrey Tan[MSFT]"" <> wrote in message
    news:...
    > 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.
     
    NetworkElf, May 17, 2007
    #18

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    Recommended spec

    John, Nov 9, 2003, in forum: Microsoft VB .NET
    Replies:
    2
    Views:
    160
    Herfried K. Wagner [MVP]
    Nov 9, 2003
  2. John

    Minimum spec for vs

    John, Dec 18, 2003, in forum: Microsoft VB .NET
    Replies:
    3
    Views:
    176
    Herfried K. Wagner [MVP]
    Dec 18, 2003
  3. JH

    Finding the directory of my installation

    JH, Mar 4, 2004, in forum: Microsoft VB .NET
    Replies:
    2
    Views:
    199
    David Guyer [MS]
    Mar 4, 2004
  4. MadCrazyNewbie

    Getting remote Computer Spec

    MadCrazyNewbie, Mar 15, 2004, in forum: Microsoft VB .NET
    Replies:
    1
    Views:
    700
    Herfried K. Wagner [MVP]
    Mar 15, 2004
  5. jc
    Replies:
    0
    Views:
    189
Loading...

Share This Page