Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts

Friday, February 3, 2017

VBScript Get List Of Running Processes And Executable Path

Dim Service, Process
 
Set Service = GetObject ("winmgmts:")
 
For each Process in Service.InstancesOf ("Win32_Process")
 Wscript.Echo Process.Name & ": " & Process.ExecutablePath
Next

VBScript - How to make program wait until process has finished

const DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0, WaitUntilFinished = true
set WScript_Shell = WScript.CreateObject("WScript.Shell")
command1 = "C:\xampp\apache_stop.bat"
command2 = "C:\xampp\apache_start.bat"
Wscript.Echo "Apache Server Stopping"
WScript_Shell.Run command1, DontShowWindow, WaitUntilFinished
Wscript.Echo "Apache Server Stopped"
Wscript.Echo "Apache Server Starting"
WScript_Shell.Run command2, DontShowWindow, DontWaitUntilFinished
Wscript.Echo "Apache Server Started"

Thursday, February 2, 2017

VBScript: How to Automatically Restart MySQL Server


Set WshShell = CreateObject("WScript.Shell" ) 
'Just Start Apache Server & MySQL Server
WshShell.Run """C:\xampp\apache\bin\httpd.exe""", 0, false
WshShell.Run """C:\xampp\mysql\bin\mysqld.exe"" --defaults-file=C:\xampp\mysql\bin\my.ini --standalone --console", 0, false
'Stop & Start MySQL Server
WshShell.Run """C:\xampp\mysql_stop.bat""", 0, false
WshShell.Run """C:\xampp\mysql_start.bat"" --defaults-file=C:\xampp\mysql\bin\my.ini --standalone --console", 0, false
Set WshShell = Nothing

Wednesday, February 1, 2017

How can I delete only PDF File from a folder using VBS

Option Explicit
Dim FileSystemObject, RootFolder, SubFolder, File
On Error Resume Next
 Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
 RootFolder = "C:\Users\PRITOM\Downloads"
 
 For Each File In FileSystemObject.GetFolder(RootFolder).Files
  If StrComp(Right(File.Path, 4), ".pdf", vbTextCompare) = 0 Then
   Wscript.Echo File.Path + " Deleted"
   FileSystemObject.DeleteFile File.Path, True
  End If
 Next
 
 For Each SubFolder In FileSystemObject.GetFolder(RootFolder).SubFolders
 Do
  If StrComp(SubFolder.Name, "management", vbTextCompare) = 0 Then
   Exit Do
  End If
  For Each File In FileSystemObject.GetFolder(SubFolder.Path).Files
   If StrComp(Right(File.Path, 4), ".pdf", vbTextCompare) = 0 Then
    Wscript.Echo File.Path + " Deleted"
    FileSystemObject.DeleteFile File.Path, True
   End If
  Next
 Loop Until True
 Next
On Error Goto 0