I
I
Ivan2017-11-02 10:15:20
VBScript
Ivan, 2017-11-02 10:15:20

How to determine the path to which a network drive is mapped using vbs?

The script checks for the presence of a disk , if it is connected, then you need to take its path and check it with the path from the current script, if they match, then do nothing, if they differ, then execute and connect the disk . How to extract a variable with the path of a network drive? If fso.driveexists(Drive) then
objNetwork.RemoveNetworkDrive Drivet, true, true
objNetwork.MapNetworkDrive Drive, Share, false

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2017-11-02
@Devagleo

Here's what I managed to write, though crutch, but it works. The check variable returns "nothing" if there is no such drive and path, and returns the path if such a drive is connected. Thus, it is possible to compare the connected network path with the existing one and, in case of a mismatch, reconnect.

Function check(Drive, share)
i = 0
Set oNet = CreateObject("WScript.Network")
Set drv = oNet.EnumNetworkDrives
Ushare = ucase(share)
check = ""
for each element in drv 
    Uelement = ucase(element)
  i = i + 1
  If i Mod 2 = 0 then
  'msgbox n
  m = i - 2
  IF Uelement = Ushare and drive = drv(m) then
  check = element
  end if
  end if
  next
  
end function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question