Assign Desktop shortcut to Task scheduler

avichandana20000

Cyborg Agent
I have created a "SHUTDOWN" shortcut on desktop.
On clicking, it is shutting down the computer as expected.

Now, i need to play a voice before shutdown.
For that i want to play the wav file from Task scheduler and that "shutdown" shortcut should be used as Trigger to play the file.

I have created the task and assigned the wav file.

But for trigger:

After creating a Task i have chosen "On an event" under Trigger.
But unable to assign the Desktop shortcut here.

Anybody knows how to do that?

End result:
i will click the SHUTDOWN shortcut, it should play the wav file and then begin shutdown process.
Capture.PNG
 

Desmond

Destroy Erase Improve
Staff member
Admin
Why not create a batch file that runs some commandline player like mpv to play the soundtrack and then executing the shutdown command?
 
OP
avichandana20000

avichandana20000

Cyborg Agent
batchfile written:

1)
"C:\Program Files\VideoLAN\VLC\vlc.exe" --qt-start-minimized "G:\VOICE\SHUTDOWN.wav"
start "" "C:\Program Files\S.lnk"

it is executing the wav file in minimised form of vlc but the commandprompt reamins open and the nxt line is not getting executed.

2)
start /min "" "C:\Program Files\Windows Media Player\wmplayer.exe" /play /close "G:\VOICE\SHUTDOWN.wav"
start "" "C:\Program Files\S.lnk"

it is executing the wav file in maximised form of wmplayer and the nxt line is getting executed.
 

Attachments

  • Capture.PNG
    Capture.PNG
    8 KB · Views: 128

Desmond

Destroy Erase Improve
Staff member
Admin
Perhaps it didn't quit the VLC process? Have you tried doing this using mpv?

Also, put `@echo off` in your batch file so that commands do not echo on the terminal.

You might also want to check this out: How to run .BAT files invisibly, without displaying the Command Prompt window
 
Last edited:

patkim

Cyborg Agent
The problems you might encounter are that Windows Media Player has poor command line support and most of the GUI programs run asynchronous when invoked in BAT file i.e. they ignore the /WAIT switch.

I suggest you use Media Player Classic (It’s free and very good) and use the built-in /shutdown switch to initiate system shutdown after the WAV file is played.

Media player classic should get installed at C:\Program Files\MPC-HC as mpc-hc64.exe Notice the space in ‘Program Files’

Put your WAV file in a location where there’s no space in the full path e.g a folder named C:\shutdown and avoid spaces in the WAV file name.

