'Call this file with an argument representing the folder you want to clean 'foldersToSkip defines the folders not to delete, seperate items by comma foldersToSkip = Array("Admin") For Each argument In WScript.Arguments emptyFolder(argument) Next Function emptyFolder(folderToEmpty) On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Set folder = fso.GetFolder(folderToEmpty) 'clean all subfolders except the once defined in foldersToSkip For Each subfolder In folder.SubFolders deleteThisFolder = True For Each skipFolder In foldersToSkip If subfolder.Name = skipFolder Then deleteThisFolder = False Next If deleteThisFolder = True Then subfolder.Delete Next 'clean all remaining files For Each file In folder.files file.Delete Next End Function
Do watchFolder(objFSO.GetFolder(folderToWatch)) WScript.Sleep(pollInterval) Loop Sub watchFolder(Folder) processRunning = 0 For Each Process in objWMIService.InstancesOf("Win32_Process") If Process.Name = "process.exe" Then processRunning = 1 End If Next If Folder.Files.Count = 0 And processRunning = 1 Then killProccess("'process.exe'") ElseIf Folder.Files.Count > 0 And processRunning = 0 Then wshell.run """C:\Program Files\some\program.exe""" End If End Sub Sub killProccess(process) Set colProcessbyName = objWMIService.ExecQuery("Select * from Win32_Process Where Name = " & process) For Each objProcess in colProcessbyName strProcessID = objProcess.ProcessId Next Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" & strProcessID) For Each objProcess in colProcessList objProcess.Terminate() Next End Sub
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim strSubject As String strSubject = Item.Subject If Len(strSubject) = 0 Then Prompt$ = "Subject is Empty. Are you sure you want to send the Mail?" If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then Cancel = True End If End If End Sub
tasklist /FI "IMAGENAME eq some.exe" 2>NUL | find /I /N "some.exe">NUL REM start some.exe if not started, kill if started. Using errorlevel as conditional if "%ERRORLEVEL%"=="0" (taskkill /F /im some.exe) else (start /min some.exe)
Set WshShell = CreateObject("WScript.Shell") regkey="HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable" return = MsgBox("Click Yes to enable proxy and default LAN", 3) If return = 6 Then WshShell.RegWrite regkey, 1, "REG_DWORD" WshShell.run "netsh interface set interface name=""Local Area Connection"" admin=ENABLED" WshShell.run "netsh interface set interface name=""Local Area Connection 2"" admin=DISABLED" ElseIf return = 7 Then WshShell.RegWrite regkey, 0, "REG_DWORD" WshShell.run "netsh interface set interface name=""Local Area Connection"" admin=DISABLED" WshShell.run "netsh interface set interface name=""Local Area Connection 2"" admin=ENABLED" End If