how to check if a .html file is open, if yes, close it using windows PowerShell script - powershell

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.

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.

Related

VS Code: when I close a sub-folder and return to the file, the sub-folder reopens

I've always developed with Sublime Text, but I feel that VS Code is much better, so I want to get started.
I have a problem please (with Sidebar of VS Code):
When I open a sub-folder in my project, and I open a file that is inside, I like to manually close this sub-folder (because I like to see the architecture of the project, etc.) and to continue working on its files which are already open in my editor.
For example (I work with Laravel): if I open a "User.php" file which is in the "App/Modals" folder, then I manually close the "App/Modals" folder, then I will work in another file, then I come back to work in "User.php", the "App/Modals" folder reopens by itself ...
I do not have this behavior with Sublime Text, nor with PHP Storm.
SVP: Is there a regulation to prevent this behavior?
Thank you.
There's an option to make this feature (it's not something that's just happening to you, it's a feature of VSCode) go away. Go to settings (ctrl + , or cmd + , on mac) and search for "explorer.autoReveal". Make sure it's unchecked, or set it to false in your setting's json.
Just by the way, I don't know if you did, or you didn't know what to search, but you should try to solve this kind of problems by googling for an answer. For instance, I didn't know the answer, but a simple 'disable auto opening folder vs code' in google brought me several results. Just a recommendation, so that you can learn how to solve your own problems and be more efficient.

Is drag-and-drop to open a file possible in VSCode?

I am wondering if something is wrong with my computer (or myself), because I can't seem to drag & drop a file into Visual Studio Code to open it in the editor. Closing an opened folder first doesn't make a difference. VSCode always shows me the 'stop sign', in every spot I tried (the editor, the opened tab bar, an existing opened file, ...).
Why does VSCode block this ?
(I have experienced this in earlier versions as well. Currently on v1.6 on Windows 7.)
Searching for a solution, I stumbled on this page, where one commenter explains:
I think you are running into the security issue where lower permission processes cannot send messages to higher permission processes. Explorere.exe, running at normal permission levels, cannot send the window message to winword.exe, running elevated.
I am indeed always running VSCode as Administrator, but not my Explorer windows.
When I run VSCode in non-administrator mode (so just my regular user), drag-and-drop works fine.
I feel silly as I lost 15 minutes looking into this. In case it helps:
Make sure you are not trying to open files from a zip file...
Cheers.

Use Powershell to highlight files on an open file explorer window

I've seen how to open a new File explorer, e.g. explorer.exe /select,$path and select files in that new window, but how would I do this with an existing File explorer window, i.e. tell File explorer to select certain files, as if the user had clicked and highlighted those files?
I love Powershell, honestly I use it even when I know another language would be better. But this is no job for Powershell. I don't know to what end, you are "selecting files" in Explorer for, but it may be possible to accomplish your end goal without utilizing the GUI. If for some reason I don't understand you actually want to do what your are asking about in your question, I would use autoit to simulate key presses or clicks.

Matlab : open OS explorer window only if not already open

I'm opening a folder in Windows explorer from within matlab with the following line :
system('explorer.exe /select,./my_folder/my_file.tif');
It works well, even with the relative path for Matlab "current folder" with "./". Note that it also selects the specified file, which is what I want.
However, I would like to open this window only if the same path isn't already open. Right now, I get several copies of the same window and it's annoying. Do you know any way to do this ?
Thanks,
Ghislain
(Windows 8, Matlab R2011b 64bits)
Disclaimer
This is a partial answer. I don't know how to go on from here, but maybe it helps anyways. Your question is quite interesting to me, and it would make data-analysis a lot easier if changing between interfaces (Matlab/Explorer) were easier!
Some History
DDE is an ancient technology (16-bit Windows, yeah!) that enables Windows applications to talk to each other. DDE has been deperecated from Windows XP on, but it simply refuses to die.
One reason for DDE's longevity is that Windows Explorer still uses DDE a lot. For example, when you double-click a file, the Explorer sends a DDE command to Excel, telling it to open that file in the current Excel window.
How DDE might help you
Matlab's DDE support is officially deprecated. Maybe it would have disappeared completely, were it not for the fact that Explorer talks to Matlab via DDE messages!
You can reverse this process by telling initiating a DDE channel to the application "folders" about the topic "appproperties":
channel = ddeinit('folders', 'appproperties')
The "folders" application appears to be a synonym for "progman", the good ol' Windows 3 program manager. You can tell Explorer ("folders") to view a folder by executing
ddeexec(channel, '[ViewFolder("%l", c:\windows, 5)]')
If Explorer already points to that folder, no new window is opened. Unfortunately, I cannot tell you much more about that command. I don't know what that %l is doing there, or the 5 for that matter. The only thing I know is that ViewFolder can be replaced by ExploreFolder, in which case you always open a new window, and that window always shows the folder tree structure on the left pane.
More Information
The most important DDE-related functions are ddeinit, ddeexec, and ddeterm. Their documentation is buried inside the .m files of those functions. You can view the .m files by simply executing
edit ddeinit
Yair Altman has some more info on Matlab's DDE capabilities. What DDE commands are understdood by Explorer evades me. I assembled my example from what I found here.

VS2005 - Automatically requesting checkout of form on open, with "View Designer"

I'm trying to integrate our Source Control(SourceAnywhere) with VS and are getting a lot of push back because of this one issue.
Almost every time we open some of our Windows forms using 'View Designer' it edits the file (* appears beside file name). Nothing has yet been changed, I've tried comparing the before and after files and they are exactly the same. If we have the solution bound it will check the file out, but even if its not bound it still 'edits' the file. When you try to check the file back in, it doesn't get a new version or anything.
I've done some searching and haven't been able to find any way to change this behavior.
This is a huge pain point for me as if someone already has the form checked out and someone else tries to open it, they just get told that it can't be checked out, and the form won't open. Or, someone who has no intention to edit the form, will now have the form checked out but hasn't made any changes.
Thoughts?
This usually happens when there are controls within the form that have "Dock" set. If the IDE feels it needs to resize the form, then those controls will also be resized, and all of that information needs to get re-written to the source file. In the case where you're editing a form named "Form1" this source file is not Form1.cs, but rather Form1.Designer.cs - try comparing that file with the version from source control.
Alternatively, move to a source control system that doesn't use locking by default (for example, Subversion) or disable that feature in SourceAnywhere. This will require users to manage merge conflicts, but allows multiple users to work on a single file at the same time.