Avatar of Danean
Danean
 asked on

count lines of text in the opened internet window

I need a batch command file to attach to an icon I have on my internet explorer toolbar.

The command needs to count the number of text lines that are in the current internet explorer window.

So it is a text file, but each text file will have a different name and be already opened when I run the batch command to simply count the lines of text in the opened window.
Windows 7PowershellScripting LanguagesWeb Browsers

Avatar of undefined
Last Comment
Qlemo

8/22/2022 - Mon
Qlemo

A .bat/.cmd file does not have access to your Internet Explorer windows. That requires .Net code. Feasible with VBS or PowerShell, or .NET programming languages.
Danean

ASKER
Okay.  Thanks for this information.  I do have powershell.  Do you know what the .Net code would be in order for me to get the line count?
Qlemo

Seems as if that is overly complicated still. I can't get PowerShell to tell which one is the "current openend Internet Explorer window". The best I can do is to show the line count of all URLs staring with FILE://:
(New-Object -COM Shell.Application).Windows() |
  where { $_.FullName -like '*\iexplore.exe' -and $_.LocationURL -like 'file:*'} |
  % { write-output ($_.LocationURL + ": " + ($_.Document.body.innerText -split "`r`n").count) }

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Danean

ASKER
the above solution works wonderfully.  However, I am kind of new and am having a few issues still.

1st.  I copied the script above into notepad and saved the files as c:\counttext.ps1.  I programmed by button to launch this file and of course it just opens the text file.  I made sure "all files" was selected before saving it.

2nd.  The solution executes fine from the powershell.

So what am I missing to get my button to run the script and not open the text file?

Thanks.
Qlemo

First try if you can start this command:
    powershell -file C:\counttext.ps1
If that works, use that line for executing the PS code.
Danean

ASKER
I can start the powershell -file c:\counttext.ps1.

I tried adding that line to the beginning of the code you gave and it still does not run.  I also created a counttext file with just that line and I still can't run it.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question