Mapping network drives and placing shorcuts of them


Recommended Posts

Hi there,

i've made a script wich maps the users homedir and places a shortcut on the desktop.

I've put the network drive icon in the script and tested it.

The funny thing is the first time the script runs it just runs perfect, but when u press F5, the icon network drive icon dissapears and when u click the icon wich appears instead u will get the "open program with" pop up screen..

Here is the code:

Option Explicit

Dim objNetwork, objUser, CurrentUser

Dim strGroup, strDesktopFolder

Dim objshell, objshortcut

'Initialise Groups with Const

Const test_Group = "cn=testgroep"

Const iedereen_Group= "cn=iedereen"

' Create objects and extract strGroup values

Set objNetwork = CreateObject("WScript.Network")

Set objUser = CreateObject("ADSystemInfo")

Set CurrentUser = GetObject("LDAP://" & objUser.UserName)

strGroup = LCase(Join(CurrentUser.MemberOf))

'*************Networkmapping shortcuts*************

'Datainc\data snelkoppeling

Set objShell = WScript.CreateObject("WScript.Shell")

strDesktopFolder = objShell.SpecialFolders("allusersDesktop")

Set objShortCut = objShell.CreateShortcut(strDesktopFolder & _

"\k:.lnk")

objShortCut.TargetPath = chr(34) & "\\servername\data" & chr(34)

ObjShortCut.IconLocation = "C:\windows\system32\shell32.dll, 9"

objShortCut.Save

'homedrive snelkoppeling

Set objShell = WScript.CreateObject("WScript.Shell")

strDesktopFolder = objShell.SpecialFolders("allusersDesktop")

Set objShortCut = objShell.CreateShortcut(strDesktopFolder & _

"\J:.lnk")

objShortCut.TargetPath = "\\servername\users\"_

& objNetwork.UserName

ObjShortCut.IconLocation = "C:\windows\system32\shell32.dll, 9"

objShortCut.Save

Can someone please tell me what i am doing wrong?

For the home drive, you'd really have a simpler time with a user logon script and a two line batch file. First, create the shortcut to K:\ with Explorer, and save it to a publicly accessible network share. Then run a script like

net use K: "\\server\Users\%username%" /persistent:yes

copy "\\server\IT\Public Desktop\Home.lnk" "%userprofile%\Desktop\Home.lnk"

Note that if you use actual "Home" drives as specified in the account page in Active Directory Users and Computers, your Vista computers will hang and pause at every turn if they're not attached to the network as in the common case of the laptop (the XP ones will do the same, but not as often). Running the "net use" bits and leaving the "Home" drive set to local will avoid that, while the %username% variable will make sure that the psuedo-home drive goes to the right place.

If you want to reassign the Desktop or My Documents to a network share, use Group Policy. If you use roaming profiles, I'd highly recommend doing that, as it prevents those folders from being copied around at each logon/logoff, and thus speeds things up a ton. Offline files is a nifty feature to use with this as well, but it can be unstable at times.

Also, make sure you use TEST groups in Active Directory when going through all of this. Cleaning up after redirecting the Documents folders incorrectly can be a real pain. :pinch:

Personally, if I had shortcuts to create on the client, I would copy them over from a server share (e.g., \\server\shortcuts\kdrive.lnk) if required (just add a check to see if the file exists first before copying). Never tried it your way using the CreateShortcut function. Nonetheless, I guess if it's supported, it should work.

Anyway, I've had a quick squiz of your code, I don't think these lines are valid because windows filenames cannot have ":" characters in them, so you might want to fix that up? Maybe that's causing you grief...

Set objShortCut = objShell.CreateShortcut(strDesktopFolder & "\k:.lnk")
...
Set objShortCut = objShell.CreateShortcut(strDesktopFolder & "\J:.lnk")

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Apart from a few very specific hiccups, Windows 11 has been good for me. Rock solid and stable. Unpopular opinion, I know, but it's mine.
    • No. Windows 8 had little to no spywhare, is actually faster than 7 but it has the dreaded start screen, nothing that you could not fix with start8. Windows ME crashed often, but was shotlived and replaced by XP, which is a much better windows in itself.
    • Windows 8 was uninspiring but it was fine / worked. It was just overshadowed by how great Windows 7 was. Windows ME seem to be just unstable for most people - I was using Windows 2000, which was far superior. The two best versions are Windows 7 and 2000
    • I don't think ME was that bad. The stability issues were mostly caused by drivers. This was when the switch from vxd to wdm was happening. The other complaint was not being able to shut down into DOS anymore which was silly with XP right around the corner.
    • As much as I hated Windows 8, although I never used it personally on any of my own machines, I think Windows Me was hands down the worst OS from MS. I have Windows 11 on 2 unsupported machines and haven't had any issues and I actually kind of like it. Still hate how slow Windows updates are though.
  • Recent Achievements

    • Rookie
      +ChiefOfNeo went up a rank
      Rookie
    • One Month Later
      Tom Schmidt earned a badge
      One Month Later
    • Week One Done
      Tom Schmidt earned a badge
      Week One Done
    • One Year In
      Tom Schmidt earned a badge
      One Year In
    • One Month Later
      JimErn earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      453
    2. 2
      +Edouard
      176
    3. 3
      PsYcHoKiLLa
      122
    4. 4
      Michael Scrip
      81
    5. 5
      Xenon
      75
  • Tell a friend

    Love Neowin? Tell a friend!