Over the past few weeks, some of our readers have encountered a wshnetwork.mapnetworkdrive capture error. This problem can occur for many reasons. Let’s discuss this now.
Err Object (VBScript) does not contain useful hints. You must detect the error and successfully complete each error-prone action separately.
General rule (recommended practice): leave error handling with
On Error GoTo 0 disabled and only enable it for suspicious activities.
Depending on the circumstances, there may be several reasons why the
mapnetworkdrive method may fail (server down, user banned, wrong/changed account, etc.):
Under MapDRV Dim errResult Set objNetwork WScript =.CreateObject("WScript.Network") errResult is "" If the error goes away, then objNetwork.MapNetworkDrive strDriveLetter, strRemotePath _ , strProfile, strUser, strPassword If Error Number = Then On transition error 0 Set objShell CreateObject("Shell=.Application") objShell.NameSpace(strDriveLetter).Self.Name = strName Different = errResult Err.Number in & 0x" & Hex(Err.Number) & ins & "Err.Source" equals errResult errResult & vbNewLine & Err.Description On transition error 0 MsgBox errResult, vbOKOnly + vbCritical, "An error occurred" end ifend under
Explicit parameterOn transition error 0Dim strResult: strResult = Wscript.ScriptNameDim strDriveLetter, strRemotePath, strUser, strPassword, strProfile, strName _ , objNetwork, objShell, CheckDrive, already connected, intDrive' The section separates variables.StrDriveLetter = "X:"strRemotePath means "\192.168.1.1general"strUser = "User"strPassword means "password".strprofile="true"strName = "Backup Disk"' This section creates objects:' two objShell when counting objNetwork and disksSet ObjShell to CreateObject("WScript.Shell")Set objNetwork = CreateObject("WScript.Network") This is' deals with a large For...Next loop' See Tips, it compares drive words listed with strDriveLetterWeak result, shareAlready Connected = FalseDo when you are already logged in = False strResult is equal to strResult & vbNewLine & New "--- check" Already Connected = False Set CheckDrive = objNetwork.EnumNetworkDrives() For = intDrive 0 For CheckDrive.Count - 1 step double If CheckDrive.Item(intDrive) is equal to strDriveLetter Then Already Connected = True toShare = CheckDrive.Item(intDrive + 1) end if strResult implies strResult and vbNewLine and CheckDrive.Item(intDrive) strResult = strResult && vbTab CheckDrive.Item(intDrive + 1) next If you are already logged in, close Do result = MsgBox("A backup is required now, but the drive is not connected." _ && vbNewLine & vbNewLine "If you are in the market..._ "&vbNewLine&vbTab&"... copy the move, then press ABORT._ "&vbNewLine&vbTab&"...save to "StrRemotePath&&" then press RETRY._ " & vbNewLine & " Otherwise, connect motivation and press IGNORE to continue." _ and vbAbortRetryIgnore + vbQuestion, "BACKUP DISK IS NOT CONNECTED") Select case result Case vbRefuse Call scriptExit vbRetry Case Go to MapDRV opposite case ' The case-else clause is not required exit selectionribbon strResult StrResult equals &vbNewLine&"copy here to &toShareSubmap DRV No override required: the WshNetwork object is already defined ' Set objNetwork = WScript.CreateObject("WScript.Network") Dim errResult If the error goes away, then objNetwork.MapNetworkDrive strDriveLetter, strRemotePath _ , strProfile, strUser, strPassword If Number of Errors = 0 Then On transition error 0 Set objShell CreateObject("Shell=.Application") objShell.NameSpace(strDriveLetter).Self.Name implies strName Different matches errResult Err.Number " & 0x" & Hex(Err.Number) & " & inch Err.Source equals errResult errResult & vbNewLine & Err. On transition error 0 MsgBox errResult, vbOKOnly + vbCritical, "An error occurred" strResult = strResult&vbNewLine&vbNewLine&errResult end ifend underCall scriptExitTipExit Wscript.Echo strResult Wscript.Exitend under
Note that the variable
strResult is only used for debugging purposes to see the following cscript output:
==> D:VB_scriptsSO37776762.vbs37776762.vbs--- new reviewY:\S-PCVB_scripts_help-2147024843 0x80070035 WSHNetwork.MapNetworkDriveThe network path was not found.--- hot testY:\S-PCVB_scripts_help--- new reviewY:\S-PCVB_scripts_helpX: \S-PCtestcopy here to \S-PCtest==>
--- newly found check
Y:scheduled drive; then experiment Retry failed (network path not actually found);
--- new check found
Y:disk programmed again; then mapped the computer to
X:manually, then called the action Ignore;
--- newly found receipt
Y:with drives connected
Do Whileloop has ended and the script will continue after the action is completed.
==> net use x: was /deletex: Removed successfully.==> cscript D:VB_scriptsSO37776762.vbs37776762.vbs--- new reviewY:\S-PCVB_scripts_help==>
The software to fix your PC is just a click away - download it now.