Determine the mapped network path from cmd windowCopy UNC network path (not drive letter) for paths on mapped...

Can we "borrow" our answers to populate our own websites?

Can the "Friends" spell be used without making the target hostile?

Prioritising polygons in QGIS

Nuance between philia and mania?

Plausible reason for gold-digging ant

How to access internet and run apt-get through a middle server?

Why did the villain in the first Men in Black movie care about Earth's Cockroaches?

Count repetitions of an array

Website seeing my Facebook data?

Potential client has a problematic employee I can't work with

Calculate the true diameter of stars from photographic plate

Why is 'diphthong' pronounced the way it is?

Sprint is 2 week and 40-stories

Separate environment for personal and development use under macOS

Non-Cancer terminal illness that can affect young (age 10-13) girls?

How do you funnel food off a cutting board?

Is there any risk in sharing info about technologies and products we use with a supplier?

Translation needed for 130 years old church document

How do you voice extended chords?

How to politely refuse in-office gym instructor for steroids and protein

Saint abbreviation

How do I prevent a homebrew Grappling Hook feature from trivializing Tomb of Annihilation?

Square Root Distance from Integers

microtype error with lualatex: "attempt to call field warning a nil value"



Determine the mapped network path from cmd window


Copy UNC network path (not drive letter) for paths on mapped drives from Windows ExplorerPutting User Directory on Mapped Network Drive on Windows 7Copy UNC network path (not drive letter) for paths on mapped drives from Windows Exploreraccessing the mapped network drives using mingw shellRename a Mapped Network Drive via CMDHow do I get the physical path to a mapped DIRECTORY (not a mapped drive)?Cmd cannot find a mapped driveCan't access Python from cmd unless on c: driveWindows cmd: escape commands to start cmd from batch file, executing commands that add to PATHchange to mapped network drive at command lineWindows Connect to Mapped Network Drive Letter without File explorer













26















I have a network drive - mapped to Z:



Is there a simple command to know the full network path from cmd ?



I.e. if cmd shows Z:ABC, I had like a command to output \networkDriveMappedDirABC



net use is fine but I would like to get the full path of the current working directory (for quick copies).










