This command can be used to add a selected file/program to the autostart, either to registry or the startup dir. The command does not need admin rights as both destinations can be written with user rights.
Autostart Location=Startupdir
Autostart Location=Registry
Command.Windows.Autostart.opusscriptinstall (1.5 KB)
Script Code
// Command.Windows.Autostart
// (c) 2026 Felix.Froemel
// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/endpoints/redirect.php?page=scripts for development information.
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "Command.Windows.Autostart";
initData.version = "1.0";
initData.copyright = "(c) 2026 Felix.Froemel";
initData.url = "https://resource.dopus.com/t/autostart-command/58983";
initData.desc = "";
initData.default_enable = true;
initData.min_version = "13.0";
initData.group = "Command";
}
// Called to add commands to Opus
function OnAddCommands(addCmdData)
{
var cmd = addCmdData.AddCommand();
cmd.name = "Autostart";
cmd.method = "OnAutostart";
cmd.desc = "Add a file/executable to autostart in registry or as ling in startup dir";
cmd.label = "Autostart";
cmd.template = "LOCATION/K[Registry,Startupfolder]";
cmd.hide = false;
cmd.icon = "play";
}
function OnAutostart(scriptCmdData)
{
var args = scriptCmdData.func.args;
var location = args.got_arg.location ? args.location.toLowerCase() : null;
var source = scriptCmdData.func.sourcetab;
var file = null;
if(source.selstats.selfiles > 0)
file = source.selected_files(0);
if(location && file)
{
if(location == "startupfolder")
AutostartStartupDir(file);
else if(location == "registry")
AutostartRegistry(file);
}
}
//Add executable to registry autostart, HKCU does not need admin rights
function AutostartRegistry(exePath)
{
var autoStartPath = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\" + exePath.name;
var shell = new ActiveXObject("WScript.Shell");
var result = shell.RegWrite(autoStartPath, exePath, "REG_SZ");
}
//Add executable to startup folder in user dir
function AutostartStartupDir(exePath)
{
var wsh = WScript.CreateObject("WScript.Shell");
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var shortcutPath = wsh.SpecialFolders("Startup") + "\\" + exePath.name + ".lnk";
// Create the .lnk shortcut
var lnk = wsh.CreateShortcut(shortcutPath);
lnk.TargetPath = exePath;
lnk.Arguments = "";
lnk.WorkingDirectory = fso.GetParentFolderName(exePath);
lnk.Description = "";
lnk.WindowStyle = 1; // 1=normal, 3=maximized, 7=minimized
lnk.IconLocation = exePath + ",0";
lnk.Save();
}