|
Prev: When do I have do define variables with "DIM" ?
Next: What folder does Outlook 2007 use for scripts?
From: Mike Bailey on 27 Jun 2008 14:35 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
From: Richard Mueller [MVP] on 27 Jun 2008 15:05 Mike Bailey wrote: > 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 --
From: ekkehard.horner on 27 Jun 2008 15:15 Mike Bailey schrieb: > 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 > > '***************** > '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. > objNetwork.RemoveNetworkDrive "G:",True,True > End If > > If objFSO.DriveExists("G:") Then ' this is good style > 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
From: Mike Bailey on 30 Jun 2008 13:40 Richard Mueller [MVP] wrote: > Mike Bailey wrote: > > >>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
From: Richard Mueller [MVP] on 1 Jul 2008 12:38
"Mike Bailey" <mbailey(a)beaumontproducts.com> wrote in message news:uu8rmht2IHA.6096(a)TK2MSFTNGP06.phx.gbl... > Richard Mueller [MVP] wrote: >> Mike Bailey wrote: >> >> >>>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 -- |