Capture cmd result without opening command prompt window or creating temporary file or .bat file, or without using python or others, possible?

ballgnm

New Member
Joined
Jan 16, 2023
Messages
12
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Hello guys. I need to get version of my installed selenium chromedriver.exe in vba.
But I couldn't find good silent method.

shell.exec always opens command prompt window that pops up.
Is there truly silent way to do it?

Or any alternative way to get version of chromedriver in vba without using python or similar third party app or without creating temp files?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
VBA Code:
    Debug.Print CreateObject("Scripting.FileSystemObject").GetFileVersion(Environ("localappdata") & "\SeleniumBasic\chromedriver.exe")
It gives me empty string.
 
Upvote 0
That command reads the chromedriver.exe file properties, however they're blank. By contrast, edgedriver.exe properties aren't blank.

A version number is displayed when I run chromedriver.exe, but I haven't found a way of reading it.
 
Last edited:
Upvote 0
Try this:
VBA Code:
Public Sub ChromeDriver_Version()

    Dim line1 As String
    
    'Run chromedriver.exe, read first line of output and extract version number
    
    With CreateObject("WScript.Shell")
        line1 = .Exec(Chr(34) & Environ("localappdata") & "\SeleniumBasic\chromedriver.exe" & Chr(34)).StdOut.ReadLine
    End With
    Debug.Print Split(line1, " ")(2)
    
    Shell "TaskKill /IM chromedriver.exe", vbHide
    
End Sub
Note that a command window is displayed briefly, however this is unavoidable with the Windows Script Host Shell Exec method. The alternative of running chromedriver.exe with the Run method, which can hide the command window, and redirecting the output to a file doesn't work because the file isn't created.
 
Upvote 0
Note that a command window is displayed briefly, however this is unavoidable with the Windows Script Host Shell Exec method.
Yeah. Unfortunately.
Tried .exec and .run before I come here and post.
Thought there would be alternative without installing third party apps.
I'll just use .Run in window hidden mode and create and delete temporary file I guess.
 
Upvote 0
Sure.

VBA Code:
Sub ChromeDriverCheck()
    Dim vChromeDriver, driverPath, ChromeDriverEXE, cmdChrome, tempFile As String

    driverPath = Environ("LocalAppData") & "\SeleniumBasic\"
    ChromeDriverEXE = driverPath & "chromedriver.exe"
    tempFile = driverPath & "TemporaryFileForDriverVersionCheck.txt"
    cmdChrome = "cmd /c """ & driverPath & "chromedriver.exe" & """ --version > " & tempFile
    
    If Dir(ChromeDriverEXE) <> "" Then
        VBA.CreateObject("WScript.Shell").Run cmdChrome, 0, True
        Open tempFile For Input As #1
        vChromeDriver = Input$(LOF(1), 1)
        Close #1
        Kill tempFile
        vChromeDriver = Split(vChromeDriver, " ")(1)
    Else
        vChromeDriver = ""
    End If
    
    Debug.Print vChromeDriver
End Sub
 
Upvote 0
Ahaa! I didn't know about the --version switch, which makes chromedriver.exe run and exit immediately. Without it, I had to TaskKill the process which meant the output file wasn't created.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top