How to map a drive to the desktop but machine specific not user?

The problem is I need to map a drive (shortcut) to a generic users desktop but only to specific machines in the domain. All the machines are the same build as well as hardware. All machines are XP Pro sp2 and fully patched. I had no problem with mapping by user so the GPs are working etc and I was told by user:  oBdA that you can only map to user specific accounts and not to machine specific accounts. I do believe him but maybe someone has a work around?
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Q_22886300.html
Heres the script which works fine by user&
Set objNet = WScript.CreateObject("WScript.Network")
Set WshShell = CreateObject("WScript.Shell")
DesktopPath = WshShell.SpecialFolders("Desktop")

'map network drive
objNet.MapNetworkDrive "T:", "\\Bst-main\Student\_Reception\Yr R 2007 - 2008", "True"

'create a icon on the desktop
Set link = WshShell.CreateShortcut(DesktopPath & "\Yr R 2007 - 2008.lnk")
link.Description = "User Share Drive"
link.HotKey = "CTRL+ALT+SHIFT+T"
link.IconLocation = "explorer.exe,0"
link.TargetPath = "T:"
link.WindowStyle = 3
link.Save

So many thanks for your help here guys&.(Gals)
AndyinJapanAsked:
Who is Participating?
 
Shift-3Connect With a Mentor Commented:
And I found another mistake.  This should be correct:

'The Distinguished Name of the group containing the computers.
strGroup = "cn=ScriptMap,cn=Users,dc=yourdomain,dc=local"

'Determines the local computername
Set objNet = CreateObject("Wscript.Network")
strComputerName = objNet.ComputerName

Set objGroup = GetObject ("LDAP://" & strGroup)
For Each objComputer in objGroup.Members
      If objComputer.Class = "computer" And objComputer.CN = strComputerName Then
            'map network drive
            objNet.MapNetworkDrive "T:", "\\Bst-main\Student\_Reception\Yr R 2007 - 2008", "True"

            'create a icon on the desktop
            Set WshShell = CreateObject("WScript.Shell")
            DesktopPath = WshShell.SpecialFolders("Desktop")
            Set link = WshShell.CreateShortcut(DesktopPath & "\Yr R 2007 - 2008.lnk")
            link.Description = "User Share Drive"
            link.HotKey = "CTRL+ALT+SHIFT+T"
            link.IconLocation = "explorer.exe,0"
            link.TargetPath = "T:"
            link.WindowStyle = 3
            link.Save
      End If
Next
0
 
Shift-3Commented:
You can put all the desired computers in a security group, then write a logon script which checks to see if the computer it's running on is a member of that group.  If so, it maps the drive.

'The Distinguished Name of the group containing the computers.
strGroup = "cn=ScriptMap,cn=Users,dc=yourdomain,dc=local"

'Determines the local computername
Set objNetwork = CreateObject("Wscript.Network")
strComputerName = objNetwork.ComputerName

Set objGroup = GetObject ("LDAP://" & objGroupList.Item(strGroup))
For Each objComputer in objGroup.Members
            If objComputer.Class = "computer" And objComputer.CN = strComputerName Then
                strGroupMembership = strGroup
            End If
        Next
0
 
Shift-3Commented:
Whoops, hit Submit by accident.  Here's what the full script would look like:

'The Distinguished Name of the group containing the computers.
strGroup = "cn=ScriptMap,cn=Users,dc=yourdomain,dc=local"

'Determines the local computername
Set objNet = CreateObject("Wscript.Network")
strComputerName = objNet.ComputerName

Set objGroup = GetObject ("LDAP://" & objGroupList.Item(strGroup))
For Each objComputer in objGroup.Members
      If objComputer.Class = "computer" And objComputer.CN = strComputerName Then
            'map network drive
            objNet.MapNetworkDrive "T:", "\\Bst-main\Student\_Reception\Yr R 2007 - 2008", "True"

            'create a icon on the desktop
            Set WshShell = CreateObject("WScript.Shell")
            DesktopPath = WshShell.SpecialFolders("Desktop")
            Set link = WshShell.CreateShortcut(DesktopPath & "\Yr R 2007 - 2008.lnk")
            link.Description = "User Share Drive"
            link.HotKey = "CTRL+ALT+SHIFT+T"
            link.IconLocation = "explorer.exe,0"
            link.TargetPath = "T:"
            link.WindowStyle = 3
            link.Save
      End If
