On the whole, in Windows, if you want to do more than one thing from a single command line command, or a simple shortcut, you should put it in a script. Scripts are easier to test and troubleshoot, they're more extensible, they keep the logic of what's being done easier to read. But sometimes there're too much effort for the job - you really just want some easy things happening in a row. In which case, the "&" command separator can be your friend.
On a Windows command line, you can put instruction1 & instruction2 and they'll just run straight after each other.
cd \ & dir .
... gets you to the root of the drive (cd \) and then shows a directory listing there (dir . )
Of course, this is just running things: there's no error control or data passing happening here. But for compactly doing a few things in order it's tidy (though putting them in a script is still better!).
You can data-pass via piping to files, of course:date /t >c:\temp\today.txt & notepad c:\temp\today.txt
... gives you an editable file in Notepad with today's date in it, for instance
One example that I recently had was where I wanted a simple shortcut icon on the dekstop to lock the console and start the screen saver. Either on its own is easy, putting them together seemed a bit much for a script, so I decided to have an & command line.
Theoretically, this should just have been
cmd /c c:\windows\screensaver_name.scr & Rundll32.exe user32.dll,LockWorkStation,/p>
... except that only gets the screensaver setup window, not the actual screensaver display itself. If I create a shortcut just using the command line
c:\windows\screensaver_name.scr
... that starts the screensaver as a screen saver. So there's an inconsistency between the command line in a command prompt window and the Command Line entry in a shortcut. Gotta love standardization.
There's a way around this: call the shortcut from the command line!
Using:
cmd /c "path_of_shortcut_lnk_file" & Rundll32.exe user32.dll,LockWorkStation
... works nicely, either from a command prompt or from a second shortcut (shortcuts hate running .lnk files directly)
Upshot is that I can now lock the workstation and leave it running the pretty screensaver from a single place. Which looks nice
(It could be practical for something like a machine in a public place, so as to show the organization's branding whenever a machine's not in use, say, without having to wait for the normal screensaver timeout.)
Niall H. , Feb 2024