' ========================================================================== ' Description: This script shuts down the TWiki Windows Personal webserver ' It will also delete the webserver logs if they were stored ' on the user's hdd in the %TMP% folder without asking. ' Filename: Stop.vbs ' Version: 1.0 ' ========================================================================= strProcess = "tinyweb.exe" strComputer = "." Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & strProcess & "'") If colProcesses.Count = 0 Then ' tinywewb is NOT running, go ahead and launch... msgbox "Webserver wasn't running so no shutdown is needed", vbOKonly, "No Shutdown Needed" Else ' Tinyweb is already running... ask if user wants to terminate... 'status = MsgBox ("Webserver detected, terminate?", vbYesNo, "Terminate?") 'If status = vbYes Then For Each objProcess in colProcesses objProcess.Terminate() Next 'End If ' ------------------------------------------- ' This loop displays an updating termination ' dialog while the webserver process is being ' shut down. ' ------------------------------------------- i = 0 strDots = "" Do i = i + 1 strDots = strDots + "." Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & strProcess & "'") If colProcesses.Count = 0 Then Exit Do Else Set objShell = CreateObject("WScript.Shell") objShell.Popup "Terminating.." & strDots, 1, "TERMINATING...", vbOkOnly End If Loop While i < 10 ' ------------------------------------------- ' Check again to see if we got it shut down and give a final message... ' ------------------------------------------- Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & strProcess & "'") If colProcesses.Count = 0 Then MsgBox "Webserver successfully shut down", vbOkOnly + vbSystemModal, "SUCCESS" Else MsgBox "Webserver was NOT successfully shutdown!", vbCritical + vbSystemModal, "ERROR" End If ' ------------------------------------------- ' See if we left any TMP files from the webserver on the user's hdd, ' in case we were running in read-only mode and had to write to the ' %TMP% folder... ' ------------------------------------------- Set objFSO = CreateObject("Scripting.FileSystemObject") Set objEnv = objShell.Environment("Process") 'WScript.Echo objEnv("TMP") 'Make sure there aren't spaces in this string after the commas: strFiles = "access_log,agent_log,error_log,referer.log" arrFiles = split(strFiles, ",") 'create an array from the list 'WScript.Echo UBound(arrFiles) For i = 0 To UBound(arrFiles) arrFiles(i) = objFSO.BuildPath(objEnv("TMP"), arrFiles(i)) ' Append TMP path to filename 'WScript.Echo arrFiles(i) If objFSO.FileExists(arrFiles(i)) THEN objFSO.DeleteFile(arrFiles(i)) ' delete the log file in the TMP directory 'WScript.Echo "Deleted: " & arrFiles(i) End If Next End If WScript.Quit