Matlab : open OS explorer window only if not already open - matlab

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.

Related

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

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.

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.

Enter Perforce Commands in p4v GUI

Is there a way to manually enter perforce commands in the p4v GUI?
I'm relatively new to Perforce and find the GUI useful for most of what I need to do, but I can see situations where a one line command would be much easier than navigating through the GUI.
Example:
Opening a file for edit that is nested deep in the source tree; this takes many clicks when done in the GUI but would be a relatively short command with environment variables set for my most commonly used directories.
p4 edit -c NNNNNN $DIRECTORY/file
It would be great if the command entered was also added to the Log window. I really like being able to scroll through the Log to see everything I've done in a session.
The closest that exists right now is "File"->"Open Command Window Here" when you have a file selected in the file browsing pane. It will open a command line in that file's directory with all of the relevant environment set up.
Unfortunately, this won't give you unified Log, and you'll have to juggle a second window.

How to create an Explorer window without Navigation Pane using Shell command Explore

My app Folders Popup is using the command ComObjCreate("Shell.Application").Explore(strPath) to create a new Explorer window. I need a way to tell this new instance of Explorer to comply with the Navigation Pane setting decided by the user (to show or not show the pane) in previous Explorer windows.
Actually, this setting is not taken into account by default in the new instance created by the Shell command and users of my app who prefer to use Explorer without this navigation pane are annoyed to see it reappear when my app is opening a new Explorer. Is there any solution to this (except sending keys to the Explorer, what I prefer to avoid)?
Simpler is sometimes better ;)
The Run command isn't just for executables, it can also open non-executable files like images/documents (as long as their file type is associated) and especially folders:
myFolderPath = C:\Path\To\Folder
Run, %myFolderPath%
Generally, it makes sense to use built-in commands or functions if available, before incorporating ActiveX, COM objects or DLL calls; those should provide extra functionality, and not replace what AHK can do out of the box. That, of course, occasionally requires some digging into the docs, but it's worth it! AHK is one of the most well-documented automation scripting languages for Windows.

Clear recently used programs from Windows 7 start menu

Does anyone know a way to clear MRU start menu programs on windows 7 using powershell? I saw a way using a registry edit, but I would prefer if at all possible to avoid that.
If you want to clear recent programs list (one that appears when the start button is pressed), here are your options:
1) Use the following Powershell script and restart Explorer (credit goes here):
del HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist
2) Because you also said disabling recent programs list works for you, here are the two ways to do it:
Using a REG File Download (see above link).
Through the Local Group Policy Editor (I would recommend this one).
And this is just another useful article that covers related topics and explains how it works in detail:
Clear recently used programs in Start Menu in Windows 7.