Board logo

标题: [注册表类] 批处理命令reg add如何添加reg_none类型的数据? [打印本页]

作者: hentai87    时间: 2023-4-17 20:55     标题: 批处理命令reg add如何添加reg_none类型的数据?

本帖最后由 hentai87 于 2023-4-18 18:42 编辑

这是是原本导出的正确数据
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SECURITY\Policy\Accounts\S-1-1-0\Privilgs]
@=hex(0):01,00,00,00,00,00,00,00,17,00,00,00,00,00,00,00,03,00,00,00
  1. reg add "HKEY_LOCAL_MACHINE\SECURITY\Policy\Accounts\S-1-1-0\Privilgs" /ve /t reg_none /d "01,00,00,00,00,00,00,00,17,00,00,00,00,00,00,00,03,00,00,00" /f
复制代码
这样导入的数据是错误的,无法直接用导出的数据直接reg add
reg add之后,数据不对,导出数据变了,错误的
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SECURITY\Policy\Accounts\S-1-1-0\Privilgs]
@=hex(0):68,00,65,00,78,00,28,00,30,00,29,00,3a,00,30,00,31,00,2c,00,30,00,30,\
  00,2c,00,30,00,30,00,2c,00,30,00,30,00,2c,00,30,00,30,00,2c,00,30,00,30,00,\
  2c,00,30,00,30,00,2c,00,30,00,30,00,2c,00,31,00,37,00,2c,00,30,00,30,00,2c,\
  00,30,00,30,00,2c,00,30,00,30,00,2c,00,30,00,30,00,2c,00,30,00,30,00,2c,00,\
  30,00,30,00,2c,00,30,00,30,00,2c,00,30,00,33,00,2c,00,30,00,30,00,2c,00,30,\
  00,30,00,2c,00,30,00,30,00,00,00
作者: chishingchan    时间: 2023-4-17 21:19

  1. reg add "HKLM\SECURITY\Policy\Accounts\S-1-1-0\Privilgs" /f /ve /t REG_NONE /d 01,00,00,00,00,00,00,00,17,00,00,00,00,00,00,00,03,00,00,00
复制代码

作者: hentai87    时间: 2023-4-17 21:21

回复 2# chishingchan


    导入之后数据不对,逗号,空格,不加符号,都试过了,都不行
作者: newswan    时间: 2023-4-17 21:31

应该是 REG_BINARY
作者: hentai87    时间: 2023-4-17 22:26

回复 4# newswan


    换成REG_BINARY,虽然数据对了,但是注册表设置没能生效,类型必须是reg_none
作者: yakeyun    时间: 2023-4-17 22:41

回复 1# hentai87
  1. reg add "" /v @ /t REG_SZ /d hex(0):01,00,00,00,00,00,00,00,17,00,00,00,00,00,00,00,03,00,00,00 /f
复制代码

作者: hentai87    时间: 2023-4-17 22:44

回复 6# yakeyun


    错误: 无效项名。
键入 "REG ADD /?" 了解用法信息。
作者: newswan    时间: 2023-4-17 22:59

本帖最后由 newswan 于 2023-4-18 16:58 编辑

回复 5# hentai87

reg add 不行的话,用 reg IMPORT *.reg

powershell 可以
  1. [byte[]]$a = @("00","03","15")
  2. New-ItemProperty -Path "HKLM:\Software\zzz" -Name "aaa" -Type None -Value $a
复制代码

作者: yakeyun    时间: 2023-4-18 13:10

本帖最后由 yakeyun 于 2023-4-18 13:12 编辑

回复 7# hentai87

路径漏了,再加个提权看看,普通权限和管理员权限各执行一次:
  1. @echo off
  2. reg add "HKLM\SECURITY\Policy\Accounts\S-1-1-0\Privilgs" /v @ /t REG_SZ /d hex(0):01,00,00,00,00,00,00,00,17,00,00,00,00,00,00,00,03,00,00,00 /f
  3. %1 %2
  4. ver|find "5.">nul&&goto :Admin
  5. mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :Admin","","runas",1)(window.close)&goto :eof
  6. :Admin
  7. reg add "HKLM\SECURITY\Policy\Accounts\S-1-1-0\Privilgs" /v @ /t REG_SZ /d hex(0):01,00,00,00,00,00,00,00,17,00,00,00,00,00,00,00,03,00,00,00 /f
  8. exit
复制代码
从测试来看,应该是要超级权限才行。
作者: hentai87    时间: 2023-4-18 18:41

回复 9# yakeyun


    类型必须是reg_none
作者: hentai87    时间: 2023-4-18 18:45

回复 8# newswan


  [byte[]]$a = @("00","03","15")
New-ItemProperty -Path "HKLM:\SECURITY\Policy\Accounts\S-1-1-0\Privilgs" -Name "@" -Type None -Value $a

New-ItemProperty : 该属性已存在。
所在位置 行:1 字符: 1
+ New-ItemProperty -Path "HKLM:\SECURITY\Policy\Accounts\S-1-1-0\Privil ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceExists: (HKEY_LOCAL_MACH...-1-1-0\Privilgs:String) [New-ItemProperty], IOExcepti
   on
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.NewItemPropertyCommand
作者: hentai87    时间: 2023-4-18 18:46