Next
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AndyinJapanAuthor Commented:
Hi there Shift-3
Firstly, many thanks for your help on this one (its a bit beyond me....)
Nearly worked just on the client machine there is the following error:
Line 8
Char1
Error: Object required: 'objGroupList'
Code:800A01A8
VB Runtime error

Thanks again Andy :)
0
 
Shift-3Commented:
That was a leftover from a old script of mine.  See my last reply; that revision got rid of it.
0
 
AndyinJapanAuthor Commented:
Hi there Shift-3,
Sorry...it works now but the desktop shortcut doesn't appear......any ideas my good friend?
Many thanks
Andy


'The Distinguished Name of the group containing the computers.
strGroup = "cn=ScriptMap,cn=Users,dc=bst,dc=local"

'Determines the local computername
Set objNet = CreateObject("Wscript.Network")
strComputerName = objNet.ComputerName

Set objGroup = GetObject ("LDAP://" & strGroup)
For Each objComputer in objGroup.Members
      If objComputer.Class = "computer" And objComputer.CN = strComputerName Then
            'map network drive
            objNet.MapNetworkDrive "K:", "\\Bst-main\Student\_Reception\Yr R 2007 - 2008", "True"

            'create a icon on the desktop
            Set WshShell = CreateObject("WScript.Shell")
            DesktopPath = WshShell.SpecialFolders("Desktop")
            Set link = WshShell.CreateShortcut(DesktopPath & "\Yr R 2007 - 2008.lnk")
            link.Description = "User Share Drive"
            link.HotKey = "CTRL+ALT+SHIFT+T"
            link.IconLocation = "explorer.exe,0"
            link.TargetPath = "K:"
            link.WindowStyle = 3
            link.Save
      End If
Next
0
 
Shift-3Commented:
It looks good to me, but you might have to introduce a delay between mapping the drive and creating the shortcut.

Try inserting "Wscript.Sleep 5000" just before the icon-creating section.  If that works, gradually decrease the interval until you find the shortest one that works.
0
 
AndyinJapanAuthor Commented:
Hi there Shift-3
Still didn't get there after all that....any other ideas?
Thanks mate
Andy
0
 
Shift-3Commented:
It appears to be erroring out on the MapNetworkDrive line if the K: drive is already mapped.  This prevents the shortcut portion from running.

To avoid this you need to check if the drive already exists and, if it does, to unmap it.


'The Distinguished Name of the group containing the computers.
strGroup = "cn=ScriptMap,cn=Users,dc=bst,dc=local"

'Determines the local computername
Set objNet = CreateObject("Wscript.Network")
strComputerName = objNet.ComputerName

Set objGroup = GetObject ("LDAP://" & strGroup)

For Each objComputer in objGroup.Members
      If objComputer.Class = "computer" And objComputer.CN = strComputerName Then
        
                  'checks for network drive and unmaps it if it exists
                  Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
                  Set colDrives = objWMIService.ExecQuery("Select * From Win32_NetworkConnection")
                  For Each objDrive in colDrives
                        If UCase(objDrive.LocalName) = "K:" Then
                              objNet.RemoveNetworkDrive "K:", True, True
                        End If
                  Next                  
                  
            'map network drive
            objNet.MapNetworkDrive "K:", "\\nisdep02\downloads", "True"  
                  
                  'create an icon on the desktop
                  Set WshShell = CreateObject("WScript.Shell")
            DesktopPath = WshShell.SpecialFolders("Desktop")
            Set link = WshShell.CreateShortcut(DesktopPath & "\Yr R 2007 - 2008.lnk")
            link.Description = "User Share Drive"
            link.HotKey = "CTRL+ALT+SHIFT+T"
            link.IconLocation = "explorer.exe,0"
            link.TargetPath = "K:"
            link.WindowStyle = 3
            link.Save
            End If
Next
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.