0
Set objShellApp = CreateObject("Shell.Application")
Dim winFolder
For Each wFolder In objShellApp.Windows
On Error Resume Next
isFolder = wFolder.document.folder  ' An IE window does not support ".document.folder". We get the first Windows Explorer window.
If Err = 0 Then
wFolder.Visible = True
Set winFolder = wFolder
Exit For
End If
Next

There must be a better way to distinguish between Windows-Explorer and Internet-Explorer.

I'd appreciate your help.


VBS: Select item in Windows Explorer last active window

barlop
  • 23,380
  • 43
  • 145
  • 225
Yaron
  • 133
  • 2
  • 13
  • 1
    Perhaps you should ask how to identify the process associated with the window. Also you mistagged this, it's not Visual Basic, it's VBScript, a very different thing. – barlop Jul 23 '17 at 22:50
  • Thanks for the correction. Visual Basic and VBScript are new to me. As for identifying the process: I'd still have to find a certain window. My way is tricky and not "proper" but might be faster. What do you think? – Yaron Jul 23 '17 at 23:30
  • 1
    I don't know.. people don't use VBScript much nowadays, JScript is similar but even that has been superceded.. Powershell is the scripting language people use now that supercedes them. It's native to windows 7 and above. NodeJS isn't native but could be said to replace JScript. And there are various non-native languages that could be said to be or are better than vbscript or jscript, like c#.It's also not clear what you want to do once you have identified whether it's IE or not. For example if you just wanted to identify whether IE was running, you could write a batch file that does that – barlop Jul 24 '17 at 00:17
  • Also when you have a programming related question, as you do, then you could ask on stackoverflow, it has a much larger base of users.. be sure to tag your question correctly, to the correct language! in your case, vbscript. (though be aware that most people would use powershell, there may still be a lot of people that remember or even use, vbscript). – barlop Jul 24 '17 at 00:20
  • Thanks for the tips. I appreciate it. *** Someone recently referred me to VBScript and that's why I've been using it. *** I want to open a folder and select a file; an IE window is, obviously, not suitable for that. *** https://superuser.com/questions/1226136/open-and-select-a-file-in-an-existing-explorer-window *** https://superuser.com/questions/1230810/vbs-select-one-file-in-a-folder *** https://superuser.com/questions/1233283/vbs-select-item-in-windows-explorer-last-active-window *** Sorry for the late reply. Probably different time zones. – Yaron Jul 24 '17 at 14:29
  • folders (not internet explorer), can be started with explorer.exe (not to be confused with iexplore.exe which is internet explorer). If you do `start c:\windows\system` then it'd just open the folder but to select a file within that folder you could use the answer here (though I adjusted it to calc.exe which is a file you will have) https://stackoverflow.com/questions/29970897/cmd-file-tasks-open-directory-and-select-file from the command line or search box(clicking the orb in the bottom left),or the run dialog box,u can type / copy-paste `explorer.exe /select,c:\windows\system32\calc.exe` – barlop Jul 24 '17 at 14:37
  • I appreciate your kind help. *** I'm using QTTabBar and I want to open a folder in a new tab in an existing window. I just saw you had read https://superuser.com/questions/1226136/open-and-select-a-file-in-an-existing-explorer-window. :) – Yaron Jul 24 '17 at 14:48
  • To get a particular tab of QTTabBar (a thing I hadn't heard of and haven't used), to open selecting a specific file in the same manner as that explorer /select command, that's not really sendkeys thing and is a question that sounds quite specific to QTTabBar e.g. its command line support.. You could also try the Qttabbar forum http://qttabbar.wikidot.com/forum/c-1286876/qttabbar-general-discussions – barlop Jul 24 '17 at 16:14
  • Thanks again. I appreciate your kind help. *** You should try QTTabBar; it's brilliant. *** I've managed to achieve what I wanted with QTTabBar (https://superuser.com/questions/1233283/vbs-select-item-in-windows-explorer-last-active-window). It's just not the best approach. – Yaron Jul 24 '17 at 16:28

1 Answers1

0

Replace

On Error Resume Next
isFolder = wFolder.document.folder
If Err = 0 Then

with

If(wFolder.FullName = "C:\Windows\Explorer.EXE") Then
Yaron
  • 133
  • 2
  • 13