Finding a share's directory spec

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NetworkElf

    #1

    Finding a share's directory spec

    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\so meshare and give me
    c:\somedir\some dir\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.


  • zacks@construction-imaging.com

    #2
    Re: Finding a share's directory spec

    On Apr 27, 10:39 am, "NetworkElf " <Network...@nos pam.nospamwrote :
    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\so meshare and give me
    c:\somedir\some dir\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.

    Comment

    • NetworkElf

      #3
      Re: Finding a share's directory spec


      <zacks@construc tion-imaging.comwrot e in message
      news:1177685666 .994446.320930@ r35g2000prh.goo glegroups.com.. .
      On Apr 27, 10:39 am, "NetworkElf " <Network...@nos pam.nospamwrote :
      >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\so meshare and give me
      >c:\somedir\som edir\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.


      Comment

      • Matthias Tacke

        #4
        Re: Finding a share's directory spec

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

        Found it with scriptomatic for wsh/vbs.

        This is my untested try to convert to vb.net

        ' The wmi Win32_ShareToDi rectory class allows you to get that information
        ' You need to add a reference to System.Manageme nt for this example.

        Dim moReturn As Management.Mana gementObjectCol lection
        Dim moSearch As Management.Mana gementObjectSea rcher
        Dim mo As Management.Mana gementObject

        moSearch = New Management.Mana gementObjectSea rcher(_
        "Select * from Win32_ShareToDi rectory")

        moReturn = moSearch.Get

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


        HTH

        --
        Greetings
        Matthias

        Comment

        • NetworkElf

          #5
          Re: Finding a share's directory spec


          "Matthias Tacke" <Matthias@Tacke .dewrote in message
          news:f0tc19$7ie $1@news.albasan i.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_ShareToDi rectory.
          >
          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.


          Comment

          • Jeffrey Tan[MSFT]

            #6
            Re: Finding a share's directory spec

            Hi,

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

            Dim objClass As New Management.Mana gementClass("Wi n32_Share")
            Dim objShare As Management.Mana gementObject
            For Each objShare In objClass.GetIns tances()
            Console.WriteLi ne(String.Forma t("{0} -{1}",
            objShare.Proper ties("Name").Va lue, objShare.Proper ties("Path").Va lue))
            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/subscripti...ult.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/subscripti...t/default.aspx.
            =============== =============== =============== =====
            This posting is provided "AS IS" with no warranties, and confers no rights.



            Comment

            • NetworkElf

              #7
              Re: Finding a share's directory spec


              ""Jeffrey Tan[MSFT]"" <jetan@online.m icrosoft.comwro te in message
              news:HLHTm6wiHH A.4332@TK2MSFTN GHUB02.phx.gbl. ..
              Hi,
              >
              Yes, you may query this information through WMI Win32_Share class. More
              specific, Win32_Share.Pat h property contains the local path to this share.
              The code snippet works well on my side:
              >
              Dim objClass As New Management.Mana gementClass("Wi n32_Share")
              Dim objShare As Management.Mana gementObject
              For Each objShare In objClass.GetIns tances()
              Console.WriteLi ne(String.Forma t("{0} -{1}",
              objShare.Proper ties("Name").Va lue, objShare.Proper ties("Path").Va lue))
              Next objShare
              Thank you, Jeffrey.


              Comment

              • Jeffrey Tan[MSFT]

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

                Best regards,
                Jeffrey Tan
                Microsoft Online Community Support
                =============== =============== =============== =====
                Get notification to my posts through email? Please refer to
                http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
                =============== =============== =============== =====
                This posting is provided "AS IS" with no warranties, and confers no rights.


                Comment

                • NetworkElf

                  #9
                  Re: Finding a share's directory spec

                  ----- Original Message -----
                  From: ""Jeffrey Tan[MSFT]"" <jetan@online.m icrosoft.com>
                  Newsgroups: microsoft.publi c.dotnet.langua ges.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.Mana gementClass("Wi n32_Share")
                  Dim objShare As Management.Mana gementObject

                  For Each objShare In objClass.GetIns tances()

                  If objShare.Proper ties("Name").Va lue = "VPHOME" Then

                  VPHOMEpath = objShare.Proper ties("Path").Va lue

                  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.Proper ties("Path").Va lue 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.


                  Comment

                  • NetworkElf

                    #10
                    Re: Finding a share's directory spec


                    "NetworkElf " <NetworkElf@nos pam.nospamwrote in message
                    news:eOloiDPjHH A.4772@TK2MSFTN GP05.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\Local Service 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.


                    Comment

                    • Jeffrey Tan[MSFT]

                      #11
                      Re: Finding a share's directory spec

                      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/subscripti...ult.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/subscripti...t/default.aspx.
                      =============== =============== =============== =====
                      This posting is provided "AS IS" with no warranties, and confers no rights.



                      Comment

                      • Jeffrey Tan[MSFT]

                        #12
                        Re: Finding a share's directory spec

                        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/subscripti...ult.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/subscripti...t/default.aspx.
                        =============== =============== =============== =====
                        This posting is provided "AS IS" with no warranties, and confers no rights.



                        Comment

                        • Jeffrey Tan[MSFT]

                          #13
                          Re: Finding a share's directory spec

                          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/subscripti...ult.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/subscripti...t/default.aspx.
                          =============== =============== =============== =====
                          This posting is provided "AS IS" with no warranties, and confers no rights.



                          Comment

                          • Jeffrey Tan[MSFT]

                            #14
                            Re: Finding a share's directory spec

                            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/subscripti...ult.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/subscripti...t/default.aspx.
                            =============== =============== =============== =====
                            This posting is provided "AS IS" with no warranties, and confers no rights.

                            Comment

                            • NetworkElf

                              #15
                              Re: Finding a share's directory spec


                              ""Jeffrey Tan[MSFT]"" <jetan@online.m icrosoft.comwro te in message
                              news:u1fYvnukHH A.4032@TK2MSFTN GHUB02.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.


                              Comment

                              Working...