Adding a Group Membership Based Shortcut to a Windows Desktop Upon Login

(That’s a wordy title, isn’t it?)

Had an issue with a client who needed to drop a shortcut to a Remote Desktop connection on certain desktops based upon their membership in a group.

A little vbscripting, and we got it done. It’s pretty simple. (You can cut and paste the script below. Change the variables to suit your environment. Word wrapping on the screen shouldn’t carry over to your editing tool of choice — mine is TextPad.)

Option Explicit
‘initialize our variables

Dim objUser, CurrentUser
Dim strGroup
Dim wShell
Dim strDesktop, objFSO
Dim link, GroupName

‘ Init our objects
Set wShell = CreateObject(“WScript.Shell”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”)

Set objUser = CreateObject(“ADSystemInfo”)
Set CurrentUser = GetObject(“LDAP://” & objUser.UserName)

‘This is the magic… our group membership
strGroup = LCase(Join(CurrentUser.MemberOf))

‘ logic testing
If InStr(strGroup, lcase(GroupName)) Then

‘ get the desktop folder path. this works for all locations
‘ redirected folders, etc.

strDesktop = WShell.SpecialFolders(“Desktop”)

‘ now we create our Shortcut object, and give it a name
Set link = wShell.CreateShortcut(strDesktop & “\Connect to TermServer.lnk”)

‘ set the location where you store the file on the server
link.TargetPath = “\\fileserver\path\server.rdp”

‘ and we have to save it to make it stick.
link.Save

End If

WScript.Quit

Easy peasy.

So then, I add the script to a domain level Group Policy object I have called, logically enough, “Login Scripts” and it runs on each login, making sure our little icon is where it belongs.