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,

FCoelho
  • 165
  • 1
  • 4
  • 11
  • 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. – leeharvey1 Oct 18 '21 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. – FCoelho Oct 18 '21 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. – user692942 Oct 18 '21 at 19:25
  • I agree with user692942's comment. I think you can't do this with VBScript. I met [a similar thread](https://learn.microsoft.com/en-us/answers/questions/515181/refresh-edge-via-c.html) before, but it uses C#. With C# you can easily get Edge url using [AutomationElement Class](https://learn.microsoft.com/en-us/dotnet/api/system.windows.automation.automationelement?view=windowsdesktop-5.0). – Yu Zhou Oct 19 '21 at 08:29
  • @user692942 you says that i can use powershell and "connect" the vbs file with this powershell code? – FCoelho Oct 19 '21 at 08:33
  • @FCoelho Just search - [Running Powershell from vbs with command as parameter](https://stackoverflow.com/q/11448365). Still think this is pointless, you're just using VBScript as a wrapper for the PowerShell command. – user692942 Oct 19 '21 at 08:36

1 Answers1

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 
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • 2
    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 Oct 18 '21 at 19:27
  • 1
    @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. – FCoelho Oct 19 '21 at 08:31