Link to home
Start Free TrialLog in
Avatar of tedcbe
tedcbeFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Script to check and install shortcuts

I need a script that will check the desktop of %allusersprofile% both on Win XP and Win 7 devices for presence of a set of shortcuts and install these shortcuts if they are not present.
I intend to deploy this script using SCCM + GPO.
Any help in this will be greatly appreciated.
Avatar of matrixnz
matrixnz

You could use AutoIT a free scripting product - www.autoitscript.com.  You can then compile the code below to an executable and deploy it.

Example:
#NoTrayIcon
;~ Check to see if the shortcut exists and if not, create it.
If FileExists(@DesktopCommonDir & '\Shortcut.lnk') = 0 Then
  FileCreateShortcut('<Full Path to file name>.exe', @DesktopCommonDir & '\Shortcut.lnk', '<Working Directory>')
EndIf

Open in new window

Hi, this VBScript should be able to be run from SCCM.

Specify strSourceFolder as a folder where you have placed the required shortcuts (and nothing else), and the script will copy the missing shortcuts to the all users desktop.

Regards,

Rob.

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strAllUsersDesktop = objShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%") & "Desktop\"
strSourceFolder = "\\server\share\shortcuts"
For Each objFile In objFSO.GetFolder(strSourceFolder).Files
	If objFSO.FileExists(strAllUsersDesktop & objFile.Name) = False Then
		objFSO.CopyFile objFile.Path, strAllUsersDesktop, True
	End If
Next

Open in new window

Avatar of tedcbe

ASKER

Thanks a lot Matrixnz and RobSamson for your suggestions and apologies for getting back late.

I ended up using RobSamson's code (with the following changes)
strAllUsersDesktop = objShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%") & "\Desktop\"

I just added the \ before Desktop

I need 2 more things and i was wondering if any of you guys might be able to help

1. I need to be able to use this script both on Win XP and Win 7 devices and at the moment it does not work on Win 7 devices (in my tests). I was under the impression that %allusersprofile%\desktop should work but it did not. Is there a way of checking if this is Win Xp or Win 7 and if it is Win 7 then to add the shortcuts to "C:\Users\Public\Desktop"

2. I have also been asked to put the shortcut for Outlook and hence I need to be able to check what version of Office is installed and put the relevant Outlook shortcut in the above location
Its one of the reasons I use AutoIT, the code between Win XP and Win 7 is completely different.

i.e. Win 7 is generally C:\Users\Public\Desktop not C:\ProgramData\Desktop.

You could query
HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Common Desktop
Or use a ShellSpecialFolderConstants to point to the All Users Desktop, although you may need to verify that it works on Windows XP as well.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tedcbe

ASKER

Thank you RobSampson. I will test this script today and let you know how it goes.
Avatar of tedcbe

ASKER

Thank you RobSamson