Start Windows with previously open programs

6

2

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.

Mowing Bar

Posted 2014-07-18T14:41:50.683

Reputation: 189

3I don't think Windows does something quite like this natively at least. Have you considered either hibernation (programs won't quit) or using the Startup folder (they will be restarted on login)? – a CVn – 2014-07-18T14:48:31.553

1Couple of questions that need to be asked: You want to return completely to the previous state so that opened files within some programs will be also opened in this program after restart, or do you want to simply start previously used programs? The second one can be done if you will be willing to use custom shortcut for a shutdown procedure. The first one is realy realy realy unlikely for most of the programs. Sublime text will open automatically previously used files but that is an exception and rather rare behavior. – mnmnc – 2014-07-18T14:51:08.037

My solution would be to create a script that will perform the shutdown procedure. But firstly it will list all the programs that are running and are started by user account, create a list o paths to those executables and place it in the .bat file that will be placed in the startup folder of the user. After those actions the script will execute shutdown -s -t 1 and quit. After the boot, all programs that were running will be started again. – mnmnc – 2014-07-18T14:53:43.497

@mnmnc I simply want to open the programs not necessarily the files. I have no programming background so how do I use a "custom shortcut for a shutdown procedure"? – Mowing Bar – 2014-07-18T14:59:28.840

@MowingBar Hey. I've created a script just for you. You can see my answer below. The script does just the thing you wanted - saves the list of programs running and starts them after next boot. – mnmnc – 2014-07-18T21:19:36.280

Answers

9

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.

Jeroen Landheer

Posted 2014-07-18T14:41:50.683

Reputation: 380

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. – Nolonar – 2014-07-18T16:22:36.723

2

So I've decided to create this Powershell script.

Github project here.

Version with capturing the process arguments as well.

The actions performed:

  1. Delete previous file.
  2. Check the running processes.
  3. Filter the list by path that contains specific word (Program) which assumes all programs are installed either in Program Files or Program files(x86)
  4. Get the absolute paths to executables of processes that were found
  5. Write paths to temp file in temp directory.
  6. 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.

mnmnc

Posted 2014-07-18T14:41:50.683

Reputation: 3 637

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? – Kevin Fegan – 2014-07-19T01:49:59.577

@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. – mnmnc – 2014-07-19T09:15:23.130

0

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.

Hannu

Posted 2014-07-18T14:41:50.683

Reputation: 4 950