さてさて、嘘をつくつもりはありません。stackoverflowでこれを見て、挑戦的な質問だと思いました。2時間かけてコードを書いてみました。そして、それはここにあります…
以下のステップに従った後、"Start “を押した後に "TaskClose notepad.exe "と入力すると、文書化されていないすべてのメモ帳ファイルをデスクトップに自動保存します。また、chrome.exeを自動終了し、復元設定を保存します。
if条件で他のアプリケーションの設定を追加・削除できます。例えば:
If InStr(SINGLECLOSEAPPS, WScript.arguments(0)) Then
SmartSendKeys strOutput,"bypass","%{F4}"
ElseIf InStr(AUTOCLOSEAPPS, WScript.arguments(0)) Then
SmartSendKeys strOutput,"","%{F4}|%s|{autoname}.txt|%s"
'Example 1: =============================================
ElseIf InStr(WScript.arguments(0), "outlook") Then
SmartSendKeys strOutput,"","%{F4}" 'Activate Alt+4
'========================================================
'Example 2: =============================================
ElseIf InStr(WScript.arguments(0), "notepad") Then 'I know, already in my autoapps
SmartSendKeys strOutput,"","%{F4}|%s|{autosave}.txt" 'Activate Alt+4 + Save File + {AutoSave} = autoincrement filename
'========================================================
Else
SmartSendKeys strOutput,"bypass","%{F4}"
End If
vbs とバッチファイルは以下の手順を実行します:
- 実行ファイルを収集します。
- その後、"Alt+F4 "であろうと、極端な場合には "Alt+F4 "であろうと、ローリングコマンドを実行します
- Alt+F4
- 保存を有効にします
- ファイル名を自動更新します
- アプリケーションを終了します。
ReturnAppList.bat : install in "C:\windowss\system32”
for /f "tokens=10 delims=," %%F in ('tasklist /v /fi "imagename eq %1" /fo csv') do @echo %%~F >>result.txt
TaskClose.bat : install in “C:\windowssystem32”
C:\windows\system32\wscript.exe c:\windows\system32\taskclose.vbs %1
TaskClose.bat : install in “C:\windowss\system32” AND “C:\UsersYourUserName”
Set WshShell = CreateObject("WScript.Shell")
Const SINGLECLOSEAPPS = "chrome.exe|iexplore.exe|firefox.exe"
Dim DEFAULTSAVELOCATION : DEFAULTSAVELOCATION = wshshell.SpecialFolders("Desktop")
Const AUTOCLOSEAPPS = "notepad.exe"
Const WshFinished = 1
Const WshFailed = 2
strCommand = "returnapplist.bat "
Set WshShellExec = WshShell.Exec(strCommand & WScript.Arguments(0))
WScript.sleep 2000
Select Case WshShellExec.Status
Case WshFinished
strOutput = LoadStringFromFile("result.txt")
Case WshFailed
strOutput = LoadStringFromFile("result.txt")
End Select
'SmartSendKeys(application_name_array, bypassclause, additionalcommands)
'========================
If InStr(SINGLECLOSEAPPS, WScript.arguments(0)) Then
SmartSendKeys strOutput,"bypass","%{F4}"
ElseIf InStr(AUTOCLOSEAPPS, WScript.arguments(0)) Then
SmartSendKeys strOutput,"","%{F4}|%s|{autoname}.txt|%s"
Else
SmartSendKeys strOutput,"bypass","%{F4}"
End If
'SmartSendKeys(application_name_array, bypassclause, additionalcommands)
'========================
Function SmartSendkeys(fArr, LoopCount, RollCommands)
Dim x
Dim splt : splt = Split(farr, vbCrLf)
If loopcount = "bypass" Then
x = 0
Else
x = UBound(splt)
End If
a = 0
For s=0 To x
If Len(splt(s)) > 1 Then
Set objShell = WScript.CreateObject("WScript.Shell")
c = 1 : tabs = ""
Success = False
Do Until Success = True
Success = objShell.AppActivate(Trim(splt(s)))
If success <> True Then
If c = 1 Then
tabs = "{TAB}"
Else
tabs = "{TAB " & c & "}"
End If
'wscript.echo "Activating: " & "%" & tabs
WshShell.SendKeys "%" & tabs
WScript.Sleep 5000
c = c + 1
If c = 100 Then
WScript.echo "App not found"
Exit Function
End If
End If
Loop
Dim cmds : cmds = Split(rollcommands, "|")
For Each cm In cmds
If InStr(cm, "{autoname}") Then
Dim file_ext : file_ext = Split(cm, ".")
cm = DEFAULTSAVELOCATION & "autosave" & a & "." & file_ext(1)
a = a + 1
End If
WshShell.SendKeys cm
WScript.sleep 500
Next
End If
Next
End Function
Function LoadStringFromFile(filename)
Const fsoForReading = 1
Const fsoForWriting = 2
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename, fsoForReading)
Dim fulltext : fulltext = f.ReadAll
LoadStringFromFile = fulltext
f.Close
fso.DeleteFile(filename)
End Function
TaskClose.vbs : install in “C:\windowssystem32”
&001
これは、書いていて楽しかったし、実際に答えを見せるよりも、書き終えた時の方が嬉しいよ。では、良い一週間を