
标题: [文本处理] 批处理怎么修改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
- @echo off
- chcp 65001
- for /f "tokens=2" %%a in ('whoami/all^|findstr "S-.*-.*-.*-.*-.*-.*-.*"') do (
- (for /f "delims=" %%b in (1.xml) do (
- echo;"%%b"|findstr "<UserId>S-1-5-21-409824130-384522784-1604236090-1000</UserId>">nul&&echo;^<UserId^>%%a^</UserId^>||echo;%%b
- ))>2.xml
- )
- move /y 2.xml 1.xml
- pause
复制代码
作者: fly9902 时间: 2021-8-24 13:53
回复 2# idwma
非常谢谢,但是最后得到一个空白的1.xml,啥也没有,继续请教
作者: idwma 时间: 2021-8-24 14:18
回复 3# fly9902 - @echo off
- chcp 65001
- for /f "tokens=2" %%a in ('whoami/all^|findstr "S-.*-.*-.*-.*-.*-.*-.*"') do (
- (for /f "tokens=1* delims=<" %%b in (1.xml) do (
- if "%%c"=="UserId>S-1-5-21-409824130-384522784-1604236090-1000</UserId>" (
- echo;^<UserId^>%%a^</UserId^>
- ) else (echo;%%b^<%%c)
- ))>2.xml
- )
- 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 - @echo off
- chcp 65001
- for /f "tokens=2 delims=\" %%a in ('reg query hku^|findstr "1000$"') do (
- (for /f "delims=" %%b in (1.xml) do (
- echo;"%%b"|findstr "<UserId>S-1-5-21-409824130-384522784-1604236090-1000</UserId>">nul&&echo;^<UserId^>%%a^</UserId^>||echo;%%b
- ))>2.xml
- )
复制代码
作者: idwma 时间: 2021-8-24 16:27
回复 5# fly9902 - @echo off
- setlocal enabledelayedexpansion
- chcp 65001>nul
- for /f "tokens=2 delims=\" %%a in ('reg query hku^|findstr "1000$"') do (
- (for /f "delims=" %%b in (1.xml) do (
- set str=%%b
- echo;!str:S-1-5-21-409824130-384522784-1604236090-1000=%%a!
- ))
- )
- 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 |