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.
tedcbeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

matrixnzCommented:
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

0
RobSampsonCommented:
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

0
tedcbeAuthor Commented:
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
0
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

matrixnzCommented:
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.
0
RobSampsonCommented:
Hi, I have added code to test if the %ALLUSERPROFILE%\Desktop folder is not found, it will use %PUBLIC%\Desktop

Also, to check the Outlook version, I have created an Outlook object, and checked the version.

Regards,

Rob.

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strAllUsersDesktop = objShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%") & "\Desktop\"
If objFSO.FolderExists(strAllUsersDesktop) = False Then strAllUsersDesktop = objShell.ExpandEnvironmentStrings("%PUBLIC%") & "\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
Set objOutlook = CreateObject("Outlook.Application")
Select Case Left(objOutlook.Version,2)
	Case "11"
		objFSO.CopyFile "\\server\share\shortcuts\outlook\Outlook 2003.lnk", strAllUsersDesktop, True
	Case "12"
		objFSO.CopyFile "\\server\share\shortcuts\outlook\Outlook 2007.lnk", strAllUsersDesktop, True
	Case "14"
		objFSO.CopyFile "\\server\share\shortcuts\outlook\Outlook 2010.lnk", strAllUsersDesktop, True
End Select
objOutlook.Quit

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tedcbeAuthor Commented:
Thank you RobSampson. I will test this script today and let you know how it goes.
0
tedcbeAuthor Commented:
Thank you RobSamson
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.