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

    • RollerCoaster Tycoon 3 and Voidwrought are free on the Epic Games Store by Pulasthi Ariyasinghe PC gamers can now jump in and grab two more games to keep this week, as the Epic Games Store's ever-present giveaway promotion has just gone through another refresh. Replacing last week's Citizen Sleeper and Robobeat offers, the store has brought in RollerCoaster Tycoon 3 Complete Edition and Voidwrought to keep. From the duo, Roller Coaster Tycoon 3: Complete Edition is an enhanced version of the classic title that was originally released in 2004. It comes with enhancements such as widescreen and 1080p resolution support, as well as increased compatibility with modern PC hardware. It also comes bundled with all the extra content from the Soaked! and Wild! expansion packs. "Control park finances, shops, services and staff to succeed in dozens of scenarios," reads the description. "Become a true tycoon and embark on your promising new career, or create your ideal park without money woes in sandbox mode. Satisfy your guests’ needs and keep your park running smoothly to succeed." If management is not your style, Voidwrought lands as a 2D action-platformer featuring hand-drawn cosmic horrors. The title touts tight platforming and close‑quarters combat, all brought together with a strong emphasis on mobility. "Descend below the star-scorched surface and explore the multidimensional depths below," says the studio Powersnake about the game. "Witness the corrupted revelry of the Court, lose yourself in the icy tunnels of the Old Waters, and discover the grim fate of the Abandoned Expedition." The RollerCoaster Tycoon 3 Complete Edition and Voidwrought giveaways are set to run until June 25 on the Epic Games Store, giving PC gamers seven days to claim the latest offer. Once this closes out, new freebies will take their place on the same day as always. Don't forget that mobile gamers can check out the Epic Game Store's weekly giveaways on Android and iOS to grab a freebie there as well.
    • I have a feeling this memory shortage issues are going to linger 6-8 years so until and unless Chinese memory floods the markets we are doomed
    • If you look at the account logs more than likely it will be showing that the request is coming from Valley Nebraska. we have been seeing thousands of these the last day or so.
    • It's requesting a login code as if I was signing into my account on my Windows machine. 
  • Recent Achievements

    • 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
    • Dedicated
      Scoobystu earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      446
    2. 2
      +Edouard
      169
    3. 3
      PsYcHoKiLLa
      133
    4. 4
      Xenon
      77
    5. 5
      Michael Scrip
      75
  • Tell a friend

    Love Neowin? Tell a friend!