On Mon, 14 Dec 2009 23:16:37 +0100, "Pegasus [MVP]" <> wrote:
>
>
>"Kim K" <> schrieb im Newsbeitrag
>news:92DBA312-5CEB-4195-9EA9-...
>> Let me stsart off by apologizing if I am posting in the wrong place!
>>
>> I have a server 2003 with many drives shared to certain groups, the groups
>> have a bat file set to attach this drive upon start up. Occasionally the
>> drive fails to launch but upon reboot will grab it. Why does this happen
>> and
>> how can I help to correct the problem so that it minimizes my issue?
>>
>> Thanks!
The batch file can fail to run for various reasons. For example the user has
unplugged the network cable or there is a Wi-Fi issue. Actually the batch file
may start but fail after a few lines. I wrote the following script to help with
this. The basic principal is to allow Persistent Mappings which will remain in
place when the script fails.
I also think it will be faster than deleting and recreating the drive mapping in
most cases.
<script>
'Copyright D J Mills,
www.djmills.co.uk 2009
'Script to map the network drives for staff.
'It first checks to see if the drive is already mapped to the correct UNC.
'If it is it leaves it alone. If not it deletes the mapping
'Finally it adds in the correct mapping. This picks up any situation where the
mapping
'did not exist in the first place.
'Using a persistent connection resolves the issue where the user logs on but the
script does not run.
Dim objNetwork
Set objNetwork = WScript.CreateObject("WScript.Network")
Dim colDrives
Set colDrives = objNetwork.EnumNetworkDrives
'On error resume next
'Specify the drive mappings required in a list of calls as below.
Call ReMapDrive("G:","\\Domain\storage\Sims",colDrives)
Call ReMapDrive("J:","\\Domain\storage\Public",colDrive s)
Call ReMapDrive("N:","\\Domain\storage",colDrives)
Call ReMapDrive("S:","\\Domain\storage\Staff",colDrives )
Call ReMapDrive("T:","\\Domain\storage\Departments",col Drives)
Call ReMapDrive("X:","\\Domain\storage\Shared",colDrive s)
Sub ReMapDrive(strDrive,strUNC,colDrives)
'strDrive = Drive letter and ":" e.g. "X:"
'strUNC = UNC to map, e.g. \\AD\STORAGE\SETUP
'colDrives = collection of existing mapped drives from EnumNetworkDrives
Dim bForce, bUpdateProfile
bforce = True
bUpdateProfile = True
'msgbox strDrive & " -> " & strUNC
'msgbox colDrives.Count
For i = 0 to (colDrives.Count-1) Step 2
If colDrives.Item(i) = strDrive Then 'Is this the requested
drive?
'msgbox strDrive & "->" & colDrives.Item(i+1) & ">>>" & strUNC
If colDrives.Item(i+1) = strUNC Then 'Is it correctly mapped
Exit Sub
Else
'msgbox "Remove Mapping " & colDrives.Item(i)
objNetwork.RemoveNetworkDrive colDrives.Item(i),bForce,bUpdateProfile
'msgbox "Remove Mapping " & colDrives.Item(i)
End If
End If
Next
'We either did not find the drive or found it was incorrect and removed it
'So map it correctly as requested.
objNetwork.MapNetworkDrive strDrive, strUNC, "True"
End Sub
</script>
>
>Your first step should be to ascertain that the batch file really failed to
>launch. You can do it by adding just one line to it, e.g. like so:
>@echo off
>echo %date% %time% %UserName% %Userdomain% >> "%temp%\logon.txt"
>[Your own code goes here]
>
>Next time someone complains that his shares failed to materialise, examing
>the log file. To ensure that you capture both domain and local logon events,
>place the above lines also into the file c:\documents and settings\all
>users\start menu\programs\startup\netlogon.bat.
--
Dave Mills
There are 10 types of people, those that understand binary and those that don't.