View Single Post
Old 06-30-2008   #4 (permalink)
Mike Bailey


 
 

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