share|improve this question





























    26















    I have a network drive - mapped to Z:



    Is there a simple command to know the full network path from cmd ?



    I.e. if cmd shows Z:ABC, I had like a command to output \networkDriveMappedDirABC



    net use is fine but I would like to get the full path of the current working directory (for quick copies).










    share|improve this question



























      26












      26








      26


      5






      I have a network drive - mapped to Z:



      Is there a simple command to know the full network path from cmd ?



      I.e. if cmd shows Z:ABC, I had like a command to output \networkDriveMappedDirABC



      net use is fine but I would like to get the full path of the current working directory (for quick copies).










      share|improve this question
















      I have a network drive - mapped to Z:



      Is there a simple command to know the full network path from cmd ?



      I.e. if cmd shows Z:ABC, I had like a command to output \networkDriveMappedDirABC



      net use is fine but I would like to get the full path of the current working directory (for quick copies).







      windows-7 windows command-line network-drive






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 30 '13 at 8:00







      Ofiris

















      asked May 27 '13 at 10:13









      OfirisOfiris

      1,39811221




      1,39811221






















          4 Answers
          4






          active

          oldest

          votes


















          37














          Type



          net use


          Which will shows you all currently connected network drive.



          OK           Z:        \127.0.0.1c$            Microsoft Windows Network





          share|improve this answer
























          • Thanks, do you know a way to get the full path of the current working directory?

            – Ofiris
            May 27 '13 at 11:23






          • 1





            What about echo %cd% ?

            – Endoro
            May 27 '13 at 14:53











          • @Endoro, echo %cd% outputs the current directory (Z:ABC) and not \netDriveABC

            – Ofiris
            May 30 '13 at 7:59













          • I don't think there is a simple command line you can do to get it. You may be able to write a batch / powershell script to do it, but I haven't tried to make one. Check the answer from Icarus on: superuser.com/questions/244579/… maybe you can use it to your need.

            – Darius
            Jun 6 '13 at 19:20











          • What about drives which are not currently connected (e.g., over a VPN which is currently disconnected)?

            – user49214
            Aug 11 '15 at 16:59



















          1














          It's quite an old question but.. I was looking for the exact same answer as I was trying to create a batch that will use the UNC path to the actual location of the patch and do some things there (so only copy&paste to another location/folder and start again).



          As I couldn't find an answer I found a solution myself, but it's not very beautiful and certainly not a simple command. But it's possible to implement in batch. On CMD it would be:



          FOR /F "tokens=2" %i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
          SET cNetworkPath=%i)
          SET cNetworkPath=%cNetworkPath%%CD:~2%
          ECHO %cNetworkPath%


          You can copy the four lines (better 4+empty line) and paste them into CMD to get an imidiate echo of the path to copy it.



          In batch you would use it a bit differently:



          FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%~d0"') DO (
          bNetworkPath=%%i)
          SET bCheckPath=!bOriginalPath!%~p0


          The variable %CD% stores the current path and you need only the drive letter so you only search for that with the FIND command in NET USE. With the "tokens=2" (or 3, depending on NET USE output) the %i variable stores the path to the drive letter you searched for. After that the second SET command adds the folders you browsed on the network drive with %CD:~2% (offset 2 to cut off the drive letter).



          For batch you use the %~d0 or %~p0 variables. %0 stores the full path of the batch itself (e. g. Z:temptest.bat ; %~d0 = Z: ; %~p0 = temp ; d = drive, p = path, f = full path, n = name) otherwise it's similar to the CMD command.






          share|improve this answer
























          • the sample is intriguing, but broken. For example the (DO...) in batch example is missing SET ..., and bOriginalPath is not defined anywhere.

            – matt wilkie
            Jul 14 '16 at 22:04



















          0














          The path of the bat may be different from the working directory. So we need Mykorrhiza's first approach inside a bat. To accommodate the situation of missing status and also local disk drives, we need additional checks. The following is the working code:



          SET cNetworkPath=    
          FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
          SET cNetworkPath=%%i)
          if "%cNetworkPath%" == "%CD:~0,2%" (
          FOR /F "tokens=3" %%i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
          SET cNetworkPath=%%i)
          )
          if "%cNetworkPath%" == "" set cNetworkPath=%CD:~0,2%
          SET cNetworkPath=%cNetworkPath%%CD:~2%
          ECHO %cNetworkPath%


          The above code works in most cases, but there are cases where the net use and the find do not work, the following is the finally tested work method:



          SET cNetworkPath=
          for /f "tokens=2" %%i in ('wmic path win32_mappedlogicaldisk get deviceid^, providername ^| findstr "%CD:~0,2%"') do (set cNetworkPath=%%i)
          echo %cNetworkPath%





          share|improve this answer

































            0














            If you want it to always display it at your prompt, you could



            set prompt=$M$Q$S$P


            which will show you your UNC path and your drive letter based path.






            share|improve this answer








            New contributor




            Cookie Butter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f600353%2fdetermine-the-mapped-network-path-from-cmd-window%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              37














              Type



              net use


              Which will shows you all currently connected network drive.



              OK           Z:        \127.0.0.1c$            Microsoft Windows Network





              share|improve this answer
























              • Thanks, do you know a way to get the full path of the current working directory?

                – Ofiris
                May 27 '13 at 11:23






              • 1





                What about echo %cd% ?

                – Endoro
                May 27 '13 at 14:53











              • @Endoro, echo %cd% outputs the current directory (Z:ABC) and not \netDriveABC

                – Ofiris
                May 30 '13 at 7:59













              • I don't think there is a simple command line you can do to get it. You may be able to write a batch / powershell script to do it, but I haven't tried to make one. Check the answer from Icarus on: superuser.com/questions/244579/… maybe you can use it to your need.

                – Darius
                Jun 6 '13 at 19:20











              • What about drives which are not currently connected (e.g., over a VPN which is currently disconnected)?

                – user49214
                Aug 11 '15 at 16:59
















              37














              Type



              net use


              Which will shows you all currently connected network drive.



              OK           Z:        \127.0.0.1c$            Microsoft Windows Network





              share|improve this answer
























              • Thanks, do you know a way to get the full path of the current working directory?

                – Ofiris
                May 27 '13 at 11:23






              • 1





                What about echo %cd% ?

                – Endoro
                May 27 '13 at 14:53











              • @Endoro, echo %cd% outputs the current directory (Z:ABC) and not \netDriveABC

                – Ofiris
                May 30 '13 at 7:59













              • I don't think there is a simple command line you can do to get it. You may be able to write a batch / powershell script to do it, but I haven't tried to make one. Check the answer from Icarus on: superuser.com/questions/244579/… maybe you can use it to your need.

                – Darius
                Jun 6 '13 at 19:20











              • What about drives which are not currently connected (e.g., over a VPN which is currently disconnected)?

                – user49214
                Aug 11 '15 at 16:59














              37












              37








              37







              Type



              net use


              Which will shows you all currently connected network drive.



              OK           Z:        \127.0.0.1c$            Microsoft Windows Network





              share|improve this answer













              Type



              net use


              Which will shows you all currently connected network drive.



              OK           Z:        \127.0.0.1c$            Microsoft Windows Network






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered May 27 '13 at 11:20









              DariusDarius

              4,68622020




              4,68622020













              • Thanks, do you know a way to get the full path of the current working directory?

                – Ofiris
                May 27 '13 at 11:23






              • 1





                What about echo %cd% ?

                – Endoro
                May 27 '13 at 14:53











              • @Endoro, echo %cd% outputs the current directory (Z:ABC) and not \netDriveABC

                – Ofiris
                May 30 '13 at 7:59













              • I don't think there is a simple command line you can do to get it. You may be able to write a batch / powershell script to do it, but I haven't tried to make one. Check the answer from Icarus on: superuser.com/questions/244579/… maybe you can use it to your need.

                – Darius
                Jun 6 '13 at 19:20











              • What about drives which are not currently connected (e.g., over a VPN which is currently disconnected)?

                – user49214
                Aug 11 '15 at 16:59



















              • Thanks, do you know a way to get the full path of the current working directory?

                – Ofiris
                May 27 '13 at 11:23






              • 1





                What about echo %cd% ?

                – Endoro
                May 27 '13 at 14:53











              • @Endoro, echo %cd% outputs the current directory (Z:ABC) and not \netDriveABC

                – Ofiris
                May 30 '13 at 7:59













              • I don't think there is a simple command line you can do to get it. You may be able to write a batch / powershell script to do it, but I haven't tried to make one. Check the answer from Icarus on: superuser.com/questions/244579/… maybe you can use it to your need.

                – Darius
                Jun 6 '13 at 19:20











              • What about drives which are not currently connected (e.g., over a VPN which is currently disconnected)?

                – user49214
                Aug 11 '15 at 16:59

















              Thanks, do you know a way to get the full path of the current working directory?

              – Ofiris
              May 27 '13 at 11:23





              Thanks, do you know a way to get the full path of the current working directory?

              – Ofiris
              May 27 '13 at 11:23




              1




              1





              What about echo %cd% ?

              – Endoro
              May 27 '13 at 14:53





              What about echo %cd% ?

              – Endoro
              May 27 '13 at 14:53













              @Endoro, echo %cd% outputs the current directory (Z:ABC) and not \netDriveABC

              – Ofiris
              May 30 '13 at 7:59







              @Endoro, echo %cd% outputs the current directory (Z:ABC) and not \netDriveABC

              – Ofiris
              May 30 '13 at 7:59















              I don't think there is a simple command line you can do to get it. You may be able to write a batch / powershell script to do it, but I haven't tried to make one. Check the answer from Icarus on: superuser.com/questions/244579/… maybe you can use it to your need.

              – Darius
              Jun 6 '13 at 19:20





              I don't think there is a simple command line you can do to get it. You may be able to write a batch / powershell script to do it, but I haven't tried to make one. Check the answer from Icarus on: superuser.com/questions/244579/… maybe you can use it to your need.

              – Darius
              Jun 6 '13 at 19:20













              What about drives which are not currently connected (e.g., over a VPN which is currently disconnected)?

              – user49214
              Aug 11 '15 at 16:59





              What about drives which are not currently connected (e.g., over a VPN which is currently disconnected)?

              – user49214
              Aug 11 '15 at 16:59













              1














              It's quite an old question but.. I was looking for the exact same answer as I was trying to create a batch that will use the UNC path to the actual location of the patch and do some things there (so only copy&paste to another location/folder and start again).



              As I couldn't find an answer I found a solution myself, but it's not very beautiful and certainly not a simple command. But it's possible to implement in batch. On CMD it would be:



              FOR /F "tokens=2" %i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
              SET cNetworkPath=%i)
              SET cNetworkPath=%cNetworkPath%%CD:~2%
              ECHO %cNetworkPath%


              You can copy the four lines (better 4+empty line) and paste them into CMD to get an imidiate echo of the path to copy it.



              In batch you would use it a bit differently:



              FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%~d0"') DO (
              bNetworkPath=%%i)
              SET bCheckPath=!bOriginalPath!%~p0


              The variable %CD% stores the current path and you need only the drive letter so you only search for that with the FIND command in NET USE. With the "tokens=2" (or 3, depending on NET USE output) the %i variable stores the path to the drive letter you searched for. After that the second SET command adds the folders you browsed on the network drive with %CD:~2% (offset 2 to cut off the drive letter).



              For batch you use the %~d0 or %~p0 variables. %0 stores the full path of the batch itself (e. g. Z:temptest.bat ; %~d0 = Z: ; %~p0 = temp ; d = drive, p = path, f = full path, n = name) otherwise it's similar to the CMD command.






              share|improve this answer
























              • the sample is intriguing, but broken. For example the (DO...) in batch example is missing SET ..., and bOriginalPath is not defined anywhere.

                – matt wilkie
                Jul 14 '16 at 22:04
















              1














              It's quite an old question but.. I was looking for the exact same answer as I was trying to create a batch that will use the UNC path to the actual location of the patch and do some things there (so only copy&paste to another location/folder and start again).



              As I couldn't find an answer I found a solution myself, but it's not very beautiful and certainly not a simple command. But it's possible to implement in batch. On CMD it would be:



              FOR /F "tokens=2" %i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
              SET cNetworkPath=%i)
              SET cNetworkPath=%cNetworkPath%%CD:~2%
              ECHO %cNetworkPath%


              You can copy the four lines (better 4+empty line) and paste them into CMD to get an imidiate echo of the path to copy it.



              In batch you would use it a bit differently:



              FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%~d0"') DO (
              bNetworkPath=%%i)
              SET bCheckPath=!bOriginalPath!%~p0


              The variable %CD% stores the current path and you need only the drive letter so you only search for that with the FIND command in NET USE. With the "tokens=2" (or 3, depending on NET USE output) the %i variable stores the path to the drive letter you searched for. After that the second SET command adds the folders you browsed on the network drive with %CD:~2% (offset 2 to cut off the drive letter).



              For batch you use the %~d0 or %~p0 variables. %0 stores the full path of the batch itself (e. g. Z:temptest.bat ; %~d0 = Z: ; %~p0 = temp ; d = drive, p = path, f = full path, n = name) otherwise it's similar to the CMD command.






              share|improve this answer
























              • the sample is intriguing, but broken. For example the (DO...) in batch example is missing SET ..., and bOriginalPath is not defined anywhere.

                – matt wilkie
                Jul 14 '16 at 22:04














              1












              1








              1







              It's quite an old question but.. I was looking for the exact same answer as I was trying to create a batch that will use the UNC path to the actual location of the patch and do some things there (so only copy&paste to another location/folder and start again).



              As I couldn't find an answer I found a solution myself, but it's not very beautiful and certainly not a simple command. But it's possible to implement in batch. On CMD it would be:



              FOR /F "tokens=2" %i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
              SET cNetworkPath=%i)
              SET cNetworkPath=%cNetworkPath%%CD:~2%
              ECHO %cNetworkPath%


              You can copy the four lines (better 4+empty line) and paste them into CMD to get an imidiate echo of the path to copy it.



              In batch you would use it a bit differently:



              FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%~d0"') DO (
              bNetworkPath=%%i)
              SET bCheckPath=!bOriginalPath!%~p0


              The variable %CD% stores the current path and you need only the drive letter so you only search for that with the FIND command in NET USE. With the "tokens=2" (or 3, depending on NET USE output) the %i variable stores the path to the drive letter you searched for. After that the second SET command adds the folders you browsed on the network drive with %CD:~2% (offset 2 to cut off the drive letter).



              For batch you use the %~d0 or %~p0 variables. %0 stores the full path of the batch itself (e. g. Z:temptest.bat ; %~d0 = Z: ; %~p0 = temp ; d = drive, p = path, f = full path, n = name) otherwise it's similar to the CMD command.






              share|improve this answer













              It's quite an old question but.. I was looking for the exact same answer as I was trying to create a batch that will use the UNC path to the actual location of the patch and do some things there (so only copy&paste to another location/folder and start again).



              As I couldn't find an answer I found a solution myself, but it's not very beautiful and certainly not a simple command. But it's possible to implement in batch. On CMD it would be:



              FOR /F "tokens=2" %i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
              SET cNetworkPath=%i)
              SET cNetworkPath=%cNetworkPath%%CD:~2%
              ECHO %cNetworkPath%


              You can copy the four lines (better 4+empty line) and paste them into CMD to get an imidiate echo of the path to copy it.



              In batch you would use it a bit differently:



              FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%~d0"') DO (
              bNetworkPath=%%i)
              SET bCheckPath=!bOriginalPath!%~p0


              The variable %CD% stores the current path and you need only the drive letter so you only search for that with the FIND command in NET USE. With the "tokens=2" (or 3, depending on NET USE output) the %i variable stores the path to the drive letter you searched for. After that the second SET command adds the folders you browsed on the network drive with %CD:~2% (offset 2 to cut off the drive letter).



              For batch you use the %~d0 or %~p0 variables. %0 stores the full path of the batch itself (e. g. Z:temptest.bat ; %~d0 = Z: ; %~p0 = temp ; d = drive, p = path, f = full path, n = name) otherwise it's similar to the CMD command.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 18 '15 at 14:22









              MykorrhizaMykorrhiza

              111




              111













              • the sample is intriguing, but broken. For example the (DO...) in batch example is missing SET ..., and bOriginalPath is not defined anywhere.

                – matt wilkie
                Jul 14 '16 at 22:04



















              • the sample is intriguing, but broken. For example the (DO...) in batch example is missing SET ..., and bOriginalPath is not defined anywhere.

                – matt wilkie
                Jul 14 '16 at 22:04

















              the sample is intriguing, but broken. For example the (DO...) in batch example is missing SET ..., and bOriginalPath is not defined anywhere.

              – matt wilkie
              Jul 14 '16 at 22:04





              the sample is intriguing, but broken. For example the (DO...) in batch example is missing SET ..., and bOriginalPath is not defined anywhere.

              – matt wilkie
              Jul 14 '16 at 22:04











              0














              The path of the bat may be different from the working directory. So we need Mykorrhiza's first approach inside a bat. To accommodate the situation of missing status and also local disk drives, we need additional checks. The following is the working code:



              SET cNetworkPath=    
              FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
              SET cNetworkPath=%%i)
              if "%cNetworkPath%" == "%CD:~0,2%" (
              FOR /F "tokens=3" %%i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
              SET cNetworkPath=%%i)
              )
              if "%cNetworkPath%" == "" set cNetworkPath=%CD:~0,2%
              SET cNetworkPath=%cNetworkPath%%CD:~2%
              ECHO %cNetworkPath%


              The above code works in most cases, but there are cases where the net use and the find do not work, the following is the finally tested work method:



              SET cNetworkPath=
              for /f "tokens=2" %%i in ('wmic path win32_mappedlogicaldisk get deviceid^, providername ^| findstr "%CD:~0,2%"') do (set cNetworkPath=%%i)
              echo %cNetworkPath%





              share|improve this answer






























                0














                The path of the bat may be different from the working directory. So we need Mykorrhiza's first approach inside a bat. To accommodate the situation of missing status and also local disk drives, we need additional checks. The following is the working code:



                SET cNetworkPath=    
                FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
                SET cNetworkPath=%%i)
                if "%cNetworkPath%" == "%CD:~0,2%" (
                FOR /F "tokens=3" %%i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
                SET cNetworkPath=%%i)
                )
                if "%cNetworkPath%" == "" set cNetworkPath=%CD:~0,2%
                SET cNetworkPath=%cNetworkPath%%CD:~2%
                ECHO %cNetworkPath%


                The above code works in most cases, but there are cases where the net use and the find do not work, the following is the finally tested work method:



                SET cNetworkPath=
                for /f "tokens=2" %%i in ('wmic path win32_mappedlogicaldisk get deviceid^, providername ^| findstr "%CD:~0,2%"') do (set cNetworkPath=%%i)
                echo %cNetworkPath%





                share|improve this answer




























                  0












                  0








                  0







                  The path of the bat may be different from the working directory. So we need Mykorrhiza's first approach inside a bat. To accommodate the situation of missing status and also local disk drives, we need additional checks. The following is the working code:



                  SET cNetworkPath=    
                  FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
                  SET cNetworkPath=%%i)
                  if "%cNetworkPath%" == "%CD:~0,2%" (
                  FOR /F "tokens=3" %%i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
                  SET cNetworkPath=%%i)
                  )
                  if "%cNetworkPath%" == "" set cNetworkPath=%CD:~0,2%
                  SET cNetworkPath=%cNetworkPath%%CD:~2%
                  ECHO %cNetworkPath%


                  The above code works in most cases, but there are cases where the net use and the find do not work, the following is the finally tested work method:



                  SET cNetworkPath=
                  for /f "tokens=2" %%i in ('wmic path win32_mappedlogicaldisk get deviceid^, providername ^| findstr "%CD:~0,2%"') do (set cNetworkPath=%%i)
                  echo %cNetworkPath%





                  share|improve this answer















                  The path of the bat may be different from the working directory. So we need Mykorrhiza's first approach inside a bat. To accommodate the situation of missing status and also local disk drives, we need additional checks. The following is the working code:



                  SET cNetworkPath=    
                  FOR /F "tokens=2" %%i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
                  SET cNetworkPath=%%i)
                  if "%cNetworkPath%" == "%CD:~0,2%" (
                  FOR /F "tokens=3" %%i IN ('NET USE ^| FIND "%CD:~0,2%"') DO (
                  SET cNetworkPath=%%i)
                  )
                  if "%cNetworkPath%" == "" set cNetworkPath=%CD:~0,2%
                  SET cNetworkPath=%cNetworkPath%%CD:~2%
                  ECHO %cNetworkPath%


                  The above code works in most cases, but there are cases where the net use and the find do not work, the following is the finally tested work method:



                  SET cNetworkPath=
                  for /f "tokens=2" %%i in ('wmic path win32_mappedlogicaldisk get deviceid^, providername ^| findstr "%CD:~0,2%"') do (set cNetworkPath=%%i)
                  echo %cNetworkPath%






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Oct 17 '16 at 19:50

























                  answered Sep 12 '16 at 14:30









                  FrankFrank

                  414




                  414























                      0














                      If you want it to always display it at your prompt, you could



                      set prompt=$M$Q$S$P


                      which will show you your UNC path and your drive letter based path.






                      share|improve this answer








                      New contributor




                      Cookie Butter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        0














                        If you want it to always display it at your prompt, you could



                        set prompt=$M$Q$S$P


                        which will show you your UNC path and your drive letter based path.






                        share|improve this answer








                        New contributor




                        Cookie Butter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          0












                          0








                          0







                          If you want it to always display it at your prompt, you could



                          set prompt=$M$Q$S$P


                          which will show you your UNC path and your drive letter based path.






                          share|improve this answer








                          New contributor




                          Cookie Butter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          If you want it to always display it at your prompt, you could



                          set prompt=$M$Q$S$P


                          which will show you your UNC path and your drive letter based path.







                          share|improve this answer








                          New contributor




                          Cookie Butter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer






                          New contributor




                          Cookie Butter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 14 mins ago









                          Cookie ButterCookie Butter

                          1011




                          1011




                          New contributor




                          Cookie Butter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          Cookie Butter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          Cookie Butter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f600353%2fdetermine-the-mapped-network-path-from-cmd-window%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...

                              Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

                              VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...