如何在指定时间后通过命令提示符关闭个性化窗口 [英] How to close the personalization window after specified time via command prompt

查看:141
本文介绍了如何在指定时间后通过命令提示符关闭个性化窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些vbs代码,这些代码将通过cmd自动更改Windows主题,并在操作完成后将其关闭。个性化窗口打开,Windows更改主题,然后个性化窗口关闭。问题是,有时更改主题后窗口无法关闭,我想知道为什么。另外,在cmd(或可以通过cmd执行的vbs)中是否有一个单行代码会关闭个性化窗口?在此先感谢您的帮助!我使用的代码如下:

I have some vbs code that will automatically change my windows theme via cmd as well as close it after the operation completes. The personalization window opens, Windows changes the theme, and then the personalization window closes. The problem is, sometimes the window doesn't close after changing the theme and I'm wondering why. Also, is there a one-liner code in cmd (or vbs that can execute through cmd) that just closes the personalization window? Thanks in advance for your help! My code used is as follows:

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""C:\Windows\Resources\Ease of Access Themes\basic.theme"""

Wscript.Sleep 1600
WshShell.AppActivate("Desktop Properties")
WshShell.Sendkeys "%FC"
WshShell.Sendkeys "{F4}"


推荐答案

您的 Run 调用已异步完成,因此您的脚本将继续运行而无需等待 Run 完成。很好,这就是您所需要的。但是,如果启动桌面属性对话框的时间超过1600毫秒,则会将 AppActivate 和您的 SendKeys 命令发送到不存在的窗口。您是否尝试过增加睡眠时间以查看它是否起作用?

Your Run call is being done asynchonously so your script will continue without waiting for Run to complete. This is fine, and it's what you need in your situation. But if it takes longer than 1600ms to launch the Desktop Properties dialog then AppActivate and your SendKeys commands are being sent to a nonexistent window. Have you tried increasing the sleep time to see if it works?

您还可以循环测试窗口的可用性。如果找到窗口,则 AppActivate 返回 True ,否则返回 False 。例如,下面的代码段尝试10秒以查看窗口是否出现(每秒检查一次)...

You can also test the availability of the window in a loop. AppActivate returns True if the window is found and False otherwise. For example, here's a snippet that tries for 10 seconds to see if the window appears (checking each second)...

For i = 1 To 10

    WScript.Sleep 1000

    If WshShell.AppActivate("Desktop Properties") Then
        WshShell.Sendkeys "%FC"
        WshShell.Sendkeys "{F4}"
        Exit For
    End If

Next

' If i > 10, it failed to find the window.

这篇关于如何在指定时间后通过命令提示符关闭个性化窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