回复 9# yakeyun


    不用提权,我已经解锁了权限
作者: hentai87    时间: 2023-4-18 18:47

回复 8# newswan


regedit.exe/s可以导入reg文件成功修改,但是我想不用额外文件,直接命令实现
作者: newswan    时间: 2023-4-18 19:04

本帖最后由 newswan 于 2023-4-18 21:18 编辑
  1. [byte[]]$a = @("00","03","15")
  2. Remove-ItemProperty -Path "HKLM:\SECURITY\Policy\Accounts\S-1-1-0\Privilgs" -Name "(Default)"
  3. New-ItemProperty -Path "HKLM:\SECURITY\Policy\Accounts\S-1-1-0\Privilgs" -Name "(Default)" -Type None -Value $a
复制代码

作者: hentai87    时间: 2023-4-18 19:34

回复 14# newswan

Remove-ItemProperty : 路径 HKEY_LOCAL_MACHINE\SECURITY\Policy\Accounts\S-1-1-0\Privilgs 处不存在属性 (Default)。
所在位置 行:1 字符: 1
+ Remove-ItemProperty -Path "HKLM:\SECURITY\Policy\Accounts\S-1-1-0\Pri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: ((Default):String) [Remove-ItemProperty],PSArgumentException
    + FullyQualifiedErrorId : System.Management.Automation.PSArgumentException,Microsoft.PowerShell.Commands.RemoveIte
   mPropertyCommand
作者: newswan    时间: 2023-4-18 21:17

本帖最后由 newswan 于 2023-4-18 21:19 编辑

回复 15# hentai87


Remove-ItemProperty 是删除 value ,错误可以忽略
New-ItemProperty 不出错就行
作者: hentai87    时间: 2023-4-19 23:35

回复 16# newswan


    New-ItemProperty后的数据不对
作者: newswan    时间: 2023-4-20 00:27

本帖最后由 newswan 于 2023-4-20 03:11 编辑

测试正确的啊
https://imgse.com/i/p9kE4R1
  1. [byte[]]$a = @("00","03","15")
  2. Set-ItemProperty -Path "HKLM:\SECURITY\Policy\Accounts\S-1-1-0\Privilgs" -Name "(Default)" -Type None -Value $a
复制代码
用 set-ItemProperty 试试
作者: hentai87    时间: 2023-4-20 22:03

回复 18# newswan


Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SECURITY\Policy\Accounts\S-1-1-0\Privilgs]
@=hex(0):00,03,0f

执行后,数据是这个
作者: newswan    时间: 2023-4-20 23:12

回复 19# hentai87
  1. [byte[]]$a = @("00","03","15")
复制代码
改这里啊
作者: hentai87    时间: 2023-4-20 23:27

回复 20# newswan


[byte[]]$a = @("01","00","00","00","00","00","00","00","17","00","00","00","00","00","00","00","03","00","00","00")
Set-ItemProperty -Path "HKLM:\SECURITY\Policy\Accounts\S-1-1-0\Privilgs" -Name "(Default)" -Type None -Value $a
还是不对,明明是17,却变成了11
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SECURITY\Policy\Accounts\S-1-1-0\Privilgs]
@=hex(0):01,00,00,00,00,00,00,00,11,00,00,00,00,00,00,00,03,00,00,00
应该是17
@=hex(0):01,00,00,00,00,00,00,00,17,00,00,00,00,00,00,00,03,00,00,00
作者: newswan    时间: 2023-4-21 00:42

本帖最后由 newswan 于 2023-4-21 01:02 编辑

回复 21# hentai87


十进制 17 转成了十六进制 11
  1. $str = "01,00,00,00,00,00,00,00,17,00,00,00,00,00,00,00,03,00,00,00"
  2. [byte[]]$a = $str -replace "(?=\d\d)","0x" -split ","
  3. set-ItemProperty -Path $path -Name "(Default)" -Type None -Value $a
复制代码

作者: hentai87    时间: 2023-4-22 22:30

回复 22# newswan


    Set-ItemProperty : 无法将参数绑定到参数“Path”,因为该参数是空值。
所在位置 行:1 字符: 24
+ set-ItemProperty -Path $path -Name "(Default)" -Type None -Value $a
+                        ~~~~~
    + CategoryInfo          : InvalidData: ( [Set-ItemProperty],ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetItemProp
   ertyCommand
作者: newswan    时间: 2023-4-28 10:20

回复 23# hentai87

那是不完整的, 对比你已有代码, 添加一句
  1. $path = "HKLM:\SECURITY\Policy\Accounts\S-1-1-0\Privilgs"
复制代码
或者
  1. Set-ItemProperty -Path "HKLM:\SECURITY\Policy\Accounts\S-1-1-0\Privilgs" -Name "(Default)" -Type None -Value $a
复制代码

作者: hentai87    时间: 2023-4-30 15:57

回复 24# newswan


    可以了,
有办法bat实现吗
作者: newswan    时间: 2023-4-30 22:08

第一行加上下面一句,保存为bat
  1. @cd /d %~dp0 & powershell -command "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause & exit/b
复制代码
回复 25# hentai87




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2