1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Windows】シャットダウン、再起動などのショートカットを作れば終了音を完璧に鳴らせる

Last updated at Posted at 2022-02-24

はじめに

Windowsでシャットダウン、再起動などができるショートカットがあれば便利ですよね。
それらは、こちらを参考にすれば作ることができます。
Windows 10 シャットダウンや再起動するショートカット

Windows Vista以降ではサウンドのプロパティで起動音を変更できなくなっています。
さらにWindows 8以降では終了音、ログオフ音、ログオン音が変更できなくなっています。

レジストリを変更すれば、これらの設定を復活させることができますが、
設定を復活させただけでは、音は鳴りません。

起動音、終了音の復活については、こちらを参照してください。
【Windows】Windows 10、11の音をもっと豊かにするバッチファイル

しかし、このやり方で終了音を復活させると、長い終了音は途中で途切れてしまいます。

そこで、終了音を最後まで鳴らしてからシャットダウンするようにします。
そうすれば、長い終了音も最後まで鳴ってからシャットダウンできると思いました。

その方法として、バッチファイルを作るのが、一番簡単だと思いました。
そしてそのバッチファイルのショートカットを作れば、長い終了音を復活されられると思いました!
(そのショートカットを開いたときだけですが)

バッチファイルの内容

  1. Windows 10 Shutdown Soundを終了します。終了音が2回鳴るのを防ぐためです。
  2. 終了音を鳴らします。
  3. シャットダウン、再起動などをします。

シャットダウン

s.bat
@echo off
chcp 65001 > nul
cd /d %~dp0

rem Windows 10 Shutdown Soundを終了
taskkill /IM "Windows 10 Shutdown Sound.exe"

rem 終了音
WindowsSound SystemExit

rem シャットダウン
shutdown /s /t 0

再起動

r.bat
@echo off
chcp 65001 > nul
cd /d %~dp0

rem Windows 10 Shutdown Soundを終了
taskkill /IM "Windows 10 Shutdown Sound.exe"

rem 終了音
WindowsSound SystemExit

rem 再起動
shutdown /r /t 0

ログオフ

l.bat
@echo off
chcp 65001 > nul
cd /d %~dp0

rem Windows 10 Shutdown Soundを終了
taskkill /IM "Windows 10 Shutdown Sound.exe"

rem 終了音
WindowsSound SystemExit

rem ログオフ
shutdown /l

ごみ箱を空にするバッチファイル

ついでなので、ごみ箱を空にするバッチファイルも作ってみました。
内容は、

  1. 存在するドライブの$Recycle.Binの中のフォルダーの中のファイルとフォルダーを全部削除します。
  2. ごみ箱のアイコンを空にします。
  3. 音を鳴らします。

アイコンを空にする方法があまりスマートなやり方とは言えませんが、ごみ箱を空にできます。

e.bat
@echo off
chcp 65001 > nul
cd /d %~dp0

rem 削除
for /F "delims=" %%i in (Letter.txt) do (
	if exist %%i:\ (
		for /F "delims=" %%j in ('dir /A:DH /B %%i:\$Recycle.Bin') do (
			del /Q %%i:\$Recycle.Bin\%%j\*
			for /D %%k in (%%i:\$Recycle.Bin\%%j\*) do (
				rd /S /Q %%k
			)
		)
	)
)

rem ごみ箱のアイコンを空にする
for /F "delims=" %%i in ('reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\DefaultIcon /v empty') do (
	set empty=%%i
)
if %empty:~13,6%==REG_SZ (
	reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\DefaultIcon /ve /d "%empty:~23%" /f > nul
) else (
	reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\DefaultIcon /ve /t REG_EXPAND_SZ /d "%empty:~30%" /f > nul
)

rem 音を鳴らす
ExplorerSound EmptyRecycleBin

ショートカットを作成するVBScript

このVBScriptを実行すると、デスクトップに8つのショートカットが作成されます。
バッチファイルではショートカットを作成することができないので、VBScriptでショートカットを作成します。
シャットダウン、再起動、ログオフ、ごみ箱を空にするはバッチファイルへのショートカットです。
休止状態、ロックはshutdown.exeへのショートカットです。
スリープはこのVBScriptと同じフォルダーにあるPSTools\psshutdown.exeへのショートカットです。
ユーザーの切り替えはユーザーの切り替えを行うためのSwitchUser.exeへのショートカットです。
32ビットか64ビットで分けています。

CreateShortcut.vbs
Option Explicit

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim cd
cd = objFSO.GetParentFolderName(WScript.ScriptFullName)

