As I came to manually create a registry value for a script I wanted to run at logon, I thought that I may as well write a script that would ass the item to save people having to remember where to create the entries. It then morphed into something that would list or remove entries too, depending on the command line parameters specified.
The script is available here and can be run in a number of different ways, e.g.:
- Show all existing autorun entries in the registry for the current user (if -registry is not specified then the file system will be used):
& "C:\Scripts\Autorun.ps1" -list -registry
- Delete an existing autorun entry for the current user that runs calc.exe either by the name of the entry (the shortcut name or registry value name) or by regular expression matching on the command run:
& "C:\Scripts\Autorun.ps1" -name "Calculator" -remove
& "C:\Scripts\Autorun.ps1" -run Calc.* -remove
- Add a new autorun entry to the file system that runs calc.exe for the current user:
& "C:\Scripts\Autorun.ps1" -name "Calculator" -run "calc.exe" -description "Calculator"
The -allusers flag can be used with any of the above to make them operate for all users but the user running the script must have administrative rights.
When creating an autorun item in the file system, the icon for the shortcut can be specified via the -icon option.
Deletions will prompt for confirmation unless you specify -Confirm:$false and it will also prompt for confirmation when creating a new entry if the name of the entry already exists.
Specifying -verify will generate an error if the executable does not exist when creating a new entry.
If you are on a 64 bit system then you can specify the -wow6432node option when using -registry to work in the wow6432node area of the registry.