0

I want to validate if the edge is open and if so I want to retrieve the url of each open tab. At the moment i have this, but i dont have much experience in vbs. What i want its possible with vbs?

    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
   sQuery = "SELECT * FROM Win32_Process"
   Set objItems = objWMIService.ExecQuery(sQuery)
   For Each objItem In objItems
       if(objItem.Name = "msedge.exe") then
            WScript.Echo "Process [Name:" & objItem.Name & "]"
            
            
        Exit For
       end if
   Next

Thanks in advance,

6
  • 2
    You might have better luck using PowerShell and working with the Windows UI Automation API. Be forewarned, it's not easy to grasp, but it will get the job done, and there are several examples readily available if you Google the right terms. Commented Oct 18, 2021 at 14:08
  • @leeharvey1 thanks for the reply. Unfortunately I really have to use vbs. the ancien program works with ie and now its just wanted that we change ie by edge. and the vbs file its called by another program and if i change to another thing it's gonna be more difficult. Commented Oct 18, 2021 at 14:26
  • 2
    @FCoelho you can't do it with VBScript without some proprietary COM DLL to do the heavy lifting. Lee's suggestion of using PowerShell is probably worth pursuing in all honesty. If you really have to use VBScript you could do it in PowerShell and pipe it through VBScript but where's the point. Commented Oct 18, 2021 at 19:25
  • I agree with user692942's comment. I think you can't do this with VBScript. I met a similar thread before, but it uses C#. With C# you can easily get Edge url using AutomationElement Class. Commented Oct 19, 2021 at 8:29
  • @user692942 you says that i can use powershell and "connect" the vbs file with this powershell code? Commented Oct 19, 2021 at 8:33

1 Answer 1

0

Refer to this access the title of a window using vbscript

I just teaked a little modification to you

Dim Tasks
Tasks = Split(WScript.CreateObject("WScript.Shell").Exec("cmd /c tasklist /v /fo csv | findstr /I ""msedge""").StdOut.ReadAll(),vbCrLf)
Dim task
For Each task In Tasks
    task = Split(Trim(task),",")
    If Ubound(task) >= 8 And task(8) <> """N/A""" Then
        WScript.Echo "Process " + task(0) + "ID: " + task(1) + " Title: " + task(8)
    Exit For
    End If
Next 
Sign up to request clarification or add additional context in comments.

2 Comments

That isn't going to help because Browsers don't display the URL in the window title but the document title taken from the HTML page being displayed. The OP is asking for the URL. Quote - "I want to retrieve the url of each open tab". It just isn't possible with native VBScript.
@user692942 That's right. I want to retrieve the url so that I can process it later. The script above only give-me the title.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.