Slight;y updated, may not be 100%, 5pm on a sunny Friday evening here :-)
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_MappedLogicalDisk")
strDriveLetter = "T:"
strNetworkShare = "\\CNXP-06559\shared"
intDriveOK = False
For Each objItem in colItems
' If the drive letter is in use but the share is in-correct,
re-map it
If objItem.Name = strDriveLetter And objItem.ProviderName <>
strNetworkShare Then
'do required stuff
Set objNetwork = CreateObject("Wscript.Network")
objNetwork.RemoveNetworkDrive strDriveLetter
objNetwork.MapNetworkDrive strDriveLetter, strNetworkShare
intdriveok = true
WScript.Echo "Drive: " & objItem.Name & ", server share: "
& objItem.ProviderName
ElseIf objItem.Name = strDriveLetter Then
' gets here if the drive is mapped correctly
intDriveOK = True
Else
'WScript.Echo "Drive ok"
End If
Next
' if the drive letter isn't mapped, map it
If intDriveOK = false Then
Set objNetwork = CreateObject("Wscript.Network")
objNetwork.RemoveNetworkDrive strDriveLetter
objNetwork.MapNetworkDrive strDriveLetter, strNetworkShare
End If
Regards
Tony Patton
Desktop Operations Cavan
Ext 8078
Direct Dial 049 435 2878
email: [email protected]
"Carl Houseman" <[email protected]>
20/03/2009 16:43
Please respond to
"NT System Admin Issues" <[email protected]>
To
"NT System Admin Issues" <[email protected]>
cc
Subject
RE: Scrip Help please?
Doesn?t meet the requirements as stated.
From: Michael B. Smith [mailto:[email protected]]
Sent: Friday, March 20, 2009 12:38 PM
To: NT System Admin Issues
Subject: RE: Scrip Help please?
In fact, call me lazy, but I just short-cut this process, this way:
Net use x: /del 2>nul >nul
Net use x: \\server\share
From: Carl Houseman [mailto:[email protected]]
Sent: Friday, March 20, 2009 12:33 PM
To: NT System Admin Issues
Subject: RE: Scrip Help please?
What is done with the mapping that is retrieved? Output to the screen,
something else?
What you've specified so far doesn't need VBS, can be done in fewer lines
of simple .cmd/.bat scripting.
if exist x:\ (
net use x:|find /I "remote name"
) else (
net use x: \\server\share
)
Doesn't get much simpler.
Carl
From: Steve Kelsay [mailto:[email protected]]
Sent: Friday, March 20, 2009 12: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, 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.
====================================================================
http://www.quinn-insurance.com
This e-mail is intended only for the addressee named above. The contents
should not be copied nor disclosed to any other person. Any views or
opinions expressed are solely those of the sender and
do not necessarily represent those of QUINN-Insurance, unless otherwise
specifically stated . As internet communications are not secure,
QUINN-Insurance is not responsible for the contents of this message nor
responsible for any change made to this message after it was sent by the
original sender. Although virus scanning is used on all inbound and
outbound e-mail, we advise you to carry out your own virus check before
opening any attachment. We cannot accept liability for any damage sustained
as a result of any software viruses.
====================================================================
QUINN-Life Direct Limited is regulated by the Financial Regulator.
QUINN-Insurance Limited is regulated by the Financial Regulator and
regulated by the Financial Services Authority for the conduct of UK
business.
====================================================================
QUINN-Life Direct Limited is registered in Ireland, registration number
292374 and is a private company limited by shares.
QUINN-Insurance Limited is registered in Ireland, registration number
240768 and is a private company limited by shares.
Both companies have their head office at Dublin Road, Cavan, Co. Cavan.
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~