I made this script as I like to watch some of my programs before I go to bed, but most of the time I fall asleep and leave my computer on all night. Or I can't be bothered to shut my computer down at the end. Lazy I know.
Anyhoo, I've made this VBScript where you can drag and drop a bunch of files onto the script and set a shutdown time when it completes. You can also double click the file to build a playlist by hand, though it is much slower.
I figured this would be the best place to share it, so tell me what you think
N.B. supports avi, mp4, mov, wmv, 3gp files only thus far. But its pretty simple to add more (VLC Saved playlists [.xspf, .m3u, .html] do not work however)
N.B. Only tested on Windows XP but should work on all Windows OS
Code: Select all
'By eyehawk78, posted on http://forum.videolan.org/viewtopic.php?f=16&t=70391
Dim oShell, FSO, FileData, vlc_path, video_dir, user, programs
Dim files, seconds
force_shutdown = FALSE 'Set to true to force quit all other applications set to false otherwise
Function SelectFile()
Set file = CreateObject("UserAccounts.CommonDialog")
file.Filter = "Video Files (avi, mp4, mov, wmv, 3gp)|*.avi;*.mp4;*.mov;*.wmv;*.3gp;"
file.FilterIndex = 1
file.InitialDir = video_dir
InitFSO = file.ShowOpen
If InitFSO = True Then
SelectFile = file.FileName
Else
WScript.Quit
End If
End Function
Sub InputError(ErrorString)
Wscript.Echo ErrorString
Wscript.Quit
End Sub
files = ""
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
If Wscript.Arguments.Count > 0 Then
For Each FileData In Wscript.Arguments
Set FileInfo = FSO.GetFile(FileData)
If InStr(FileInfo.Type, ".avi") or InStr(FileInfo.Type, ".mp4") or InStr(FileInfo.Type, ".mov") or InStr(FileInfo.Type, ".wmv") or InStr(FileInfo.Type, ".3gp") Then
files = files & " " & CHR(34) & FileData & CHR(34)
Else
InputError("File " & CHR(34) & FileInfo.Name & CHR(34) & " has an unrecognised file type - Must be of type .avi, .mp4, .mov, .wmv or .3gp")
End If
Next
Else
user = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
video_dir = oShell.ExpandEnvironmentStrings("%VLC_SHUTDOWN_VIDEOS_DIRECTORY%")
'If this if first run, we must save where the default video directory is
If video_dir = "%VLC_SHUTDOWN_VIDEOS_DIRECTORY%" Then
video_dir = InputBox("Please input the directory where your Videos are kept." & vbcrlf & vbNewLine & "E.g. C:\Documents and Settings\User Name\My Documents\My Videos", "First Run", user)
If video_dir <> "" Then
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objVariable = objWMIService.Get("Win32_Environment").SpawnInstance_
objVariable.Name = "VLC_SHUTDOWN_VIDEOS_DIRECTORY"
objVariable.UserName = "<System>"
objVariable.VariableValue = video_dir
objVariable.Put_
Else
WScript.Quit
End If
End If
answer = 6
'Loop while user wishes to add more files to playlist
Do While answer = 6
files = files & " " & CHR(34) & SelectFile() & CHR(34)
answer = MsgBox("Would you like to add another file to the playlist?", 3, "Continue?")
Loop
If answer = 2 Then
WScript.Quit
End If
End If
'If this if first run, we must save where the default VLC directory is
programs = oShell.ExpandEnvironmentStrings("%PROGRAMFILES%")
vlc_path = oShell.ExpandEnvironmentStrings("%VLC_SHUTDOWN_VLC_LOCATION%")
If vlc_path = "%VLC_SHUTDOWN_VLC_LOCATION%" Then
vlc_path = InputBox("Please input the directory where VLC program file is kept." & vbcrlf & vbNewLine & "E.g. C:\Program Files\VideoLAN\VLC", "First Run", programs)
If vlc_path <> "" Then
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objVariable = objWMIService.Get("Win32_Environment").SpawnInstance_
objVariable.Name = "VLC_SHUTDOWN_VLC_LOCATION"
objVariable.UserName = "<System>"
objVariable.VariableValue = vlc_path
objVariable.Put_
Else
WScript.Quit
End If
End If
vlc_path = CHR(34) & vlc_path & "\vlc.exe" & CHR(34) 'VLC directory location
seconds = InputBox("Please enter the number of seconds the system should delay before commencing shutdown" & vbNewLine & vbNewLine & "You will be able to abort the shutdown during this time", "Enter Number of Seconds", "10")
If seconds <> "" Then
If IsNumeric(seconds) And seconds > 0 Then
oShell.Run vlc_path & " " & files & " vlc://quit", 1, TRUE
For i = Round(seconds) To 0 Step -1
intRet = oShell.Popup("Cancel the shutdown" & vbNewLine & vbNewLine & "Shutdown down in: "& i, 1, "Cancel Shutdown?", 4 + 32)
If intRet = 6 Then
'Shutdown aborted
oShell.Run "shutdown -a"
oShell.Popup "Shutdown Aborted", , "Aborted", 0 + 64
Wscript.Quit
Elseif intRet = 7 Then
Exit For
End If
Next
'Shutdown now
If force_shutdown Then
oShell.Run "shutdown -s -f -t 0"
Else
oShell.Run "shutdown -s -t 0"
End If
Wscript.Quit
Else
InputError("Input not a number or negative")
End If
End If
Wscript.Quit
Note: Set line 6 to TRUE to force all other applications to quit before shutdown
Tell me what you think?