Re: WSH Error when running script



You could use something similar to below to trap the error raised if drive
S: is already mapped:

If (WSHNetwork.UserName = "USERNAME") Then
On Error Resume Next
WSHNetwork.MapNetworkDrive "S:", "\\SERVERNAME\SHARE"
If (Err.Number <> 0) Then
On Error GoTo 0
WSHNetwork.RemoveNetworkDrive "S:", True, True
WSHNetwork.MapNetworkDrive "S:", "\\SERVERNAME\SHARE"
End If
On Error GoTo 0
End If

In case it matters, the above could fail in a logon script if the client is
Windows 95 or 98. The UserName property of the WSHNetwork object can return
a blank value at first on these clients during logon. If you need it, the
workaround is a loop similar to:

' Loop required for Win9x clients during logon.
strNTName = ""
On Error Resume Next
Do While strNTName = ""
strNTName = objNetwork.UserName
Err.Clear
If (Wscript.Version > 5) Then
Wscript.Sleep 100
End If
Loop
On Error GoTo 0

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"James Robertson" <jrobertson@xxxxxxxxxxxxxxxxxxx> wrote in message
news:25A587DD-F482-40EF-838E-76C59C9F80D4@xxxxxxxxxxxxxxxx
Thank you for the response. I am also running this command

if WSHNetwork.UserName="USERNAME" then WSHNetwork.MapNetworkDrive "S:",
"\\SERVERNAME\SHARE"

Will this work or am I wrong on the statement. I thought that I had it
working before.

Thanks in advance.


"Richard Mueller" wrote:

James Robertson wrote:

I am running a simple script to map netwrok drives and it gives me an
error
when the device is already in use.

ERROR: The local device name is already in use.
Code: 80070055
WSHNetwork.MapNetworkDrive

Is there any way to suppress those errors? I am slo using this in a
Group
Policy.

Hi,

An error can be raised when you map a drive because the drive letter is
already in use, perhaps due to a persistent connection. You can trap the
error, remove the drive mapping, and map again. For example:

' Temporarily suspend normal error handling.
On Error Resume Next
' Map a drive
objNetwork.MapNetworkDrive "M:", \\filesrv01\admin
' Test for an error.
If (Err.Number <> 0) Then
' Restore normal error handling
On Error GoTo 0
' Remove the drive mapping.
objNetwork.RemoveNetworkDrive "M:", True, True
objNetwork.MapNetworkDrive "M:", "\\filesrv01\admin"
End If
' Restore normal error handling.
On Error GoTo 0

I suspend normal error handling only for statements I expect might raise
an
error, then restore normal error handling. Otherwise, you'll never know
if
there are unexpected problems.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net





.



Relevant Pages

  • Re: WSH Error when running script
    ... I am sorry let me explain further what I am wanting is a more dynamic script ... based only on their username. ... On Error GoTo 0 ... ' Temporarily suspend normal error handling. ...
    (microsoft.public.windows.server.scripting)
  • Re: WSH Error when running script
    ... You could have one If Then/End If structure for each UserName. ... ' Subroutine to map a drive to a share. ... On Error GoTo 0 ... ' Temporarily suspend normal error handling. ...
    (microsoft.public.windows.server.scripting)
  • Re: adding error checking to code
    ... The statement "On Error GoTo 0" restores normal error handling, ... ' Trap error if folder cannot be created. ...
    (microsoft.public.scripting.vbscript)
  • Re: Manage errors
    ... ' Turn off normal error handling for the statement that might fail. ... objFSO.CopyFile strSource, strDestination ... Restore normal error handling ... On Error GoTo 0 ...
    (microsoft.public.windows.server.scripting)
  • Re: Will not work in Vista
    ... ' Restore normal error handling. ... On Error GoTo 0 ...
    (microsoft.public.scripting.vbscript)

Loading