Thursday, 11 August 2011

VBScript to pin shortcut to StartMenu

You can use it as a package's program in SCCM to deploy a shortcut and pin it to the Start Menu.
The script copy the file to the user's desktop. The script also checks if the user has a roaming profile.

If you are going to deploy via SCCM, make sure you set it to run as the user and the shortcut and the script are in the same folder.

Set WshShell = Wscript.CreateObject("WScript.Shell")
profile = WshShell.ExpandEnvironmentStrings("%USERPROFILE%")
username = WshShell.ExpandEnvironmentStrings("%USERNAME%")

Call CopyFile

Sub CopyFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
sFile = "filename.lnk"
sFolder = profile & "\Desktop\"
sRoam = "PathToWhereTheProfilesAreStored" & username & "\Desktop\"

if(objFSO.FolderExists(sRoam)) Then
objFSO.CopyFile sFile, sRoam, True
objFSO.CopyFile sFile, sFolder, True
Call Pin

else
objFSO.CopyFile sFile, sFolder, True
Call Pin
End If

End Sub

Sub Pin

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(profile & "\Desktop")
Set objFolderItem = objFolder.ParseName("filename.lnk")
objFolderItem.InvokeVerb("P&in to Start Menu")

End Sub

No comments:

Post a Comment