Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista Tutorial - Help with Logon script error

Reply
 
Old 06-27-2008   #1 (permalink)
Mike Bailey
Guest


 
 

Help with Logon script error

Below is a logon script that I've basically put together from various
other examples. The intention of the script is to map a set of common
drives for my users. The script should check to see if a drive mapping
already exist, if so, then remove it, then map the drive letter back to
what I want. I kow/think that part of it is an attempt to handle
persistent drive letters in Explorer where even after disconnecting the
drive,it still appears in "My Computer"

When I run the script I get the following error:

Line: 11
Char: 1
Error: object required 'objFSO'

Can anyone help? I'm sure this is soemthing simple, but I have basically
no VBS knowlege

Thanks,
Mike


Here is the scrip:

=====================================================================================
Dim WshNet

'*****************
'MAP COMMON DRIVES
'*****************
'
'Note: U: (User Home directory) is mapped in the user profile in Active
Directory

'G: Drive - FS01\App
'************************
If (objFSO.DriveExists("G:" = True)) Then
objNetwork.RemoveNetworkDrive "G:",True,True
End If

If objFSO.DriveExists("G:") Then
Set objReg =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.DeleteKey HKCU, "Network\" & Left("G:", 1)
Set objReg = Nothing
End If

Set WshNet = WScript.CreateObject("WScript.Network")
WshNet.MapNetworkDrive "G:", "\\fs01\app"
Set WSHNet = Nothing

'S: Drive - Bea2\Users
'************************
If (objFSO.DriveExists("S:" = True)) Then
objNetwork.RemoveNetworkDrive "S:",True,True
End If

If objFSO.DriveExists("S:") Then
Set objReg =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.DeleteKey HKCU, "Network\" & Left("S:", 1)
Set objReg = Nothing
End If

Set WshNet = WScript.CreateObject("WScript.Network")
WshNet.MapNetworkDrive "S:", "\\bea2\users"
Set WSHNet = Nothing

'I: Drive - FS02\Img
'************************
If (objFSO.DriveExists("I:" = True)) Then
objNetwork.RemoveNetworkDrive "I:",True,True
End If

If objFSO.DriveExists("I:") Then
Set objReg =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
Set objReg = Nothing
End If

Set WshNet = WScript.CreateObject("WScript.Network")
WshNet.MapNetworkDrive "I:", "\\fs02\img"
Set WSHNet = Nothing
==================================================================================================

End of Script

My System SpecsSystem Spec
Old 06-27-2008   #2 (permalink)
Richard Mueller [MVP]
Guest


 
 

Re: Help with Logon script error

Mike Bailey wrote:
Quote:

> Below is a logon script that I've basically put together from various
> other examples. The intention of the script is to map a set of common
> drives for my users. The script should check to see if a drive mapping
> already exist, if so, then remove it, then map the drive letter back to
> what I want. I kow/think that part of it is an attempt to handle
> persistent drive letters in Explorer where even after disconnecting the
> drive,it still appears in "My Computer"
>
> When I run the script I get the following error:
>
> Line: 11
> Char: 1
> Error: object required 'objFSO'
>
> Can anyone help? I'm sure this is soemthing simple, but I have basically
> no VBS knowlege
>
> Thanks,
> Mike
>
>
> Here is the scrip:
>
> =====================================================================================
> Dim WshNet
>
> '*****************
> 'MAP COMMON DRIVES
> '*****************
> '
> 'Note: U: (User Home directory) is mapped in the user profile in Active
> Directory
>
> 'G: Drive - FS01\App
> '************************
> If (objFSO.DriveExists("G:" = True)) Then
> objNetwork.RemoveNetworkDrive "G:",True,True
> End If
>
> If objFSO.DriveExists("G:") Then
> Set objReg =
> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
> objReg.DeleteKey HKCU, "Network\" & Left("G:", 1)
> Set objReg = Nothing
> End If
>
> Set WshNet = WScript.CreateObject("WScript.Network")
> WshNet.MapNetworkDrive "G:", "\\fs01\app"
> Set WSHNet = Nothing
>
> 'S: Drive - Bea2\Users
> '************************
> If (objFSO.DriveExists("S:" = True)) Then
> objNetwork.RemoveNetworkDrive "S:",True,True
> End If
>
> If objFSO.DriveExists("S:") Then
> Set objReg =
> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
> objReg.DeleteKey HKCU, "Network\" & Left("S:", 1)
> Set objReg = Nothing
> End If
>
> Set WshNet = WScript.CreateObject("WScript.Network")
> WshNet.MapNetworkDrive "S:", "\\bea2\users"
> Set WSHNet = Nothing
>
> 'I: Drive - FS02\Img
> '************************
> If (objFSO.DriveExists("I:" = True)) Then
> objNetwork.RemoveNetworkDrive "I:",True,True
> End If
>
> If objFSO.DriveExists("I:") Then
> Set objReg =
> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
> objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
> Set objReg = Nothing
> End If
>
> Set WshNet = WScript.CreateObject("WScript.Network")
> WshNet.MapNetworkDrive "I:", "\\fs02\img"
> Set WSHNet = Nothing
> ==================================================================================================
>
> End of Script
I don't know about the registry settings, I've never seen that, but before
using any object reference, such as objFSO, you must bind to the object with
a Set statement. The same error will be raised when you use objNetwork,
because it also not bound. Once the object is bound, there is no need to
repeat that step, you can just reuse the object reference. Don't set the
object to Nothing until you are done. Note that objNetwork and WshNet refer
to the same object. The script could be written as follow (watch for line
wrapping):
======
Option Explicit
Dim objFSO, objNetwork, objReg

'*****************
'MAP COMMON DRIVES
'*****************
'
'Note: U: (User Home directory) is mapped in the user profile in Active
Directory

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objReg =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

'G: Drive - FS01\App
'************************
If (objFSO.DriveExists("G:" = True)) Then
objNetwork.RemoveNetworkDrive "G:", True, True
End If

If objFSO.DriveExists("G:") Then
objReg.DeleteKey HKCU, "Network\" & Left("G:", 1)
End If

objNetwork.MapNetworkDrive "G:", "\\fs01\app"

'S: Drive - Bea2\Users
'************************
If (objFSO.DriveExists("S:" = True)) Then
objNetwork.RemoveNetworkDrive "S:", True, True
End If

If objFSO.DriveExists("S:") Then
objReg.DeleteKey HKCU, "Network\" & Left("S:", 1)
End If

objNetwork.MapNetworkDrive "S:", "\\bea2\users"

'I: Drive - FS02\Img
'************************
If (objFSO.DriveExists("I:" = True)) Then
objNetwork.RemoveNetworkDrive "I:", True, True
End If

If objFSO.DriveExists("I:") Then
objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
End If

objNetwork.MapNetworkDrive "I:", "\\fs02\img"
========
I also added "Option Explicit" and declared all variables in a Dim statement
to make troubleshooting easier. There are other ways to handle persistent
drive mappings, but this will work (as long as the registry setting you
delete makes sense).

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 06-27-2008   #3 (permalink)
ekkehard.horner
Guest


 
 

Re: Help with Logon script error

Mike Bailey schrieb:
Quote:

> Below is a logon script that I've basically put together from various
> other examples. The intention of the script is to map a set of common
> drives for my users. The script should check to see if a drive mapping
> already exist, if so, then remove it, then map the drive letter back to
> what I want. I kow/think that part of it is an attempt to handle
> persistent drive letters in Explorer where even after disconnecting the
> drive,it still appears in "My Computer"
>
> When I run the script I get the following error:
>
> Line: 11
> Char: 1
> Error: object required 'objFSO'
>
> Can anyone help? I'm sure this is soemthing simple, but I have basically
> no VBS knowlege
>
> Thanks,
> Mike
>
>
> Here is the scrip:
>
> =====================================================================================
>
> Dim WshNet
Dim objFSO : Set objFSO = CreateObject( "Scripting.FileSystemObject" )
' now we have the required object
Quote:

