Board logo

标题: [文本处理] 批处理怎么修改xml文件中的SID修改为当前账户的SID值? [打印本页]

作者: fly9902    时间: 2021-8-24 12:08     标题: 批处理怎么修改xml文件中的SID修改为当前账户的SID值?

例如 1.xml 文件中包含:

  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-409824130-384522784-1604236090-1000</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>

如何用批处理把  S-1-5-21-409824130-384522784-1604236090-1000  修改为电脑当前账户的SID?
作者: idwma    时间: 2021-8-24 13:18

  1. @echo off
  2. chcp 65001
  3. for /f "tokens=2" %%a in ('whoami/all^|findstr "S-.*-.*-.*-.*-.*-.*-.*"') do (
  4. (for /f "delims=" %%b in (1.xml) do (
  5.   echo;"%%b"|findstr "<UserId>S-1-5-21-409824130-384522784-1604236090-1000</UserId>">nul&&echo;^<UserId^>%%a^</UserId^>||echo;%%b
  6. ))>2.xml
  7. )
  8. move /y 2.xml 1.xml
  9. pause
复制代码

作者: fly9902    时间: 2021-8-24 13:53

回复 2# idwma

非常谢谢,但是最后得到一个空白的1.xml,啥也没有,继续请教
作者: idwma    时间: 2021-8-24 14:18

回复 3# fly9902
  1. @echo off
  2. chcp 65001
  3. for /f "tokens=2" %%a in ('whoami/all^|findstr "S-.*-.*-.*-.*-.*-.*-.*"') do (
  4. (for /f "tokens=1* delims=<" %%b in (1.xml) do (
  5.   if "%%c"=="UserId>S-1-5-21-409824130-384522784-1604236090-1000</UserId>" (
  6. echo;^<UserId^>%%a^</UserId^>
  7. ) else (echo;%%b^<%%c)
  8. ))>2.xml
  9. )
  10. pause
复制代码

作者: fly9902    时间: 2021-8-24 15:16

回复  fly9902
idwma 发表于 2021-8-24 14:18



    非常感谢,但依然输出一个空白的文件,
作者: Batcher    时间: 2021-8-24 15:22

回复 5# fly9902


请检查一下你的bat和xml分别是什么编码格式,参考:
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
作者: idwma    时间: 2021-8-24 15:24

回复 5# fly9902
  1. @echo off
  2. chcp 65001
  3. for /f "tokens=2 delims=\" %%a in ('reg query hku^|findstr "1000$"') do (
  4. (for /f "delims=" %%b in (1.xml) do (
  5.   echo;"%%b"|findstr "<UserId>S-1-5-21-409824130-384522784-1604236090-1000</UserId>">nul&&echo;^<UserId^>%%a^</UserId^>||echo;%%b
  6. ))>2.xml
  7. )
复制代码

作者: idwma    时间: 2021-8-24 16:27

回复 5# fly9902
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. chcp 65001>nul
  4. for /f "tokens=2 delims=\" %%a in ('reg query hku^|findstr "1000$"') do (
  5. (for /f "delims=" %%b in (1.xml) do (
  6. set str=%%b
  7. echo;!str:S-1-5-21-409824130-384522784-1604236090-1000=%%a!
  8. ))
  9. )
  10. pause
复制代码

作者: fly9902    时间: 2021-8-24 16:27

回复  fly9902
idwma 发表于 2021-8-24 15:24




感谢,成功了
作者: fly9902    时间: 2021-8-24 16:27

回复  fly9902
idwma 发表于 2021-8-24 15:24



    感谢,成功了




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