Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send ALT + F4

Status
Not open for further replies.

drgt

Technical User
Jun 20, 2021
8
GR
Used Windows notepad, typed Sendkeys "%{f4}" and saved the file with vbs extension.
However, when executing, I get:

Windows Script Host
Script: C:\test.vbs
Line: 1
Char: 1
Error: Type mismatch: 'Sendkeys'
Code: 800A000D
Source: Microsoft VBScript runtime error

What am I doing wrong?

Win XP SP2

Thank you
 
What is it you are trying to do?

I assume you are trying to 'send' ALT+F4?

Did you create the required shell object first?

Try:

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "%{F4}"

This should show you the prompt asking whether you want to shut the Windows OS down.

Hope this helps...
 
Thanks for the answer.
Let me be more specific. I am trying to make a batch file that when executed:
1. Would open a chrome window and get an http address: "C:\Program Files\Google\Chrome\Application\chrome.exe" --app=2. Would then close that window
3. Would then close the batch command prompt window.

I guess a different shell object must be created?

AND...Can we do away with the prompt you mentioned?
 
So, nothing at all to do with Sendkeys "%{f4}" at all then.

You want to open then close a remote connection using http? One problem is that Google Chrome doesn't expose COM objects but you can get around this by passing a parameter to a process... but VBS isn't the best method.

Perhaps use PowerShell?

Code:
Start-Process "chrome.exe" "[URL unfurl="true"]http://xxx.xxx.xxx.xxx/cm?cmnd"[/URL]

... then use Stop-Process?
 
Up to this point ("C:\Program Files\Google\Chrome\Application\chrome.exe" --app= it works fine.
If I hit Alt + F4 manually the window closes. I just need the batch file to do it...
 
Perhaps use:
Code:
taskkill /IM chrome.exe

or, to force the process to close:

Code:
taskkill /F /IM chrome.exe
 
taskkill terminates chrome alltogether. I want to close the window the "chrome.exe --app=..." just opened.

That is why I want to send Alt + F4
 
Figured it out.

Code:
Set objShell = Wscript.CreateObject("Wscript.Shell") 
objshell.SendKeys "%{F4}"
 
Hmm, so... my first post hit the nail on its head...
 
Yes, thank you.
(You should have stayed at the code and omit OS shutdown after prompt! :))
 
>I want to close the window the "chrome.exe --app=..." just opened.

In that case, are you sure you want Alt + F4 rather than Ctl + F4?
 
@strongm
Hmmm... I do not know.
It works right now. Does not affect other chrome, or not, windows and as wise people have said, "If it is not broken, DO NOT fix it"!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top