>
> '*****************
> 'MAP COMMON DRIVES
> '*****************
> '
> 'Note: U: (User Home directory) is mapped in the user profile in Active
> Directory
>
> 'G: Drive - FS01\App
> '************************
> If (objFSO.DriveExists("G:" = True)) Then
==>
If objFSO.DriveExists( "G:" ) Then

Trying to be extra explicit (comparing a truth value to True, adding
brackets/parentheses) may make things worse by cluttering up the
code. Sending the result of the comparison between "G:" and True
to the .DriveExists method surely wasn't intended.

Quote:

> objNetwork.RemoveNetworkDrive "G:",True,True
> End If
>
> If objFSO.DriveExists("G:") Then
' this is good style
Quote:

> Set objReg =
> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>
> objReg.DeleteKey HKCU, "Network\" & Left("G:", 1)
> Set objReg = Nothing
> End If
>
> Set WshNet = WScript.CreateObject("WScript.Network")
> WshNet.MapNetworkDrive "G:", "\\fs01\app"
> Set WSHNet = Nothing
>
> 'S: Drive - Bea2\Users
> '************************
> If (objFSO.DriveExists("S:" = True)) Then
> objNetwork.RemoveNetworkDrive "S:",True,True
> End If
>
> If objFSO.DriveExists("S:") Then
> Set objReg =
> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>
> objReg.DeleteKey HKCU, "Network\" & Left("S:", 1)
> Set objReg = Nothing
> End If
>
> Set WshNet = WScript.CreateObject("WScript.Network")
> WshNet.MapNetworkDrive "S:", "\\bea2\users"
> Set WSHNet = Nothing
>
> 'I: Drive - FS02\Img
> '************************
> If (objFSO.DriveExists("I:" = True)) Then
> objNetwork.RemoveNetworkDrive "I:",True,True
> End If
>
> If objFSO.DriveExists("I:") Then
> Set objReg =
> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>
> objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
> Set objReg = Nothing
> End If
>
> Set WshNet = WScript.CreateObject("WScript.Network")
> WshNet.MapNetworkDrive "I:", "\\fs02\img"
> Set WSHNet = Nothing
> ==================================================================================================
>
>
> End of Script
My System SpecsSystem Spec
Old 06-30-2008   #4 (permalink)
Mike Bailey
Guest


 
 

Re: Help with Logon script error

Richard Mueller [MVP] wrote:
Quote:

> Mike Bailey wrote:
>
>
Quote:

