I am running Windows 7 64 bit. When I shut down my computer I have many programs open on the desktop. When I start my computer I want these programs to open automatically. I am aware of SaveMyCache, this requires me to tick boxes every time I shutdown my computer, I want something automatic.
3 Answers
Something that comes close to what you're asking: Enable hibernation in power management and instead of shutting down your PC, use the hibernate option. This does turn off your PC's power and restores your PC to the state you were in when you turned the system off.
Other than that, there's no built-in functionality that does what you are asking. The Windows restart manager was created for situations like this but software needs to support that and this is typically only used when installing new software or when updates are installed.
-
2I just wanted to add, that when your PC needs to reboot to apply some updates or finalize an installation, you will need to shut your PC down instead of hibernating it.– NolonarJul 18, 2014 at 16:22
So I've decided to create this Powershell script.
Version with capturing the process arguments as well.
The actions performed:
- Delete previous file.
- Check the running processes.
- Filter the list by path that contains specific word (Program) which assumes all programs are installed either in Program Files or Program files(x86)
- Get the absolute paths to executables of processes that were found
- Write paths to temp file in temp directory.
- Move temp file to destination directory that is to Startup folder of user.
Pros:
- Written in powershell so the code is native and should work in Windows Vista and above.
- Works.
Cons:
Programs installed in another path - not under program files - will not get picked up in this version. That is of course necessary to avoid starting native Windows processes like explorer.exe and so on. However if you have a path like
D:\Apps
where you also install programs, you can modify the line$_.Path -match "Program"
to
$.Path -match "Program" -or $.Path -match "D:\Apps"
and it will work all the same.
Now the script code:
###############################
# AUTOMATIC STARTUP GENERATOR #
# ASGEN v.1.0 by mnmnc @ 2014 #
###############################
# VARIABLES
# CURRENT PATH
$current = $(pwd).ToString()
# DESTINATION PATH
$destination_path = "$env:userprofile\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\programs.bat"
# MOVING TO TEMP
cd $env:systemroot\Temp
# REMOVING OLD FILE
del $destination_path
# EMPTY ARRAYS
$arr_names = @()
$arr_paths = @()
# FILLING ARRAYS
Get-Process | Where-Object {$_.Path -match "Program" } | foreach { $arr_names += $_.Name; $arr_paths += $_.Path }
# CREATING FILE
for($i = 0; $i -le $arr_names.count -1; $i++)
{
$out = "`"" + $arr_paths[$i] + "`""
write-output $out | out-file "programs.bat" -append -Encoding ascii
}
# INFO
Write-host "`nFolowwing programs will be started on next boot:`n"
cat programs.bat
Write-host "`n"
# MOVING TO STARTUP FOLDER
mv programs.bat "$destination_path"
# RETURNING
cd $current
exit
Simpy copy this code and paste it in the file shutdown.ps1
on your desktop. Save and close this file. Now create a second file shutdown.bat
and put the code
powershell shutdown.ps1
shutdown -s -t 1
in this file. Save and close the bat file. You can now move both files to preferred directory. After that you can click with Right Mouse Button on a bat file and create a shortcut to this file. Then click with Right Mouse Button on a shortcut this time and choose Pin to Start Menu. This will add the shortcut to your Start Menu.
Now every time when you want to close the PC and save the running programs for an automatic startup after boot, you can use this shortcut.
Edit - Including Command Line arguments
Since you would like to save the process command line arguments as well, you have to change the Filling Arrays and Creating file sections to those:
# FILLING ARRAYS
Get-WmiObject Win32_Process | Where-Object { $_.Path -match "Program" } | foreach { $arr_names += $_.Name; $arr_paths += $_.CommandLine; }
# CREATING FILE
for($i = 0; $i -le $arr_names.count -1; $i++)
{
$out = $arr_paths[$i]
write-output $out | out-file "programs.bat" -append -Encoding ascii
}
The change is with using WMI now instead of get-process. Additionally the quotation marks have to be omitted this time.
Notice
In case you have an error when executing the script you probably have incorrect setting for Execution policy for powershell. To change that you have to open powershell console as administrator and type in Set-ExecutionPolicy Unrestricted
and type in Y
when asked to confirm. That's it. Should work fine.
-
This looks great, and I'll be trying this out soon. Will this (Get-Process) capture only the process "D:\path\program.exe", or will it (can it) also capture the process full-command-line or command-line-arguments? Jul 19, 2014 at 1:49
-
@KevinFegan By default this would not capture the command line arguments as those are not a part of Process object as far as I know. However I've extended my answer with Edit and included the code to capturing command line arguments as well. I've tested it on my side and it is working fine. Let me know if this works for you.– mnmncJul 19, 2014 at 9:15
Another option is to pull links to software to start into the 'Startup' folder in the Start menu - it is Slow, but works. It doesn't open the 'previously' open programs though, just a preset set.
Startup
folder (they will be restarted on login)?.bat
file that will be placed in the startup folder of the user. After those actions the script will executeshutdown -s -t 1
and quit. After the boot, all programs that were running will be started again.