0

I am new to PowerShell scripting. I would like to know if i can check whether a html file is open. If it is opened, then i would like to re-open it after running the same script.

My script creates a html file and using Invoke-Item, i am opening it. The next time i run the same script, the updated html file gets opened in the new tab. I want my script to close the previously opened file right before opening the new one or some similar logic.

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40

1 Answers1

0

By using Invoke-Item you actually are asking Windows' Explorer to open the file with the default application that's registered for .html files. In out of the box configuration, that's Internet Explorer or Edge. This, of course, can be customized.

Depending on the browser used, there might be a COM interface for querying browser status. As how to do that is subject to another a question, as it really depends on the browser. Looking for, say, file handles might or might not work, as browsers tend to open files in read only mode - they are not supposed to modify it anyway.

Anyway, this sounds like another a XY problem. Please edit the question and describe what problem are you really trying to solve; maybe there's better a way.

vonPryz
  • 22,996
  • 7
  • 54
  • 65