>>Below is a logon script that I've basically put together from various
>>other examples. The intention of the script is to map a set of common
>>drives for my users. The script should check to see if a drive mapping
>>already exist, if so, then remove it, then map the drive letter back to
>>what I want. I kow/think that part of it is an attempt to handle
>>persistent drive letters in Explorer where even after disconnecting the
>>drive,it still appears in "My Computer"
>>
>>When I run the script I get the following error:
>>
>>Line: 11
>>Char: 1
>>Error: object required 'objFSO'
>>
>>Can anyone help? I'm sure this is soemthing simple, but I have basically
>>no VBS knowlege
>>
>>Thanks,
>>Mike
>>
>>
>>Here is the scrip:
>>
>>=====================================================================================
>>Dim WshNet
>>
>>'*****************
>>'MAP COMMON DRIVES
>>'*****************
>>'
>>'Note: U: (User Home directory) is mapped in the user profile in Active
>>Directory
>>
>>'G: Drive - FS01\App
>>'************************
>>If (objFSO.DriveExists("G:" = True)) Then
>> objNetwork.RemoveNetworkDrive "G:",True,True
>>End If
>>
>>If objFSO.DriveExists("G:") Then
>> Set objReg =
>>GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>> objReg.DeleteKey HKCU, "Network\" & Left("G:", 1)
>> Set objReg = Nothing
>>End If
>>
>>Set WshNet = WScript.CreateObject("WScript.Network")
>> WshNet.MapNetworkDrive "G:", "\\fs01\app"
>>Set WSHNet = Nothing
>>
>>'S: Drive - Bea2\Users
>>'************************
>>If (objFSO.DriveExists("S:" = True)) Then
>> objNetwork.RemoveNetworkDrive "S:",True,True
>>End If
>>
>>If objFSO.DriveExists("S:") Then
>> Set objReg =
>>GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>> objReg.DeleteKey HKCU, "Network\" & Left("S:", 1)
>> Set objReg = Nothing
>>End If
>>
>>Set WshNet = WScript.CreateObject("WScript.Network")
>> WshNet.MapNetworkDrive "S:", "\\bea2\users"
>>Set WSHNet = Nothing
>>
>>'I: Drive - FS02\Img
>>'************************
>>If (objFSO.DriveExists("I:" = True)) Then
>> objNetwork.RemoveNetworkDrive "I:",True,True
>>End If
>>
>>If objFSO.DriveExists("I:") Then
>> Set objReg =
>>GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>> objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
>> Set objReg = Nothing
>>End If
>>
>>Set WshNet = WScript.CreateObject("WScript.Network")
>> WshNet.MapNetworkDrive "I:", "\\fs02\img"
>>Set WSHNet = Nothing
>>==================================================================================================
>>
>>End of Script
>
>
> I don't know about the registry settings, I've never seen that, but before
> using any object reference, such as objFSO, you must bind to the object with
> a Set statement. The same error will be raised when you use objNetwork,
> because it also not bound. Once the object is bound, there is no need to
> repeat that step, you can just reuse the object reference. Don't set the
> object to Nothing until you are done. Note that objNetwork and WshNet refer
> to the same object. The script could be written as follow (watch for line
> wrapping):
> ======
> Option Explicit
> Dim objFSO, objNetwork, objReg
>
> '*****************
> 'MAP COMMON DRIVES
> '*****************
> '
> 'Note: U: (User Home directory) is mapped in the user profile in Active
> Directory
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objNetwork = CreateObject("Wscript.Network")
> Set objReg =
> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>
> 'G: Drive - FS01\App
> '************************
> If (objFSO.DriveExists("G:" = True)) Then
> objNetwork.RemoveNetworkDrive "G:", True, True
> End If
>
> If objFSO.DriveExists("G:") Then
> objReg.DeleteKey HKCU, "Network\" & Left("G:", 1)
> End If
>
> objNetwork.MapNetworkDrive "G:", "\\fs01\app"
>
> 'S: Drive - Bea2\Users
> '************************
> If (objFSO.DriveExists("S:" = True)) Then
> objNetwork.RemoveNetworkDrive "S:", True, True
> End If
>
> If objFSO.DriveExists("S:") Then
> objReg.DeleteKey HKCU, "Network\" & Left("S:", 1)
> End If
>
> objNetwork.MapNetworkDrive "S:", "\\bea2\users"
>
> 'I: Drive - FS02\Img
> '************************
> If (objFSO.DriveExists("I:" = True)) Then
> objNetwork.RemoveNetworkDrive "I:", True, True
> End If
>
> If objFSO.DriveExists("I:") Then
> objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
> End If
>
> objNetwork.MapNetworkDrive "I:", "\\fs02\img"
> ========
> I also added "Option Explicit" and declared all variables in a Dim statement
> to make troubleshooting easier. There are other ways to handle persistent
> drive mappings, but this will work (as long as the registry setting you
> delete makes sense).
>
How would you suggest handling the persistent drive mappings? As I
mentioned, I just got this from other places, so I don't know what's
better or not. I'm open to any suggestions. Ultimate goal - simply map
some drives. I never thought this would be so complicated - the
simplest solution didn't accomodate the persistent drives which opened
up another can of worms. Most script examples I find are way to
"inclusive" and complicatd trying to include every scenerio, messages,
promts, etc, for what I want and need.

