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

    • I have a TV, but it is not used for normal linear TV, only streaming and it is not a Samsung and the best bit is, I don;'t and never have had a Instagram account. The only thing I have to do with Meta is Faceache and I only keep that just for the messaging part.
    • But building your own.. what? You can't build anything like the Steam Machine yourself. Even trying to get close costs a good deal more. Even just the CPU cooler in their price comparison is as big as the entire Steam Machine. If you want a regular gaming PC, then by all means, build that. If you want a a small console-like PC for the living room that is good for gaming, I'm not sure what else is a better deal. In the GN review, they only mentioned a small form factor Dell, which is like twice the size and hundreds of dollars more expensive.
    • Those are some popular multiplayer games. But hardly "all". Just those that don't work on Linux currently due to specific anti-cheat implementations. I think it's also fair to point out the literally thousands of games that don't work on the PS5. And it's not locked at 1080p. That's the default, which you can change.
    • Ubuntu Livepatch arrives on Arm64 to eliminate system reboots for kernel updates by Paul Hill Canonical has just announced that its Livepatch service now supports computers with Arm64 processors. For those who are not familiar, Livepatch allows users to apply important kernel updates without any service interruption or rebooting. While home users will benefit from this, it’s even more important for critical machines that absolutely should not be going offline at all. The feature is available as part of Ubuntu Core 26 for Arm64 and Ubuntu Core 20 and onwards for AMD64. According to Canonical, this will improve the security of systems that aren’t security-maintained daily or weekly, and it helps organizations work towards Cyber Resilience Act (CRA) compliance. If you are familiar with Ubuntu, you probably know that most packages can be updated without having to restart the system. There is one big exception to this, and that’s the kernel; it typically requires you to reload the system to boot into the new kernel. With Livepatch, Canonical has done something so that you don’t need to restart to begin using the new kernel. Aside from Ubuntu Core 26, users with Arm64 chips running Ubuntu 26.04 LTS can also use Livepatch. If you want to learn more about Livepatch, check out its product page. There, you can also find a button to join Ubuntu Pro (it’s free for several home devices) so that you can enable Livepatch. By linking your computer to Ubuntu Pro, you will also extend the life of your Ubuntu install from five years to ten years. If you are running Ubuntu, let us know in the comments if you have been looking forward to this feature on your ARM-based computer. If you’ve had a compatible AMD64 machine for a while and never used this feature, let us know why in the comments!
  • Recent Achievements

    • One Month Later
      nates earned a badge
      One Month Later
    • Week One Done
      Almohandis earned a badge
      Week One Done
    • Rookie
      dorf went up a rank
      Rookie
    • First Post
      mike_rumble earned a badge
      First Post
    • Dedicated
      tuben earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      497
    2. 2
      +Edouard
      205
    3. 3
      PsYcHoKiLLa
      94
    4. 4
      Michael Scrip
      89
    5. 5
      neufuse
      71
  • Tell a friend

    Love Neowin? Tell a friend!