Question Locked

Creating a script to extract the UNC path

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
What are the commands to use to call find the full unc path of a drive letter. I need help on how to create a script to find the UNC path

9 replies

by rob miners

Click Start, Run and type cmd and press Enter.

At the commmand prompt type net use and press Enter.

It will give you a list of drive mappings and you will be able to see if the batch file below will help you. Copy and paste it into Notepad and save it as dletter.cmd.

In a batch file to save the information you could use:

@echo off

C:

net use > C:\dletter.txt

goto end

:END

Keep us informed as to your progress if you require further assistance.

If you think that any of the posts that have been made by all TR Members, have solved or contributed to solving the problem, please Mark them as Helpful so that others may benefit from the outcome. ;) :D

by minkey23

The net use command works but the batch file did not work. This is definitely a step in the right direction. I appreciate the help.

Is there a command we can use to invoke a similar command like "net use" when we make a vbs script?

by rob miners

retested the batch file by copying it to notepad and running it. Here is the result.

Status Local Remote Network

-------------------------------------------------------------------------------
OK Z: \\fs2003\e$ Microsoft Windows Network
The command completed successfully.

I don't know how to get it into a VB script but you should be able to call it from a script. Here is a couple of samples to play with.

Set oShell = CreateObject("WScript.Shell")
oShell.Run "test.bat"

Function Tilak()
dim shell
set shell=createobject("wscript.shell")
shell.run "INSTALL.bat"
set shell=nothing

End Function

Keep us informed as to your progress if you require further assistance.

If you think that any of the posts that have been made by all TR Members, have solved or contributed to solving the problem, please Mark them as Helpful so that others may benefit from the outcome. ;) :D

by larryd4

Give me and idea of what UNC path you want to discover.

A mapped drive?

by larryd4

Yo may need to tailor this to your needs but this should do what you need.

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Drives = WshNetwork.EnumNetworkDrives

For i = 0 to Drives.Count - 1 Step 2
WScript.Echo Drives.Item(i), Drives.Item(i+1)

If Drives.Item(i) = "H:" Then
homepath = Drives.Item(i+1)
Else
End If
Wscript.Echo homepath
Next

by rob miners

Set oWshShell = WScript.CreateObject("WScript.Shell")
sCommand = "t1.bat"

oWshShell.Run(sCommand)

by rob miners

This will run the net use command and save the output to c:\dletter.txt

Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /c c: & net use >dletter.txt "
WScript.Quit

This will run the net use command and save the output to c:\dletter.txt and open it in Notepad.

Option Explicit
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /c c: & net use >dletter.txt "_
& " & notepad dletter.txt"
WScript.Quit

http://www.computerperformance.co.uk/ezine/ezine80.htm

Keep us informed as to your progress if you require further assistance.

If you think that any of the posts that have been made by all TR Members, have solved or contributed to solving the problem, please Mark them as Helpful so that others may benefit from the outcome. ;) :D

This discussion is closed to new replies.