Re: WSH Error when running script
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 24 May 2006 17:57:25 -0500
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
.
- Follow-Ups:
- Re: WSH Error when running script
- From: James Robertson
- Re: WSH Error when running script
- References:
- Re: WSH Error when running script
- From: Richard Mueller
- Re: WSH Error when running script
- Prev by Date: Re: What's the difference between...?
- Next by Date: Re: WSH Error when running script
- Previous by thread: Re: WSH Error when running script
- Next by thread: Re: WSH Error when running script
- Index(es):
Relevant Pages
|
Loading