Put the following commands in a plain text file and save it as .VBS

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("""C:\Program Files\MPC-HC\mpc-hc64.exe "" /play /shutdown C:\Temp\shut\sound.wav" , 0, false)

In your Media Player Classic ensure that Repeat Forever is un-ticked i.e. you want the Media Player to stop playing after one iteration and replace C:\Temp\shut\sound.wav with full path of your .WAV file. As mentioned earlier avoid spaces in path name and file name. It’s still possible you but need to escape them again as “”” as already done for C:\Program Files\MPC-HC\mpc-hc64.exe. Also note one space after mpc-hc64.exe to allow the parameters to get accepted.

That’s it. Create a shortcut to this .VBS on desktop or wherever you want and set Run as Admin.

Double click the shortcut to play the .WAV file and after that it will initiate Windows shutdown.

If this does not work, then invoke .VBS as START command in a .BAT file and after that set TIMEOUT command to pause BAT for specified number of seconds that the WAV is expected to run and then include the SHUTDOWN command thereafter. Else SHUTDOWN will not WAIT for previous MPC process to finish as it’s a separate GUI and not a built-in command or a process.

Despite if you have Virtual Machine running then it might halt the Shutdown process and user intervention could be required in those special cases.
 
OP
avichandana20000

avichandana20000

Cyborg Agent
done it with mpv.

mpv starts in a minimised form in task bar and then the shutdown process starts. But a message box appears : You are about to sign out...." with a Close button
 
OP
avichandana20000

avichandana20000

Cyborg Agent
The problems you might encounter are that Windows Media Player has poor command line support and most of the GUI programs run asynchronous when invoked in BAT file i.e. they ignore the /WAIT switch.

I suggest you use Media Player Classic (It’s free and very good) and use the built-in /shutdown switch to initiate system shutdown after the WAV file is played.

Media player classic should get installed at C:\Program Files\MPC-HC as mpc-hc64.exe Notice the space in ‘Program Files’

Put your WAV file in a location where there’s no space in the full path e.g a folder named C:\shutdown and avoid spaces in the WAV file name.

Put the following commands in a plain text file and save it as .VBS

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("""C:\Program Files\MPC-HC\mpc-hc64.exe "" /play /shutdown C:\Temp\shut\sound.wav" , 0, false)

In your Media Player Classic ensure that Repeat Forever is un-ticked i.e. you want the Media Player to stop playing after one iteration and replace C:\Temp\shut\sound.wav with full path of your .WAV file. As mentioned earlier avoid spaces in path name and file name. It’s still possible you but need to escape them again as “”” as already done for C:\Program Files\MPC-HC\mpc-hc64.exe. Also note one space after mpc-hc64.exe to allow the parameters to get accepted.

That’s it. Create a shortcut to this .VBS on desktop or wherever you want and set Run as Admin.

Double click the shortcut to play the .WAV file and after that it will initiate Windows shutdown.

If this does not work, then invoke .VBS as START command in a .BAT file and after that set TIMEOUT command to pause BAT for specified number of seconds that the WAV is expected to run and then include the SHUTDOWN command thereafter. Else SHUTDOWN will not WAIT for previous MPC process to finish as it’s a separate GUI and not a built-in command or a process.

Despite if you have Virtual Machine running then it might halt the Shutdown process and user intervention could be required in those special cases.



" MPC-HC is not under development since 2017. Please switch to something else. "
 

patkim

Cyborg Agent
The reason I suggested MPC is because I know and I have tested that the /SHUTDOWN switch works correctly & unconditionally on Windows 10 1909 as well as 2004. It need not be used as a primary app. Its sole purpose is just to play a single wav file that too invisible and initiated shutdown unconditionally thru supported command line options, which is what you want.

I am not sure about any other software. Also I do not know if such a feature of shutdown after play thru command line is supported by mpv. I think even VLC and MPC-BE both support /SHUTDOWN switch I guess but I have never checked it.

The main point here is that you have to use a software that works on your version of Windows 10 and that supports command line option to shutdown after play and that too unconditional. Not all players support full command line options and features. Experiment further on those lines and instantiate the .VBS directly so that the ‘System is going for shutdown - Close Button” should not appear.

Despite if you face any issues, run the command

Code:
shutdown -s -f -t 1
This command shall forcefully shutdown Windows and with a very narrow timeout of just 1 second so that the message will appear and immediately disappear starting Windows shutdown.
 
Last edited:
OP
avichandana20000

avichandana20000

Cyborg Agent
Thanks patkim...its done.

thanks whitestar for the dwnld link.

i need to make similar for restart ...should i replace the word shutdown with restart ?


The problems you might encounter are that Windows Media Player has poor command line support and most of the GUI programs run asynchronous when invoked in BAT file i.e. they ignore the /WAIT switch.

I suggest you use Media Player Classic (It’s free and very good) and use the built-in /shutdown switch to initiate system shutdown after the WAV file is played.

Media player classic should get installed at C:\Program Files\MPC-HC as mpc-hc64.exe Notice the space in ‘Program Files’

Put your WAV file in a location where there’s no space in the full path e.g a folder named C:\shutdown and avoid spaces in the WAV file name.

Put the following commands in a plain text file and save it as .VBS

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("""C:\Program Files\MPC-HC\mpc-hc64.exe "" /play /shutdown C:\Temp\shut\sound.wav" , 0, false)

In your Media Player Classic ensure that Repeat Forever is un-ticked i.e. you want the Media Player to stop playing after one iteration and replace C:\Temp\shut\sound.wav with full path of your .WAV file. As mentioned earlier avoid spaces in path name and file name. It’s still possible you but need to escape them again as “”” as already done for C:\Program Files\MPC-HC\mpc-hc64.exe. Also note one space after mpc-hc64.exe to allow the parameters to get accepted.

That’s it. Create a shortcut to this .VBS on desktop or wherever you want and set Run as Admin.

Double click the shortcut to play the .WAV file and after that it will initiate Windows shutdown.

If this does not work, then invoke .VBS as START command in a .BAT file and after that set TIMEOUT command to pause BAT for specified number of seconds that the WAV is expected to run and then include the SHUTDOWN command thereafter. Else SHUTDOWN will not WAIT for previous MPC process to finish as it’s a separate GUI and not a built-in command or a process.

Despite if you have Virtual Machine running then it might halt the Shutdown process and user intervention could be required in those special cases.
 

patkim

Cyborg Agent
Run the MPC app. Go to Help --> Command Line Switches and see for yourself if Restart is supported or not!

Use following .VBS for Restart

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("""C:\Program Files\MPC-HC\mpc-hc64.exe "" /play /close C:\Temp\shut\sound.wav" , 0, True)
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\WINDOWS\system32\shutdown.exe  -f -r -t 1"

Use 'True' switch in second line as shown to make it synchronous and make sure to disable Repeat forever or equivalent menu in the GUI upfront once.
 
Last edited:

patkim

Cyborg Agent
If that message is bothering you even for 1 second which is set in timeout then use the command

Code:
Shutdown.exe -f -r -t 0

If in case hyphen is not accepted by Shutdown command on your Windows then use

Code:
Shutdown.exe /f /r /t 0

To know how this command works, invoke it as
Code:
shutdown.exe /?
On command prompt. You will see list of all supported switches.
 

patkim

Cyborg Agent
It should not as the previous command is invoked with 'True' switch to make it synchronous in .VBS
 
Top Bottom