Dim shell
Set shell = WScript.CreateObject("WScript.Shell")

dim desktopPath
desktopPath = shell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop")

Dim shortCut
Set shortCut = shell.CreateShortcut(desktopPath & "\ごみ箱を空にする.lnk")
With shortCut
	.TargetPath = objFSO.GetAbsolutePathName("e.bat")
	.WorkingDirectory = cd
	.WindowStyle = 7
	.IconLocation = cd & "\EMPTY_RECYCLE_BIN.ico,0"
	.save
End With
Set shortCut = Nothing

Set shortCut = shell.CreateShortcut(desktopPath & "\ユーザーの切り替え.lnk")
With shortCut
	If shell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") = "AMD64" Then
		.TargetPath = objFSO.GetAbsolutePathName("SwitchUserx64.exe")
	Else
		.TargetPath = objFSO.GetAbsolutePathName("SwitchUser.exe")
	End If
	.WorkingDirectory = cd
	.WindowStyle = 7
	.IconLocation = cd & "\SWITCH_USER.ico,0"
	.save
End With
Set shortCut = Nothing

Set shortCut = shell.CreateShortcut(desktopPath & "\ロック.lnk")
With shortCut
	.TargetPath = objFSO.GetAbsolutePathName("C:\Windows\System32\rundll32.exe")
	.Arguments = "user32.dll,LockWorkStation"
	.WorkingDirectory = "C:\Windows\System32"
	.WindowStyle = 7
	.IconLocation = "%SystemRoot%\System32\shell32.dll,44"
	.save
End With
Set shortCut = Nothing

Set shortCut = shell.CreateShortcut(desktopPath & "\ログオフ.lnk")
With shortCut
	.TargetPath = objFSO.GetAbsolutePathName("l.bat")
	.WorkingDirectory = cd
	.WindowStyle = 7
	.IconLocation = "%SystemRoot%\System32\shell32.dll,44"
	.save
End With
Set shortCut = Nothing

Set shortCut = shell.CreateShortcut(desktopPath & "\休止状態.lnk")
With shortCut
	.TargetPath = objFSO.GetAbsolutePathName("C:\Windows\System32\shutdown.exe")
	.Arguments = "/h"
	.WorkingDirectory = "C:\Windows\System32"
	.WindowStyle = 7
	.IconLocation = cd & "\SUSPEND.ico,0"
	.save
End With
Set shortCut = Nothing

Set shortCut = shell.CreateShortcut(desktopPath & "\スリープ.lnk")
With shortCut
	.TargetPath = objFSO.GetAbsolutePathName("PSTools\psshutdown.exe")
	.Arguments = "/d /t 0 /accepteula"
	.WorkingDirectory = cd & "\PStools"
	.WindowStyle = 7
	.IconLocation = cd & "\SUSPEND.ico,0"
	.save
End With
Set shortCut = Nothing

Set shortCut = shell.CreateShortcut(desktopPath & "\再起動.lnk")
With shortCut
	.TargetPath = objFSO.GetAbsolutePathName("r.bat")
	.WorkingDirectory = cd
	.WindowStyle = 7
	.IconLocation = cd & "\REBOOT.ico,0"
	.save
End With
Set shortCut = Nothing

Set shortCut = shell.CreateShortcut(desktopPath & "\シャットダウン.lnk")
With shortCut
	.TargetPath = objFSO.GetAbsolutePathName("s.bat")
	.WorkingDirectory = cd
	.WindowStyle = 7
	.IconLocation = "%SystemRoot%\System32\shell32.dll,27"
	.save
End With
Set shortCut = Nothing

Set objFSO = Nothing
Set shell = Nothing

ダウンロード

これらはここからダウンロードできます。

インストールしていない場合は、こちらもダウンロードしてください。

psshutdown.exeはこちらからダウンロードできます。

shutdown.zipをダウンロードしたら、適当な場所に展開してください。
PsToolsをダウンロードしたら、shutdown\PSToolsに展開してください。

そして、CreateShortcut.vbsを実行すれば、デスクトップにシャットダウン、再起動などのショートカットが作られます。

アイコンについて

ごみ箱を空にするのアイコンは、Windows XPのshell32.dllから取りました。
ロック、ログオフ、シャットダウンのアイコンは、Windows 10にもあるので、そのまま使いました。
ユーザーの切り替え、休止状態、スリープ、再起動のアイコンは、Linux用のWindows XPのテーマから取りました。
出典: Windows XP icon theme pack - Gnome-look.org

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?