I had a working script for Windows XP clients, distributed via group policy from Windows Server 2003 PDC.
This is the main part of the script:
Function ggMapNetworkDrive(fDriveLetter, fShareName, fDrives, fWSHNet)
'Map a network drive
Dim lExist
lExist = -1
For i = 0 to fDrives.Count - 1 Step 2
If fDrives.Item(i) = fDriveLetter Then
lExist = i
End If
Next
If lExist = -1 Then
'no drive, map us a drive
fWSHNet.MapNetworkDrive fDriveLetter, fShareName
Else
If fDrives.Item(lExist+1) = fShareName Then
'do nothing, mapped to right point
Else
'is mapped somewhere else; remove then map then add again
fWSHNet.RemoveNetworkDrive fDriveLetter, False, True
fWSHNet.MapNetworkDrive fDriveLetter, fShareName
End If
End If
End Function
How to do the above in Windows 7?
EDIT: Error message...
Script: \\full-path-to-script\logon.vbs
Line: (line containing 'fWSHNet.MapNetworkDrive fDriveLetter, fShareName')
Char: 2
Error: The network path was not found
Code: 80070035
Source: WSHNetwork.MapNetworkDrive
After further inspection I can see something is wrong with networking, here are the symptoms: pinging and address resolution works, access to all computers on the same segment works as expected, but only access to PDC (windows 2003) is not working as expected (as experienced from win XP clients).
EDIT2:
I made a change for MapNetworkDrive to map to FQDN and it allowed the script to run. Still access to \server without the domain is not restored yet.
I would recommend looking at Group Policy Preferences for mapped network drives in Windows 7. To support Group Policy Preferences on Windows XP and Windows Vista you will need to install the Group Policy Preferences Client-Side Extensions on the clients - you can do this through WSUS if you have that.
The feature was added for Windows Server 2008 but you don't need a WS08 domain or DC to use it, just the Remote Server Administration Tools pack for Windows 7 or Windows Vista SP1. The Group Policy Management console's Policy Object Editor in RSAT then supports Preferences as well as Policies.