Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WSH script to Logon with Mapped Drives

Status
Not open for further replies.

bont

Programmer
Sep 7, 2000
200
US
I currently have a script to map multiple drives to assumed drive letters. This script currently doesn't allow a drive to be mapped, if the drive letter is already mapped, this is good, but I will still receive an error, if the node being reference on the network is not connected or active. Does anyone know how to check to see if a node is present prior to trying to map the drive, or something to prevent this error?
 
Hi there,

I have had the same problem. Below is a script that deletes the drive prior to creating the drive. You can cut and past this script. Also save this as a .wsf format (it runs much faster).

Paul F


<package>
<job id=&quot;vbs&quot;>
<script language=&quot;VBScript&quot;>

'logon.vbs
'The following Script logs into the Network
'Script Written by Paul F 04-08-2002

'Variables below are used for connecting network drives
Dim objNetwork, strName
Set objNetwork = CreateObject(&quot;WScript.Network&quot;)

'Variables below are used for enumerating (listing) drives enable for diagnostic
'Set WshNetwork = WScript.CreateObject(&quot;WScript.Network&quot;)
'Set oDrives = WshNetwork.EnumNetworkDrives

'Variables below are used for the win pop-up network message
Dim WshShell, BtnCode
Set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)

On Error Resume Next
'get user name
While strName = &quot;&quot;
strName = objNetwork.UserName
WScript.Sleep 100
WEnd

'Add network drives below to make sure drives are disconnect
'before connecting new drives to network shares
WshNetwork.RemoveNetworkDrive &quot;R:&quot;
WshNetwork.RemoveNetworkDrive &quot;S:&quot;
WshNetwork.RemoveNetworkDrive &quot;T:&quot;
WshNetwork.RemoveNetworkDrive &quot;W:&quot;

' Add network drives below to connect users to network shares
'connect to OAKNTFS 1
objNetwork.MapNetworkDrive &quot;R:&quot;, &quot;\\OAKNTFS1\DEPTAPP1&quot;, False
'connect to OAKNTFS 2
objNetwork.MapNetworkDrive &quot;S:&quot;, &quot;\\OAKNTFS2\DEPTAPP1&quot;, False
'connect to OAKNTFS 3
objNetwork.MapNetworkDrive &quot;T:&quot;, &quot;\\OAKNTFS3\DEPTAPP1&quot;, False
'connect to OAKNTFS 4
objNetwork.MapNetworkDrive &quot;W:&quot;, &quot;\\OAKNTFS4\DEPTAPP1&quot;, False

'This lists the network drives that the user is connected to
'Enable for Diagnostics only
' For i = 0 to oDrives.Count - 1 Step 2
' WScript.Echo &quot;Drive &quot; & oDrives.Item(i) & &quot; = &quot; & oDrives.Item(i+1)
' Next

'The code below used for the win pop-up network message
BtnCode = WshShell.Popup(&quot;Network Drives Connected&quot;, 5, &quot;OakNet Login&quot;, 0 + 64)

' The following code sets the time on the PC to that of the PDC
' Please note the net time command must go to the PDC
Set oShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
oShell.Run &quot;command /C net time \\OAKNTDC2 /set /yes&quot;,0,True


</script>
</job>
</package>
 
Thanx for replying. I have up to this part done already, what I am looking for a way to detect if the computer I am going to map to is connected to the network, prior to trying to map a drive to it. Currently, if the drive letter is not mapped, I map it; however, if the other PC is not present it errors (i.e. my laptop). Any suggestions, anyone?
 
Please see code below:

net.MapNetworkDrive drivelett & &quot;:&quot;,&quot;\\&quot; & servername & &quot;\&quot; & sharename
If err.number = &quot;0&quot; Then
Msgbox &quot;Drive maping worked&quot;
Else
If err.number = &quot;-2147023693&quot; Then
msgbox &quot;Server not available &quot; & err.number
End If
If err.number = &quot;-2147024891&quot; Then
msgbox &quot;Access Denied &quot; & err.number
End If
If err.number = &quot;-2147024811&quot; Then
msgbox &quot;Drive Already Mapped &quot; & err.number
End If
End If

Regards
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top