Friday, February 3, 2017

Install and Create MySQL ODBC Connector on Windows 7

MySQL ODBC Connector help you to connect to MySQL via different applications. It supports Windows, Linux, Mac & Unix Platforms. You can more details from here. Please follow the following steps to download and install MySQL ODBC Connector to your machine.


  • Download and install from here or from here
  • Double click on the file "mysql-connector-odbc-3.51.30-winx64.msi" that you just downloaded to run the setup process.
  • Click Next and accept the license agreement.
  • Select Custom to see what we will have after the installation

VBScript Get a List of the ODBC Drivers

Const HKEY_LOCAL_MACHINE = &H80000002
StrComputer = "."
Set ObjRegistry = GetObject("winmgmts:\\" & StrComputer & "\root\default:StdRegProv")
StrKeyPath = "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
ObjRegistry.EnumValues HKEY_LOCAL_MACHINE, StrKeyPath, arrValueNames, arrValueTypes

For i = 0 to UBound(arrValueNames)
    StrValueName = arrValueNames(i)
    ObjRegistry.GetStringValue HKEY_LOCAL_MACHINE,StrKeyPath,StrValueName,StrValue
    Wscript.Echo StrValueName + " - " + StrValue
Next

Windows - How to terminate process using VBScript

Sub ProcessTerminate(Process)
    Const StrComputer = "." 
    Set WshShell = CreateObject("WScript.Shell")
    Set ObjWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & StrComputer & "\root\cimv2")

    Set ProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & Process & "'")
    For Each ObjProcess in ProcessList 
        On Error Resume Next
        ObjProcess.Terminate
        Wscript.Echo "Process Terminated, ProcessId=" & ObjProcess.ProcessId & " (" & ObjProcess.Name & ")" 
    Next
End Sub

ProcessTerminate "chrome.exe"

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