You could use this :

 

Set wshNetwork = CreateObject("Wscript.network")

 

Set maps=wshNetwork.EnumNetworkDrives

 

Call ChangeMapping(x:, \\server\path <file:///\\server\path> )

 

sub ChangeMapping ( Letter, Path )

                DriveLetterMapped = false

                i = 0

                do while ( (DriveLetterMapped = false) and (i <= ( maps.Length 
- 2) ) )

                                if maps.item(i) = Letter then

                                                ' Letter already mapped, check 
if mapped to same (can be ignored)  or mapped different (needs remapping), no 
need to continue looping

                                                                
DriveLetterMapped = true

                                                                Mapped(i) = true

                                                                if maps.item(i 
+ 1) = Path then

                                                                                
oLogFile.WriteLine("Drive " & Letter & " already mapped correctly to " & Path & 
" , skipped")

                                                                                
'same, ignore

                                                                else

                                                                                
oLogFile.WriteLine("Mapping " & Letter & " from " & maps.item(i + 1) & " to " & 
Path)

                                                                                
'unmap letter, remap

                                                                                
wshNetwork.RemoveNetworkDrive Letter, True, True

                                                                                
wshNetwork.MapNetworkDrive Letter, Path, True

                                                                end if

                                else

                                                'Different letter, continue 
scan next one

                                end if

                                i = i + 2

                Loop

                

                if DriveLetterMapped = false Then

                                'letter not occupied, just map it

                                oLogFile.WriteLine("Mapping " & Letter & " to " 
& Path)

                                wshNetwork.MapNetworkDrive Letter, Path, True

                end if

end sub

 

René

 

From: Reÿé de Haas [mailto:[email protected]] 
Sent: Friday, March 20, 2009 5:28 PM
To: NT System Admin Issues
Subject: RE: Scrip Help please?

 

First you get all mappings with wshNetwork.EnumNetworkDrives then check them

Trick is index 0,2,4 etc are driveletters

Index 1,3,5 etc are the mappings

 

You could do something like this:

 

Option Explicit

 

Dim wshNetwork

Dim maps

Dim i

 

Set wshNetwork = CreateObject("Wscript.network")

 

Set maps=wshNetwork.EnumNetworkDrives

for i=0 to maps.Length-2 step 2

Next

 

Hth

ÿÿÿé

 

From: Steve Kelsay [mailto:[email protected]] 
Sent: Friday, March 20, 2009 5:19 PM
To: NT System Admin Issues
Subject: Scrip Help please?

 

I am looking for help writing a VBScript to 

1.       Detect whether a specified mapped drive exists

2.       If so, retrieve the target mapping (if the X: drive is not mapped to 
\\server\share <file:///\\server\share> , then map it )

 

I have Googled and found lots of stuff, but nothing that does this. I can 
retrieve the drive letter and see if it exists, but where it is mapped to is 
eluding me.

 

It has to be simple. 

 

 

 
________________________________


***
The information in this e-mail is confidential and intended solely for the 
individual or entity to whom it is addressed. If you have received this e-mail 
in error please notify the sender by return e-mail delete this e-mail and 
refrain from any disclosure or action based on the information.
*** 

 

 

 


***
The information in this e-mail is confidential and intended solely for the 
individual or entity to whom it is addressed.  If you have received this e-mail 
in error please notify the sender by return e-mail delete this e-mail and 
refrain from any disclosure or action based on the information.
***

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

Reply via email to