• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Command Line Question

kcnychief

█▄█ ▀█▄ █
Political User
#1
Does anyone know of any slick console (cmd.exe) commands that will return the UNC path of a mapped drive with no other text? I need to isolate the UNC path to store it in a text file. So far I have this:

C:\>net use t:
Local name T:
Remote name \\server\share
Resource type Disk
Status OK
# Opens 0
# Connections 1
The command completed successfully.

But all I want is the value of the "Remote name", and I am limited strictly to console commands like dir, echo, net, and so on. A batch file would work fine if you have a set of commands that will get the same result. I am looking to append the value into a text file with a simple redirection like this:

C:\>net use t: >> UNCPath.TXT

Any DOS/cmd gurus know of any tricks to do that? It has to be something that can execute on any PC (2k or XP) without installing anything.
 

fitz

Woah.. I'm still here?
Staff member
Political User
#2
Try this in a batch file

Code:
@echo off
for /f "tokens=2,3 delims=\" %%i in ('net use %1 ^| find "[URL="file://%5C%5C"%27"]\\"'[/URL]) do echo [URL="file://%5C%5C%%i%5C%%j"]\\%%i\%%j[/URL]
just pass the drive letter as a parameter of the batchfile.. ie:

c:\> somename.bat t: >> mydestFile.txt

edit: Removed an extra backslash in the code
 
Last edited:

kcnychief

█▄█ ▀█▄ █
Political User
#3
Worked perfectly, simply amazing.

Reps++

-edit-

Any web resources where I can learn about that - it was pretty sweet :D
 
Last edited:

fitz

Woah.. I'm still here?
Staff member
Political User
#4
Actually, that was "out of my head" so to speak.. sadly enough I didn't need to look it up (other than to remember the exact syntax of the "for" command, which you can get by typing "for /?" and the command line).

YOu can probably google "DOS Batch" and come up with some good resources though..

If you had a list of drive letters, you can actually put them all in a text file (one drive letter per line) and wrap the whole thing in another for loop

Code:
for /f %i in (driveLetterList.txt) do UNCPath.bat %i >> UNCPathList.txt
driveLetterList.txt --> List of Drive letters
UNCPath.bat --> Name of Batch file
UNCPathList.txt --> Destination file
 

kcnychief

█▄█ ▀█▄ █
Political User
#5
Ok so I have spent quite a bit of time on this, question now is how I can shrink below 9 varialbes :dead:

For a little background, this is designed to be a clickable button in Lotus Notes that a user can click, enter the path for a file and then it will paste a URL into a message for them.

I also want to be able to go back to an 8.3 naming convention, as the output acts weird when there are spaces in the file name.

Code:
[FONT=Courier][SIZE=2]szfile := @Prompt([LocalBrowse]; "Select a file:"; "3");[/SIZE][/FONT]
[SIZE=2][FONT=Courier]@If(szfile = ""; @Return(1);[/FONT][/SIZE]
[SIZE=2][FONT=Courier]@Contains(szfile;":\\") & !@Contains(szfile;"C:");@Do(@Command([Execute]; "cmd.exe"; "\" /c echo @echo ^^^<a href='file:^^^/^^^/%1 %2 %3 %4 %5 %6 %7 %8'^^^>^^^<font face=sans-serif size=2^^^>\\\\%1 %2 %3 %4 %5 %6 %7 %8^^^<^^^/a^^^> > ml.bat");@Command([Execute]; "cmd.exe"; "\" /c echo @for ^/f \"tokens=2,3 delims=\\\" %%i in ('net use %1 ^^^| find \"\\\\\"') do @call ml.bat %%i\\%%j\\%2 %3 %4 %5 %6 %7 %8 %9 >gUNC.bat");@Command([Execute]; "cmd.exe"; "\" /c gUNC " + @Left(szFile;"\\") + " " + @Right(szFile;"\\") + " >link.htm"));[/FONT][/SIZE]
[SIZE=2][FONT=Courier]@Do(@Set("szLink";@ReplaceSubstring("file://" + szfile; "/":" "; "^/":"%20"));@Set("linkhtml";"^<html^>^<a href='"+szLink+"'^>^<font face=\"sans-serif, Arial, Helvetica, Geneva\" size=\"2\"^>"+szFile+"^<^/font^>^<^/a^>^<^/html^>");@Command([Execute]; "cmd.exe"; "\" /c echo "+linkhtml+">link.htm"))[/FONT][/SIZE]
[SIZE=2][FONT=Courier]);[/FONT][/SIZE]
[SIZE=2][FONT=Courier]@Do(@Prompt([Ok];"Pause";"Press Space or Enter to continue and create the link.");[/FONT][/SIZE]
[SIZE=2][FONT=Courier]@PostedCommand([FileImport]; "HTML"; "link.htm"))[/FONT][/SIZE]
 

VenomXt

Blame me for the RAZR's
#6
damn I always feel like I am a step behind you guys. But I just wanted to say thanks because I usually learn something from your problems for the future. Its easy to feel like a idiot online and another thing to feel like that in front of your boss. lol. I will shut up now.
 

kcnychief

█▄█ ▀█▄ █
Political User
#7
FWIW, and stop hijacking my thread :)p), I don't think your an idiot. And your ability to solve problems outside of your immediate intelligence makes you more valuable than those who can't do that.

So, chin up :)
 

Members online

No members online now.

Latest posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,013
Latest member
Pdawgintown