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

    • IBM reveals sub-1nm chip technology, production expected in another 5 years by Pradeep Viswanathan TSMC is now leading the chip manufacturing industry with its 2nm-class process node called N2. Samsung Foundry also has a 2nm-class process node called SF2. TSMC says N2 entered volume production in Q4 2025. Samsung says SF2 started mass production in 2025. Today, IBM announced the world’s first sub-1-nanometer chip technology, marking another major semiconductor research milestone. The new technology is based on a 0.7nm, or 7-angstrom, node and uses a new transistor architecture called “nanostack.” The new design vertically stacks and staggers nanosheet-based transistors so that more components can fit into the same chip area while also improving performance and power efficiency. IBM claims that this new sub-1nm chip can pack nearly 100 billion transistors onto a chip the size of a fingernail. This offers almost twice the density, up to 50 percent higher performance, or 70 percent better energy efficiency when compared to IBM's 2nm node design announced back in 2021. Also, IBM mentioned that this new architecture can deliver 40 percent SRAM scaling. It is important to consider that this announcement from IBM is a research milestone rather than a near-term process node launch. Back in 2021, IBM unveiled the world’s first 2nm chip design, claiming 50 billion transistors on a fingernail-sized chip and major performance and efficiency gains. Five years later, IBM’s 2nm technology has still not entered mainstream commercial production. That is because IBM is no longer a major commercial chip manufacturer. It sold its chip manufacturing business to GlobalFoundries years ago and has since then focused only on semiconductor research, IP development, and partnerships. To productize its 2-nm chip technology, IBM partnered with Japan’s Rapidus, but it has not resulted in anything shipping at scale. IBM says that its new sub-1nm technology can reach production as early as within the next five years. If that happens, it will likely depend on manufacturing partners, advanced EUV tooling, and years of yield improvements.
    • It's funny when thieves accuse other thieves of stealing. Ai companies just blatantly siphoned all the knowledge of the internet without consent and are now selling it with their service... so excuse me if I find this a bit ironic.
  • Recent Achievements

    • Week One Done
      Meta Plast earned a badge
      Week One Done
    • First Post
      kinowa earned a badge
      First Post
    • Rookie
      krychek57 went up a rank
      Rookie
    • Grand Master
      Jaybonaut went up a rank
      Grand Master
    • One Year In
      Philsl earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      454
    2. 2
      +Edouard
      170
    3. 3
      PsYcHoKiLLa
      135
    4. 4
      Michael Scrip
      78
    5. 5
      Xenon
      77
  • Tell a friend

    Love Neowin? Tell a friend!