How do I elevate vbs to delete a Registry key

元气小坏坏 提交于 2019-12-25 05:14:26

问题


This is the faulty code

WshShell.RegDelete "HKEY_LOCAL_MACHINE\SOFTWARE\cFos\test\tvalue"

This is my error
Error: Unable to remove registry key "HKLM\SOFTWARE\test".
Code: 800070005 Source: WshShell.RegDelete

I gather that I need to disable UAC in Win Vista/7/8 but I was wondering if there is a way to directly run the .vbs file as administrator. Because I need to distribute it and people might not like disabling their UAC and some might even think this is malicious if I give an explicit instruction to pull down their defense


回答1:


Create a new shortcut file using below command line.

runas /profile /user:administrator cscript myscript.vbs

or...

runas /profile /user:administrator cscript "C:\Script Collection\My Script.vbs"

You can then simply double click the shortcut file to execute the script using Administrator account.

The shortcut will prompt for Administrator password each time. If you want it to fully automate it, use below command line instead.

runas /profile /savecred /user:administrator cscript myscript.vbs

It will prompt for the password, but only once. The next time you run it, it will not prompt it again.




回答2:


Open the Start Menu and type cmd. When Command Prompt appears, right-click it and choose Run as Administrator. You can run your script from the elevated command prompt with either cscript.exe or wscript.exe.

To run the script from a shortcut, right-click the desktop and choose New > Shortcut. It will prompt you for the location of the program. Type the following:

runas /noprofile /savecred /user:localmachinename\administrator cscript.exe "C:\path\to\script.vbs"

Click Next. Enter whatever name you like for your shortcut and then click Finish.



来源:https://stackoverflow.com/questions/11980651/how-do-i-elevate-vbs-to-delete-a-registry-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!