Translate

2016年10月24日月曜日

【vbs】ダウンロードが終了したらシャットダウンするプログラム(案)

なんとか便とかで数ギガ単位のファイルをダウンロードしなければならず、
ダウンロードが終わるまで帰れない・・・という時のために。
ダウンロードフォルダのサイズを監視して、サイズが更新されていればカウントダウンをリセットするというもの。
ただ、ダウンロードが続いていてもフォルダサイズが更新されないことがある。
要修正かな。

Dim monitorFolder
Dim lastSize
Dim currentSize
Dim shutDownCount
Dim WSH
Dim fso


Call selectFolder

Sub selectFolder()

    Set objShell = WScript.CreateObject("Shell.Application")
    lastSize = 0
    shutDownCount = 10
    Set monitorFolder = objShell.BrowseForFolder(0, "監視するフォルダを選択してください", 0)
    If monitorFolder Is Nothing Then Exit Sub
    Call repeat

End Sub

Sub measureFolder()

    Set fso = CreateObject("Scripting.FileSystemObject")
    currentSize = fso.GetFolder(monitorFolder.Items.Item.Path).Size
    Set WSH = CreateObject("WScript.Shell")
    If currentSize <> lastSize Then
        lastSize = currentSize
        shutDownCount = 10
        Else
        shutDownCount = shutDownCount - 1
    End If

    If shutDownCount = -1 Then
        Call shutdownevent
    Else
        Set WSH = CreateObject("WScript.Shell")
        WSH.Popup "shutdown :" & shutDownCount & " " & lastSize & " / " & currentSize   , 5, "count down", vbInformation

        Call repeat
    End If

End Sub

Sub repeat()

    WScript.Sleep 60000
    Call measureFolder()
    'Range("B3").Value = shutDownCount
    'Application.OnTime Now + TimeValue("00:01:00"), "measureFolder"

End Sub

Sub shutdownevent()

Set ws = WScript.CreateObject("WScript.Shell")
ws.Run "%WINDIR%\system32\shutdown.exe -s -t 60", 0

    Set WSH = Nothing

End Sub

0 件のコメント:

コメントを投稿