3

How does one add entries to the Windows 7 start menu for All Users programatically? For example I might want to add the folder MyApps containing a shortcut to myapp.exe and a URL for www.myapp.com.

Ideally I'd like to do this in a batch file but I'll take VBScript or PowerShell as well please.

1
  • 2
    Keep in mind that your program will have to run with elevated permissions to write to those folders.
    – Zoredache
    Feb 14, 2012 at 17:28

2 Answers 2

2

To add entries to the All Programs portion, merely include a shortcut under the folder %AllUserProfile%\Microsoft\Start Menu\Programs.

You can use the SpecialFolder object in VBScript.

Not sure how to do it in Powershell, but this is it in Javascript:

var shell = WScript.CreateObject("WScript.Shell");
var allUserProfilePath = shell.SpecialFolders("CommonPrograms");
var myShortcut = shell.CreateShortcut(allUserProfilePath + "\\myShortcut.lnk");
myShortcut.TargetPath = "c:\\My Programs Path";
myShortcut.WorkingDirectory = "c:\\Blah";
myShortcut.WindowStyle = 4;
myShortcut.Save();

The translation to VB is straight forward

Dim shell 
Set shell = WScript.CreateObject("WScript.Shell")
Dim allUserProfilePath 
Set allUserProfilePath = shell.SpecialFolders("CommonPrograms")
Dim myShortcut 
Set myShortcut = shell.CreateShortcut(allUserProfilePath + "\myShortcut.lnk")
myShortcut.TargetPath = "c:\My Programs Path"
myShortcut.WorkingDirectory = "c:\Blah"
myShortcut.WindowStyle = 4
myShortcut.Save()
1

There are functions in VB and PS to target system folders like the All Users Desktop, All Users Start Menu, etc.

In VBscript you'll want to use SpecialFolders and in PowerShell use Environment Variables.

The following is a snip of code I use to call a function DeleteFile, and pass it the location of a file on the AllUsersDesktop:

DeleteFile (objShell.SpecialFolders ("AllUsersDesktop") & "\Microsoft Word 2010.lnk")

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .