search
HomeSystem TutorialWindows SeriesWindows11 VBS Tutorial: How to gracefully close applications?

Windows11 VBS Tutorial: How to gracefully close applications?

Mar 08, 2024 am 11:54 AM
windowsvbsclose application

Windows 11 VBS Tutorial: How to gracefully close an application?

When we use the Windows 11 operating system daily, we often encounter situations where we need to close multiple applications at the same time. Sometimes we may habitually click the close button, or use the task manager to end application processes one by one. However, using VBS script (Visual Basic Script) can more efficiently close multiple applications at once, making the operation smoother and more convenient.

1. What is VBS script?

VBS is a scripting language developed by Microsoft. It is based on Visual Basic and is specially used for scripting on the Windows platform. VBS scripts can be used to perform various system operations, including opening, closing, configuring applications, etc.

2. How to write a VBS script to close an application?

First, open a text editor (such as Notepad) and create a new text file. Then enter the following code in the file:

Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.AppActivate "应用程序标题"
WScript.Sleep 1000
objWshShell.SendKeys "%{F4}"

Wherein, "Application Title" needs to be replaced with the window title of the application you want to close. The script first activates the application window with the specified title, then waits for 1 second and then sends the Alt F4 keyboard combination to close the application.

3. How to close applications in batches?

If you want to close multiple applications at once, you can simply repeat the above code block, modify the "Application Title" and add it to the same VBS file. Here is an example:

Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.AppActivate "应用程序标题1"
WScript.Sleep 1000
objWshShell.SendKeys "%{F4}"

objWshShell.AppActivate "应用程序标题2"
WScript.Sleep 1000
objWshShell.SendKeys "%{F4}"

4. How to optimize VBS script to close the application?

  • Use loops: If you need to close a large number of applications, you can use loops to optimize the code and reduce redundancy. For example, use a For loop to loop through all application titles that need to be closed.
  • Exception handling: In actual applications, you may encounter situations where some applications become unresponsive, the window title changes, etc. Exception handling mechanisms can be added, such as using Try...Catch blocks to catch exceptions and handle them accordingly.
  • Scheduled shutdown: You can combine it with Windows Task Scheduler and other tools to set up scheduled tasks to execute VBS scripts to realize the function of timing shutting down applications.

Conclusion

Close the application through VBS script, which can make the operation more efficient and convenient, and improve work efficiency. In daily use, the script can be further optimized according to individual needs to achieve more personalized application management. I hope the above content can help everyone better use the Windows 11 operating system.

The above is the detailed content of Windows11 VBS Tutorial: How to gracefully close applications?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
8 Ways to Clear the Clipboard on Windows 118 Ways to Clear the Clipboard on Windows 11Apr 21, 2025 pm 12:13 PM

This guide provides multiple ways to clear your Windows 11 clipboard, ensuring your copied data remains private. Your clipboard stores various items, including text, images, and videos. Let's explore several methods to erase its contents. Method 1:

Logitech's G515 Lightspeed keyboard is 25% offLogitech's G515 Lightspeed keyboard is 25% offApr 21, 2025 pm 12:06 PM

Logitech G515 Lightspeed TKL Mechanical Gaming Keyboard Review The Logitech G515 Lightspeed TKL uses low profile keys and feels very similar to the Apple Magic Keyboard, but has an additional mechanical switch, which is slim overall and has a rechargeable battery. Amazon Link This keyboard is perfect for users who both work and games. Amazon currently sells for $119.99, down from its original price of $159.99, only once before it reached this price. G515 Lightspeed TKL is slim in size, 14.49 inches long and 5.91 inches wide,

How to Enable TPM 2.0 to Get Windows 11How to Enable TPM 2.0 to Get Windows 11Apr 21, 2025 am 11:17 AM

Many users with powerful desktops were initially blocked from upgrading to Windows 11 due to a simple BIOS setting being disabled by default: TPM 2.0. This guide explains how to enable it. Checking for TPM Compatibility Windows has a built-in tool t

How to Download a Website as an App on the DesktopHow to Download a Website as an App on the DesktopApr 21, 2025 am 10:37 AM

Quickly Access Your Favorite Websites: Two Methods for Adding Websites to Your Desktop Tired of hunting through bookmarks? Windows offers easy ways to add frequently visited websites directly to your desktop for instant access. This guide details tw

8 Ways to Open the Run Dialog Box on Windows 118 Ways to Open the Run Dialog Box on Windows 11Apr 20, 2025 am 06:01 AM

Windows 11's Run dialog box (Run) provides a convenient way to quickly access various system features and installed applications. The way to start this dialog is simple, just use keyboard shortcuts or select menu items. This article will describe several ways to start this utility. Use keyboard shortcuts to open the run dialog The quickest way to start a Run dialog on Windows 11 is to use keyboard shortcuts. This method opens the dialog box instantly. To do this, press the Windows R key on the keyboard. No matter where you are currently on your computer, Windows 11 will immediately open the Run dialog box. You can then enter the name of the utility you want to start.

Samsung's 32-inch Odyssey G7 IPS Gaming Monitor Is $270 Off TodaySamsung's 32-inch Odyssey G7 IPS Gaming Monitor Is $270 Off TodayApr 20, 2025 am 03:01 AM

Samsung Odyssey G7 (G70D) 32-inch Esports Monitor Special Offer! Original price is $800, current price is only $530, saving $270! This Odyssey G7 sports monitor has 4K resolution, IPS panel, 144Hz refresh rate, AMD FreeSync Premium support, and smart Tizen capabilities. Samsung's official website priced at $530 If you need a monitor that supports high refresh rate gaming, this Samsung 32-inch Odyssey G7 monitor is ideal for you. Currently on sale, priced at $530, $270 less than the original price, and comes with 4K resolution, IPS panel and smart software capabilities. 32-inch Odyss

6 Tasks You Should Do Regularly on Your Windows Computer6 Tasks You Should Do Regularly on Your Windows ComputerApr 19, 2025 am 03:01 AM

Maintaining a Windows computer requires regular upkeep to ensure smooth operation and prevent performance issues, security risks, and unnoticed hardware problems. Here's a routine maintenance checklist to keep your computer running smoothly: 1. Run

How to Right-Click With No MouseHow to Right-Click With No MouseApr 18, 2025 pm 12:03 PM

The mouse is a vital component to getting work done on your PC. But when you’re stuck with a faulty mouse, you can run into a few problems including the inability to right-click. But the good news is that there are definitely ways t

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools