Windows 上的关闭脚本以删除注册表项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/111097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:16:11  来源:igfitidea点击:

Shut-down script on Windows to delete a registry key?

windowsbatch-filescriptingregistry

提问by Matt

EDIT:This was formerly more explicitly titled: - "Best solution to stop Kontiki's KHOST.EXE from loading automatically at start-up on Windows XP?"

编辑:这以前更明确地命名为:-“阻止 Kontiki 的 KHOST.EXE 在 Windows XP 上启动时自动加载的最佳解决方案?

Essentially, whenever the 40Dapplication is run it sets up khost.exeto automatically start-up with Windows. This is annoying as it increases my boot up time by a couple of minutes and I don't even use the P2P aspect of 4OD anyway.

本质上,每当40D应用程序运行时,它都会设置khost.exe以自动启动 Windows。这很烦人,因为它使我的启动时间增加了几分钟,而且我什至不使用 4OD 的 P2P 方面。

The registry keys that are set are:

设置的注册表项是:

Command: C:\Program Files\Kontiki\KHost.exe -all
Description: kdx
Location: HKU\S-1-5-21-1757981266-1960408961-839522115-1003\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Name: kdx
Setting ID:
User: LAPTOP\Me

Command: "C:\Program Files\Kontiki\KHost.exe" -all
Description: 4oD
Location: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Name: 4oD
Setting ID:
User: All Users

I'm assuming some kind of start-upor shut-downscriptto delete these registry keys would be the best solution, but I'm not that up with .vbsor .batscripting or where I'd put them to automatically run at an appropriate time.

我假设某种启动关闭脚本来删除这些注册表项将是最好的解决方案,但我不喜欢.vbs.bat脚本或我将它们放在哪里自动运行在适当的时候。

I know there is a TV On-Demand Monitor application, but I don't really need to be running yet another process, I just need to delete the registry keys as I describe above.

我知道有一个TV On-Demand Monitor 应用程序,但我真的不需要再运行另一个进程,我只需要删除我上面描述的注册表项。

采纳答案by beakersoft

for the vb script you would use something like this:

对于 vb 脚本,您将使用以下内容:

Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
'repeat the line below for each key to delete 
WSHShell.RegDelete "[Location of Key]"

Just drop the code into a text file and re-name it something like shutdown,vbs.

只需将代码放入一个文本文件中,然后将其重命名为 shutdown、vbs。

As for when to run it, if you are in a corporate environment you could use a group policy and set it as a machine shutdown script. Alternatively, see this page hereabout adding it manually

至于何时运行它,如果您在公司环境中,您可以使用组策略并将其设置为机器关闭脚本。或者,请在此处查看有关手动添加的页面

回答by Matt

What I ended up doing in the end:

我最后做了什么:

1)Stopped 40Dfrom the task tray with a right-click> exitwhich terminated the Khost.exeprocess.

1)通过右键单击>退出从任务托盘中停止40D,这终止了Khost.exe进程。

2)Opened Start> All Programs> Administrative Tools> Servicesand stopped KServicethen set the Startup Typeto 'Manual'.

2)打开开始>所有程序>管理工具>服务并停止KService然后将启动类型设置为'手动'。

3)Created a ShutdownScript.vbswith the following content:

3)创建了一个ShutdownScript.vbs,内容如下:

Set SH = CreateObject("WScript.Shell")

RemoveRegKey "HKU\S-1-5-21-1757981266-1960408961-839522115-1003\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\kdx"
RemoveRegKey "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\kdx"
RemoveRegKey "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunoD"

Shutdown

Set Shell = Nothing
Set SH = Nothing
WScript.Quit

Sub RemoveRegKey(sKey)
    On Error Resume Next
    SH.RegDelete sKey
End Sub

Sub Shutdown()
    SH.Run "shutdown -s -t 1", 0, TRUE
End Sub

4)Put a shortcutto the script in my Start Menuand now use that to shut the PC down.

4)在我的开始菜单中添加脚本的快捷方式,现在使用它来关闭 PC。

Now 40Dwill work when I need it, and all I have to do is quit it and shutdown with the script to stop it auto-starting everytime I boot up the PC.

现在40D将在我需要时工作,我所要做的就是退出它并使用脚本关闭以在每次启动 PC 时停止它自动启动。

THANKS FOR ALL YOUR HELP WITH THIS! :)

感谢您的帮助!:)

回答by Frank Krueger

Why not just copy the executable to some other name, and put a do-nothing exe in its place. Then change your shortcuts to the copied and renamed EXE. If the program is sensitive to its name, then point your shortcuts to a VBS file to temporarily rename the EXE file.

为什么不将可执行文件复制到其他名称,并在其位置放置一个无用的 exe。然后将您的快捷方式更改为复制并重命名的 EXE。如果程序对其名称敏感,则将快捷方式指向 VBS 文件以临时重命名 EXE 文件。

回答by Frank Krueger

Another method:

另一种方法:

Create a VBS file that runs the program and then deletes the registry keys.

创建一个运行该程序的 VBS 文件,然后删除注册表项。

Set objShell = CreateObject("WScript.Shell") 

objShell.Exec("C:\Program Files\Kontiki\KHost.exe")

strRoot = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunoD" 
strDelete = objShell.RegDelete(strRoot) 
...

And point your shortcuts at that.

并指出你的捷径。

回答by Pascal T.

Should I suggest you give a try to AutoIt (http://www.autoitscript.com/autoit3/), a freeware scripting language designed for automating the Windows GUI and general scripting.

我应该建议您尝试使用 AutoIt ( http://www.autoitscript.com/autoit3/),这是一种免费软件脚本语言,旨在自动化 Windows GUI 和通用脚本。

If you choose to use it, the AutoIt code for your need would be a 2-liner:

如果您选择使用它,您需要的 AutoIt 代码将是 2 行:

RegDelete("YourKey", "YourValue");
ShutDown(1);

And you can compile it into a standalone exe that can run on any computer (no runtime library needed)

并且您可以将其编译为可以在任何计算机上运行的独立 exe(不需要运行时库)