感谢各位大佬指正,目前用Powershell命令可以实现了,修正后的代码在4楼。
另外5楼大佬给出了纯bat脚本的修改方法,上机测试也是可行的,点赞!!!。
再次感谢!!!- @echo off
- set byte= 04
- for /f "tokens=1-2*" %%A in ('reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\SkyPDF Pro Driver" /v "Default DevMode"') do (
- set settings=%%C
- )
- echo 原来的值 %settings%
- set settings=%settings:~0,14127%%byte%%settings:~14129%
- echo 修改后的值 %settings%
- reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\SkyPDF Pro Driver" /v "Default DevMode" /t REG_BINARY /d %settings% /f
- @pause
复制代码
作者: aloha20200628 时间: 5 天前 15:27
本帖最后由 aloha20200628 于 2024-12-23 15:29 编辑
回复 1# wallat
先在命令行直接运行- reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\SkyPDF Pro Driver" /v "Default DevMode"
复制代码
其返回值应该至少有一行貌似以下:
Default DevMode REG_BINARY 01
若楼主确认如此,可用以下代码修改其值 01 为 04- @echo off &setlocal &set "byte=04"
- for /f "delims=" %%a in (
- 'reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\SkyPDF Pro Driver" /v "Default DevMode"^|findstr /ic:"Default DevMode" '
- ) do (set "settings=%%a")
- echo,原值=%settings:~-2%
- echo,新值=%byte%
- reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\SkyPDF Pro Driver" /v "Default DevMode" /t REG_BINARY /d %byte% /f
- pause&exit/b
复制代码
作者: WHY 时间: 5 天前 15:44
%settings:~0,14127%
看看这个偏移值,就知道纯批有没有办法搞定。
作者: wallat 时间: 5 天前 18:28
确实是,刚才修补修补,看了下,bat命令行读取不到这么长的数值,用Powershell搞定了,感谢各位大佬指导!!!- $regPath = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\SkyPDF Pro Driver"
- $valueName = "Default DevMode"
-
- # 获取当前的二进制值
- $currentBinaryValue = (Get-ItemProperty -Path $regPath -Name $valueName).$valueName
-
- if ($currentBinaryValue -is [byte[]]) {
- if ($currentBinaryValue.Length -ge 7064) {
- $currentBinaryValue[7064] = 0x04 # 0x04 就是十六进制表示的04,在PowerShell里修改字节数组中字节用十六进制赋值更方便理解
- # 将修改后的值重新设置回注册表
- Set-ItemProperty -Path $regPath -Name $valueName -Value $currentBinaryValue
- Write-Host "注册表中指定位置数值修改成功"
- }
- else {
- Write-Host "当前二进制值长度不足,无法进行指定位置修改"
- }
- }
-
- else {
- Write-Host "指定的注册表值不是二进制类型,无法进行操作"
- }
复制代码
作者: WHY 时间: 5 天前 21:37
本帖最后由 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.');
- }
复制代码
作者: wallat 时间: 4 天前 14:51
Test.bat,双击运行。
WHY 发表于 2024-12-23 21:37
实际上机测试了下,纯bat也可以修改,给大佬点赞!!
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |