本帖最后由 WHY 于 2024-12-24 14:31 编辑
Test.bat,双击运行。- @if(0)==(0) echo off
- %1 mshta VBScript:CreateObject("Shell.Application").ShellExecute("CMD","/c """"%~f0"" ::""","","RunAs",1)(close)&exit/b
- set "regPath=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\SkyPDF Pro Driver"
- set "regName=Default DevMode"
- reg query "%regPath%" /v "%regName%" 2>&1 | cscript //nologo //e:jscript "%~f0" "%regPath%" "%regName%"
- pause & exit/b
- @end
-
- var strPath = WSH.Arguments(0);
- var valName = WSH.Arguments(1);
- var subKey = strPath.substr(strPath.indexOf('\\')+1);
- var ROOT = function(){
- if (/^(?:HKCR|HKEY_CLASSES_ROOT)/i.test(strPath)){
- return 0x80000000;
- } else if (/^(?:HKCU|HKEY_CURRENT_USER)/i.test(strPath)){
- return 0x80000001;
- } else if (/^(?:HKLM|HKEY_LOCAL_MACHINE)/i.test(strPath)){
- return 0x80000002;
- } else if (/^(?:HKUS|HKEY_USERS)/i.test(strPath)){
- return 0x80000003;
- } else if (/^(?:HKCC|HKEY_CURRENT_CONFIG)/i.test(strPath)){
- return 0x80000005;
- }
- }();
-
- function setRegistryValue(arrValue){
- var objLoc = new ActiveXObject('WbemScripting.SWbemLocator');
- var objReg = objLoc.ConnectServer(null, 'Root\\Default').Get('StdRegProv');
- var oMethod = objReg.Methods_.Item('SetBinaryValue');
- var inParam = oMethod.InParameters.SpawnInstance_();
- inParam.hDefKey = ROOT;
- inParam.sSubKeyName = subKey;
- inParam.sValueName = valName;
- inParam.uValue = arrValue;
- objReg.ExecMethod_(oMethod.Name, inParam);
- }
-
- function convertData(Data){
- var arr = [];
- var reg = /../g;
- while (e = reg.exec(Data)) arr.push(1 * ('0x' + e[0]));
- return arr;
- }
-
- var s = WSH.StdIn.ReadAll();
- var m = s.match(/REG_BINARY\s+([a-f0-9]{14128})[a-f0-9]{2}([a-f0-9]+)/i);
- if(m){
- var Data = m[1] + '04' + m[2]; //从14128个字符起,后2个字符修改为04
- setRegistryValue(convertData(Data));
- WSH.Echo('Done');
- } else {
- WSH.Echo('no such registry key or value found.');
- }
复制代码
|