Win+D In a .vbs/SendKeys file? [duplicate] - windows

This question already has answers here:
I found some code that shows/hides desktop icons, but it moves the icons in the process. How can I edit the code to not move the icons?
(2 answers)
Closed 5 years ago.
I'm trying to simulate Win+D (show desktop) in a .vbs file, but I can't use the Windows key. I tried using Ctrl+Esc, but that doesn't work. I'm running Windows 10.
Here's my code right now:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "windows key + d ?????"

ToggleDesktop Method
Raises and lowers the desktop.
object.ToggleDesktop
Parameter Description object Required. An object expression that evaluates to a Shell object.
Remarks
This method behaves like the toggle desktop icon on the quick launch
bar. It hides all open windows and shows the desktop, or hides the
desktop and shows all open windows. The ToggleDesktop method does not
display any user interface, it just invokes the toggle action.
From https://msdn.microsoft.com/en-us/library/windows/desktop/gg537747(v=vs.85).aspx
Use this line to create the object
Set objShell = CreateObject("Shell.Application")

Related

HTA Files and Microsoft Edge [duplicate]

This question already has an answer here:
Open a link with a specified url and specified browser hidden with vbscript
(1 answer)
Closed 10 months ago.
I have a HTA application. Within the HTA, I'm calling a function to open up a webpage using:
window.open( sURL, "Working" );
This opens a page in Internet Explorer and not Edge.
Is there a way to default window.open to open a webpage in Edge?
Using window.open in an HTA will always open the specified URL in Internet Explorer, even in Windows 11 (build 22000.348 or higher required). If you wish to open a web page in Edge, you can do so using the Run method:
Set oWSH = CreateObject("WScript.Shell")
oWSH.Run "msedge.exe --new-window ""https://www.cnn.com""",0,False

Can an already running program's window be hidden?

I have been using wsh to run vbscripts in conjunction with iMacros at my work for going on 3 years now. I know that the iMacros browser itself has an option to run hidden but the web-based db interface I have to work with does not function in the iMacros browser. For this reason I have had to use Internet Explorer. I have no problems with the script itself or how it runs. The thing I would like to improve is how the Internet Explorer window itself is handled.
Currently, when iMacros is initiated it creates the IE window in a non-maximized state cascaded from where the previous window was created. Because of iMacros's behavior, I then resize the window using an iMacros script so that enough of the page is rendered for the script to see everything it needs.
Set iim1 = CreateObject ("imacros")
iret = iim1.iimOpen ("-ie -iePrivate", TRUE, 300)
iret = iim1.iimPlayCode("SIZE X=" & scrWidth & " Y=" & scrHeight)
This all works fine and dandy. The scripts are scheduled to run at specific times, gather information out of the db and then imports that data into Excel spreadsheets and prints them out.
What I would like to do is make the IE window hidden while these scripts run. Because I do not create the IE window first (Set objIE = CreateObject("internetexplorer.Application")) I do not have access to the IE window object. I let iMacros create the window with the -iePrivate flag so that it will not disturb my own IE window if I should be logged in and working in the db while the script executes. However, it does try to take focus and become the active application while the script executes. Which can be very annoying at time. My goal is to be able to share these scripts with my co-workers but I don't want the IE windows popping up on them while they may be working on something else.
Is there a way to get to the IE object created by iMacros so that the window can be hidden?
This does Internet Explorer and Explorer windows (they used to be the same program).
Set objShell = CreateObject("Shell.Application")
Set AllWindows = objShell.Windows
For Each window in AllWindows
msgbox window.locationname
Next

Invoke 'Open' Dialog from Windows Desktop

Is there some way I can programmatically (in VBS) OR by using CMD/RUN open the 'Open' dialog that contains the places bar and a browser but without opening say notepad or MSpaint?
http://i.technet.microsoft.com/dynimg/IC354177.jpg
I'd like to use this on the desktop itself, it would be really cool if there was a DLL I can just use instead of having a VBS file but if not i'm sure its possible in VBS.
I'm busy searching where the actual open dialog box comes from, it should come from some DLL file somewhere.
I might even consider stopping the windows shell from opening all together and just using this open window as the shell on some computers.
Regards, Rocklore
What version of Windows are you on?
"UserAccounts.CommonDialog" was the way to do this in XP. But it no longer exists in Windows 7. You may be able to use some of the flags available for the BrowseForFolder() method to make it look like a file open dialog. See this page for an example.
XP Edit:
Here's an XP example using UserAccounts.CommonDialog.
With CreateObject("UserAccounts.CommonDialog")
.InitialDir = CreateObject("WScript.Shell").SpecialFolders("Desktop")
.Filter = "All Files|*.*"
' Show the dialog. If [Open] is clicked, save the name of the selected file...
If .ShowOpen Then strFile = .FileName
End With

How can you have a dialog box displayed when opening a program in windows xp?

Does anyone know how to have a dialog box with a custom message pop up any time that a specific program is opened? The computer is running Windows XP Professional 2002 with Service Pack 3. The program is used to operate a scientific instrument that keeps getting damaged by lab users who disregard printed instructions around it. Ideally, I could have a dialog box pop up that requires users to click an "OK" button before the program opens. I've spent some time browsing the web for ideas, but have so far come back empty-handed. The program is usually opened from a shortcut on the desktop.
Many thanks,
Jeremy
A user on another forum answered this question for me. I created a small shell script (text file saved with .vbs extension) to display the dialog box when the program is opened from a Desktop shortcut targeting the script file.
Here's the link to the post in the other forum for more details:
The script that worked for me is shown below:
startupMessage = MsgBox("...close the lid gently and only use the button to open it.", 0, "To prevent instrument damage...")
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim cmd
cmd = "C:\Program Files\InstrumentApplication.exe"
cmd = chr(34) & cmd & chr(34)
WshShell.Run(cmd)

Minimize windows, application startup

Is there a way to minimize all windows automatically when launching an application?
I tried to call a .vbs file with the content above:
Set shell = wscript.CreateObject("Shell.Application")
Shell.MinimizeAll
But doing this, application is minimized too.
I'm not sure if this minimizes the windows, but it will probably satisfy your requirement:
set objShell = CreateObject("shell.application")
objShell.ToggleDesktop
This is equivalent to clicking the show desktop button.
Or as just extending your code:
shell.ToggleDesktop
Edit: Nevermind... this does the same thing as your code above. But why not just run this and then display your window? For instance, if it is your app... call the vbs and then display the window. Or if you have no control over the app, call it from a .bat file and run this vbs then your program.
What you want to do is first minimize all applications or toggle the desktop; THEN (perhaps even after a delay) open your application.

Resources