Re: WSH Error when running script



I am sorry let me explain further what I am wanting is a more dynamic script
based on username. IE

if WSHNetwork.UserName="username" then WSHNetwork.MapNetworkDrive "S:",
"\\server\share"
if WSHNetwork.UserName="username2" then WSHNetwork.MapNetworkDrive "S:",
"\\server2\share"
if WSHNetwork.UserName="username3" then WSHNetwork.MapNetworkDrive "S:",
"\\server3\share"

As you can see different users will map to different servers in my domain
based only on their username. I am not concerned about the error just
overwriting the mapping with the appropriate server mapping. Can this be
done with your example and what lines do I need to duplicate and change
accordingly


"Richard Mueller" wrote:

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: need to modify local group membership via VBscript
    ... Use "On Error GoTo 0" to restore normal error handling. ... domain admin credentials in the script, ...
    (microsoft.public.windows.server.scripting)
  • Re: WSH Error when running script
    ... You could use something similar to below to trap the error raised if drive ... On Error GoTo 0 ... The UserName property of the WSHNetwork object can return ... ' Temporarily suspend normal error handling. ...
    (microsoft.public.windows.server.scripting)
  • Re: need to modify local group membership via VBscript
    ... "On Error GoTo 0" to restore normal error handling. ... Restore normal error handling and clear error condition. ... domain admin credentials in the script, then run the script through the ...
    (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: Code to verify already existing objects in AD
    ... The script is working great and creates all the contacts reading an excel ... Restore normal error handling. ... On Error GoTo 0 ...
    (microsoft.public.scripting.vbscript)