Thanks for you help and suggestions,
Mike
My System SpecsSystem Spec
Old 07-01-2008   #5 (permalink)
Richard Mueller [MVP]
Guest


 
 

Re: Help with Logon script error


"Mike Bailey" <mbailey@xxxxxx> wrote in message
news:uu8rmht2IHA.6096@xxxxxx
Quote:

> Richard Mueller [MVP] wrote:
Quote:

>> Mike Bailey wrote:
>>
>>
Quote:

>>>Below is a logon script that I've basically put together from various
>>>other examples. The intention of the script is to map a set of common
>>>drives for my users. The script should check to see if a drive mapping
>>>already exist, if so, then remove it, then map the drive letter back to
>>>what I want. I kow/think that part of it is an attempt to handle
>>>persistent drive letters in Explorer where even after disconnecting the
>>>drive,it still appears in "My Computer"
>>>
>>>When I run the script I get the following error:
>>>
>>>Line: 11
>>>Char: 1
>>>Error: object required 'objFSO'
>>>
>>>Can anyone help? I'm sure this is soemthing simple, but I have basically
>>>no VBS knowlege
>>>
>>>Thanks,
>>>Mike
>>>
>>>
>>>Here is the scrip:
>>>
>>>=====================================================================================
>>>Dim WshNet
>>>
>>>'*****************
>>>'MAP COMMON DRIVES
>>>'*****************
>>>'
>>>'Note: U: (User Home directory) is mapped in the user profile in Active
>>>Directory
>>>
>>>'G: Drive - FS01\App
>>>'************************
>>>If (objFSO.DriveExists("G:" = True)) Then
>>> objNetwork.RemoveNetworkDrive "G:",True,True
>>>End If
>>>
>>>If objFSO.DriveExists("G:") Then
>>> Set objReg =
>>> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>>> objReg.DeleteKey HKCU, "Network\" & Left("G:", 1)
>>> Set objReg = Nothing
>>>End If
>>>
>>>Set WshNet = WScript.CreateObject("WScript.Network")
>>> WshNet.MapNetworkDrive "G:", "\\fs01\app"
>>>Set WSHNet = Nothing
>>>
>>>'S: Drive - Bea2\Users
>>>'************************
>>>If (objFSO.DriveExists("S:" = True)) Then
>>> objNetwork.RemoveNetworkDrive "S:",True,True
>>>End If
>>>
>>>If objFSO.DriveExists("S:") Then
>>> Set objReg =
>>> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>>> objReg.DeleteKey HKCU, "Network\" & Left("S:", 1)
>>> Set objReg = Nothing
>>>End If
>>>
>>>Set WshNet = WScript.CreateObject("WScript.Network")
>>> WshNet.MapNetworkDrive "S:", "\\bea2\users"
>>>Set WSHNet = Nothing
>>>
>>>'I: Drive - FS02\Img
>>>'************************
>>>If (objFSO.DriveExists("I:" = True)) Then
>>> objNetwork.RemoveNetworkDrive "I:",True,True
>>>End If
>>>
>>>If objFSO.DriveExists("I:") Then
>>> Set objReg =
>>> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>>> objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
>>> Set objReg = Nothing
>>>End If
>>>
>>>Set WshNet = WScript.CreateObject("WScript.Network")
>>> WshNet.MapNetworkDrive "I:", "\\fs02\img"
>>>Set WSHNet = Nothing
>>>==================================================================================================
>>>
>>>End of Script
>>
>>
>> I don't know about the registry settings, I've never seen that, but
>> before using any object reference, such as objFSO, you must bind to the
>> object with a Set statement. The same error will be raised when you use
>> objNetwork, because it also not bound. Once the object is bound, there is
>> no need to repeat that step, you can just reuse the object reference.
>> Don't set the object to Nothing until you are done. Note that objNetwork
>> and WshNet refer to the same object. The script could be written as
>> follow (watch for line wrapping):
>> ======
>> Option Explicit
>> Dim objFSO, objNetwork, objReg
>>
>> '*****************
>> 'MAP COMMON DRIVES
>> '*****************
>> '
>> 'Note: U: (User Home directory) is mapped in the user profile in Active
>> Directory
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objNetwork = CreateObject("Wscript.Network")
>> Set objReg =
>> GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
>>
>> 'G: Drive - FS01\App
>> '************************
>> If (objFSO.DriveExists("G:" = True)) Then
>> objNetwork.RemoveNetworkDrive "G:", True, True
>> End If
>>
>> If objFSO.DriveExists("G:") Then
>> objReg.DeleteKey HKCU, "Network\" & Left("G:", 1)
>> End If
>>
>> objNetwork.MapNetworkDrive "G:", "\\fs01\app"
>>
>> 'S: Drive - Bea2\Users
>> '************************
>> If (objFSO.DriveExists("S:" = True)) Then
>> objNetwork.RemoveNetworkDrive "S:", True, True
>> End If
>>
>> If objFSO.DriveExists("S:") Then
>> objReg.DeleteKey HKCU, "Network\" & Left("S:", 1)
>> End If
>>
>> objNetwork.MapNetworkDrive "S:", "\\bea2\users"
>>
>> 'I: Drive - FS02\Img
>> '************************
>> If (objFSO.DriveExists("I:" = True)) Then
>> objNetwork.RemoveNetworkDrive "I:", True, True
>> End If
>>
>> If objFSO.DriveExists("I:") Then
>> objReg.DeleteKey HKCU, "Network\" & Left("I:", 1)
>> End If
>>
>> objNetwork.MapNetworkDrive "I:", "\\fs02\img"
>> ========
>> I also added "Option Explicit" and declared all variables in a Dim
>> statement to make troubleshooting easier. There are other ways to handle
>> persistent drive mappings, but this will work (as long as the registry
>> setting you delete makes sense).
>>
>
> How would you suggest handling the persistent drive mappings? As I
> mentioned, I just got this from other places, so I don't know what's
> better or not. I'm open to any suggestions. Ultimate goal - simply map
> some drives. I never thought this would be so complicated - the simplest
> solution didn't accomodate the persistent drives which opened up another
> can of worms. Most script examples I find are way to "inclusive" and
> complicatd trying to include every scenerio, messages, promts, etc, for
> what I want and need.
>
> Thanks for you help and suggestions,
> Mike
I use error trapping and if the mapping files I use RemoveNetworkDrive with
parameters to remove the persistent feature. Sometimes I do this in a
Function. For example:
==============
Set objNetwork = CreateObject("Wscript.Network")

If (MapDrive("K:", "\\MyServer\MyShare") = False) Then
Call MsgBox("Failed to map drive K:")
End If

Function MapDrive(ByVal strDrive, ByVal strShare)
' Function to map network share to a drive letter.
' If the drive letter specified is already in use, the function
' attempts to remove the existing network connection.
' objNetwork is the Network object, with global scope.
' Returns True if drive mapped, False otherwise.

On Error Resume Next
objNetwork.MapNetworkDrive strDrive, strShare
If (Err.Number <> 0) Then
Err.Clear
' Mapping failed. Attempt to remove existing mapping.
objNetwork.RemoveNetworkDrive strDrive, True, True
' Try again.
objNetwork.MapNetworkDrive strDrive, strShare
If (Err.Number <> 0) Then
' Still failed. May lack permission.
MapDrive = False
Else
' Success on second try.
MapDrive = True
End If
Else
' Success.
MapDrive = True
End If

End Function

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Map network drive via logon script and launchapp.wsf error in scri Vista networking & sharing
Logon script PowerShell
Logon Script Causing Laptops To Hang - Problems in script? VB Script
Logon Script VB Script
Logon Script Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46