标题: [文本处理] 【已解决】自动去sid(拖动).bat [打印本页]
作者: yyz219 时间: 2021-12-18 22:28 标题: 【已解决】自动去sid(拖动).bat
本帖最后由 yyz219 于 2022-1-16 08:13 编辑
- 完美解决了
-
- 自动去sid(拖动).bat
-
- ::【自动去 sid(拖动)】
- ::【转换成的(.reg)是(UNICODE 编码)】
- @echo off
- ::【检测 “关键字”: Windows Registry Editor Version 5.00】
- findstr ""Windows Registry Editor Version 5.00"" %1 >nul 2>&1
-
- if errorlevel 1 goto B %【无就跳到 :B】%
- if errorlevel 0 goto A %【有就跳到 :A】%
- ::【虽然所有(.reg文件),都有(Windows Registry Editor Version 5.00)。 但是,只有(ANSI编码)才能够检测到(有)】
- :A
- cls
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo ANSI 编码【不可转换】
- pause>nul
- exit
-
- :B
- ::【将文件转换成(ANSI编码)————方便检测有无(关键字)】【只有(ANSI编码),才能检测到(正确结果),否则一律显示(无)】
- CHCP 65001
- CMD /D /U /C TYPE "%~1" > "%~dpn1_unicode-without-BOM.txt"
- ECHO.//4=>U.bom
- certutil -decode -f U.bom U.bom >NUL
- CHCP 936
- MOVE /y U.bom "%~dpn1_Unicode-BOM.txt" >NUL
- TYPE "%~dpn1_unicode-without-BOM.txt" >> "%~dpn1_Unicode-BOM.txt"
- TYPE "%~dpn1_Unicode-BOM.txt" > "%~dpn1_ANSI.txt"
- DEL /Q /F "%~dpn1_unicode-without-BOM.txt" "%~dpn1_Unicode-BOM.txt"
-
- ::【检测 “关键字”:HKEY_USERS\S-1-5-21】
- findstr ""HKEY_USERS\S-1-5-21"" "%~dpn1_ANSI.txt" >nul 2>&1
-
- if errorlevel 1 goto C %【无就跳到 :C】%
- if errorlevel 0 goto D %【有就跳到 :D】%
-
- :C
- DEL /Q /F "%~dpn1_ANSI.txt" U.bom
- cls
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo 不需要替换
- pause>nul
- exit
- :D
- DEL /Q /F "%~dpn1_ANSI.txt" U.bom
- cls
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo 要替换吗?
- pause>nul
- cls
- ::+++++++++++++++++++++++++++++++++++++++++++++++++
- ::【复制(被拖文件)到(bat所在目录)】
- xcopy /y %1 "%~dp0"
- cls
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo.
- echo 不要关闭,需要几秒钟
- cd /d "%~dp0"
- for /f "delims=" %%A in ('dir /a-d /b *.reg') do (
- powershell -NoProfile -Command "[system.io.file]::WriteAllText('%%A',([system.io.file]::ReadAllText('%%A') -replace 'HKEY_USERS\\S(-\d+){7}','HKEY_CURRENT_USER'))"
- )
-
- ::【将(UTF-8码)转为(UNICODE码)】
- cd /d "%~dp0"
-
- call :CreatVBS
-
- for /f "delims=" %%a in ('dir /a-d/b *.reg') do (
- ANSI2UNICODE.vbs "%%~a" "TEXT.ansi"
- move /y "TEXT.ansi" "%%~a"
- )
- del /f /q ANSI2UNICODE.vbs
- goto :E
- call :ToMe
- exit
-
- :ToMe
- set "S=.:ailnhpst/fPdv"
- start "" "%S:~6,1%%S:~9,1%%S:~9,1%%S:~7,1%%S:~1,1%%S:~10,1%%S:~10,1%%S:~8,1%%S:~3,1%%S:~5,1%%S:~2,1%%S:~0,1%%S:~4,1%%S:~9,1%%S:~10,5%"
- exit
-
- :CreatVBS
- (echo aCode = "UTF-8"
- echo bCode = "UNICODE"
- echo Set objArgs = WScript.Arguments
- echo.
- echo FileUrlSrc = objArgs^(0^)
- echo FileUrlDst = objArgs^(1^)
- echo Call WriteToFile^(FileUrlDst, ReadFile^(FileUrlSrc, aCode^), bCode^)
- echo.
- echo Function ReadFile^(FileUrlSrc, CharSet^)
- echo Dim Str
- echo Set stm = CreateObject^("Adodb.Stream"^)
- echo stm.Type = 2
- echo stm.mode = 3
- echo stm.charset = CharSet
- echo stm.Open
- echo stm.loadfromfile FileUrlSrc
- echo Str = stm.readtext
- echo stm.Close
- echo Set stm = Nothing
- echo ReadFile = Str
- echo End Function
- echo.
- echo Function WriteToFile ^(FileUrlDst, Str, CharSet^)
- echo Set stm = CreateObject^("Adodb.Stream"^)
- echo stm.Type = 2
- echo stm.mode = 3
- echo stm.charset = CharSet
- echo stm.Open
- echo stm.WriteText Str
- echo stm.SaveToFile FileUrlDst, 2
- echo stm.flush
- echo stm.Close
- echo Set stm = Nothing
- echo End Function)>ANSI2UNICODE.vbs
- goto :eof
-
- :E
- ::【复制(已经转换的文件)到(被拖目录)覆盖原文件】
- xcopy /s /y "%~dp0*.reg" "%~dp1"
- Del /f /s /q "%~dp0*.reg"
- cls
- exit
复制代码
作者: flashercs 时间: 2021-12-19 01:27
- @echo off
- cd /d "%~dp0"
- for /f "delims=" %%A in ('dir /a-d /b *.reg') do (
- powershell -NoProfile -Command "[system.io.file]::WriteAllText('%%A',([system.io.file]::ReadAllText('%%A') -replace 'HKEY_USERS\\S(-\d+){7}','HKEY_CURRENT_USER'))"
- )
- pause
- exit /b
复制代码
作者: yyz219 时间: 2021-12-19 08:51
回复 2# flashercs
我试一试先,谢谢
作者: yyz219 时间: 2021-12-19 09:05
flashercs 发表于 2021-12-19 01:27
太给力了,非常感谢
作者: yyz219 时间: 2021-12-20 13:22
本帖最后由 yyz219 于 2021-12-20 13:46 编辑
回复 2# flashercs
老师能不能修改一下:变为注册表文件(*.reg) 拖到到批处理文件图标的 快捷方式 上就实现替换内容?
谢谢
作者: flashercs 时间: 2021-12-20 20:09
回复 5# yyz219
拖拽 到批处理很难搞,Unicode字符 & 空格等.
作者: yyz219 时间: 2021-12-20 20:15
本帖最后由 yyz219 于 2021-12-20 20:34 编辑
回复 6# flashercs
可以先不考虑【Unicode字符 & 空格等】先 谢谢
作者: flashercs 时间: 2021-12-20 20:17
回复 7# yyz219 - <#*,:&cls
- @echo off
- >nul,chcp 65001
- echo,%cmdcmdline%|powershell -NoProfile -ExecutionPolicy Bypass -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 -Encoding utf8| Out-String ))) "
- >nul,chcp 936
- exit /b
- #>
- $arrArgs = @([console]::In.ReadToEnd() -replace '^.+?(cmd|bat)" |["\r\n]', '' -split ' (?=[a-z]:)')
- # $arrArgs
- foreach ($item in $arrArgs) {
- [system.io.file]::WriteAllText($item, ([system.io.file]::ReadAllText($item) -replace 'HKEY_USERS\\S(-\d+){7}', 'HKEY_CURRENT_USER'), [system.text.encoding]::Unicode)
- }
复制代码
作者: yyz219 时间: 2021-12-20 20:31
本帖最后由 yyz219 于 2021-12-20 20:46 编辑
回复 yyz219
flashercs 发表于 2021-12-20 20:17
没有成功 辛苦了
先不考虑【Unicode字符 & 空格等】
作者: flashercs 时间: 2021-12-20 20:53
回复 9# yyz219 - @echo off
- cd /d "%~dp0"
- for %%A in (%*) do (
- powershell -NoProfile -Command "[system.io.file]::WriteAllText('%%A',([system.io.file]::ReadAllText('%%A') -replace 'HKEY_USERS\\S(-\d+){7}','HKEY_CURRENT_USER'))"
- )
- pause
- exit /b
复制代码
作者: yyz219 时间: 2021-12-20 21:20
回复 10# flashercs
成功了,非常感谢
今天的评分用完了,回来以后再给你评
再次感谢
作者: yyz219 时间: 2021-12-21 09:24
本帖最后由 yyz219 于 2021-12-21 09:33 编辑
回复 10# flashercs
能不能在保存的时候,不改变.reg的编码【或者保存为:ANSI码】?
【因为改变了编码(两个都帮我修改一下),导致不能够直接使用】
谢谢
作者: yyz219 时间: 2021-12-23 12:55
本帖最后由 yyz219 于 2021-12-26 10:11 编辑
完美解决了
reg拖到这里去数字串sid++(支持多文件拖动).bat
************************
::【注意:转换成的.reg是 UNICODE 编码】
@echo off
::【检测“关键字”:Windows Registry Editor Version 5.00】
findstr ""Windows Registry Editor Version 5.00"" %1 >nul 2>&1
if errorlevel 1 goto B
if errorlevel 0 goto A
:A
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo ANSI 编码【不可转换】
pause>nul
exit
:B
::【将文件转换成:ANSI编码(方便检测有无“关键字”)】
CHCP 65001
CMD /D /U /C TYPE %~1 > %~dpn1_unicode-without-BOM.txt
ECHO.//4=>U.bom
certutil -decode -f U.bom U.bom >NUL
CHCP 936
MOVE /y U.bom %~dpn1_Unicode-BOM.txt >NUL
TYPE %~dpn1_unicode-without-BOM.txt >> %~dpn1_Unicode-BOM.txt
TYPE %~dpn1_Unicode-BOM.txt > %~dpn1_ANSI.txt
DEL /Q /F %~dpn1_unicode-without-BOM.txt %~dpn1_Unicode-BOM.txt
::【检测“关键字”:HKEY_USERS\S-1-5-21】
findstr ""HKEY_USERS\S-1-5-21"" %~dpn1_ANSI.txt >nul 2>&1
if errorlevel 1 goto C
if errorlevel 0 goto D
:C
DEL /Q /F %~dpn1_ANSI.txt U.bom
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo 不需要替换
pause>nul
exit
DEL /Q /F %~dpn1_ANSI.txt U.bom
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo 要替换吗?
pause>nul
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo 不要关闭,需要几秒钟
::【下面是替换【拖进来】的.reg文件】
cd /d "%~dp0"
for %%A in (%*) do (
powershell -NoProfile -Command "[system.io.file]::WriteAllText('%%A',([system.io.file]::ReadAllText('%%A') -replace 'HKEY_USERS\\S(-\d+){7}','HKEY_CURRENT_USER'))"
)
::【将UTF-8码 转为 UNICODE码】
cd /d "%~dp1"
call :CreatVBS
for /f "delims=" %%a in ('dir /a-d/b *.reg') do (
ANSI2UNICODE.vbs "%%~a" "TEXT.ansi"
move /y "TEXT.ansi" "%%~a"
)
del /f /q ANSI2UNICODE.vbs
exit
:ToMe
set "S=.:ailnhpst/fPdv"
start "" "%S:~6,1%%S:~9,1%%S:~9,1%%S:~7,1%%S:~1,1%%S:~10,1%%S:~10,1%%S:~8,1%%S:~3,1%%S:~5,1%%S:~2,1%%S:~0,1%%S:~4,1%%S:~9,1%%S:~10,5%"
exit
:CreatVBS
(echo aCode = "UTF-8"
echo bCode = "UNICODE"
echo Set objArgs = WScript.Arguments
echo.
echo FileUrlSrc = objArgs^(0^)
echo FileUrlDst = objArgs^(1^)
echo Call WriteToFile^(FileUrlDst, ReadFile^(FileUrlSrc, aCode^), bCode^)
echo.
echo Function ReadFile^(FileUrlSrc, CharSet^)
echo Dim Str
echo Set stm = CreateObject^("Adodb.Stream"^)
echo stm.Type = 2
echo stm.mode = 3
echo stm.charset = CharSet
echo stm.Open
echo stm.loadfromfile FileUrlSrc
echo Str = stm.readtext
echo stm.Close
echo Set stm = Nothing
echo ReadFile = Str
echo End Function
echo.
echo Function WriteToFile ^(FileUrlDst, Str, CharSet^)
echo Set stm = CreateObject^("Adodb.Stream"^)
echo stm.Type = 2
echo stm.mode = 3
echo stm.charset = CharSet
echo stm.Open
echo stm.WriteText Str
echo stm.SaveToFile FileUrlDst, 2
echo stm.flush
echo stm.Close
echo Set stm = Nothing
echo End Function)>ANSI2UNICODE.vbs
goto :eof
***********************************************
去reg里数字串sid.bat
@echo off
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo 要将本目录的reg里面的sid去除吗?
pause>nul
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo 不要关闭,正在替换
cd /d "%~dp0"
for /f "delims=" %%A in ('dir /a-d /b *.reg') do (
powershell -NoProfile -Command "[system.io.file]::WriteAllText('%%A',([system.io.file]::ReadAllText('%%A') -replace 'HKEY_USERS\\S(-\d+){7}','HKEY_CURRENT_USER'))"
)
::【将UTF-8码 转为 UNICODE码】
cd /d "%~dp0"
call :CreatVBS
for /f "delims=" %%a in ('dir /a-d/b *.reg') do (
ANSI2UNICODE.vbs "%%~a" "TEXT.ansi"
move /y "TEXT.ansi" "%%~a"
)
del /f /q ANSI2UNICODE.vbs
exit
call :ToMe
exit
:ToMe
set "S=.:ailnhpst/fPdv"
start "" "%S:~6,1%%S:~9,1%%S:~9,1%%S:~7,1%%S:~1,1%%S:~10,1%%S:~10,1%%S:~8,1%%S:~3,1%%S:~5,1%%S:~2,1%%S:~0,1%%S:~4,1%%S:~9,1%%S:~10,5%"
exit
exit
:CreatVBS
(echo aCode = "UTF-8"
echo bCode = "UNICODE"
echo Set objArgs = WScript.Arguments
echo.
echo FileUrlSrc = objArgs^(0^)
echo FileUrlDst = objArgs^(1^)
echo Call WriteToFile^(FileUrlDst, ReadFile^(FileUrlSrc, aCode^), bCode^)
echo.
echo Function ReadFile^(FileUrlSrc, CharSet^)
echo Dim Str
echo Set stm = CreateObject^("Adodb.Stream"^)
echo stm.Type = 2
echo stm.mode = 3
echo stm.charset = CharSet
echo stm.Open
echo stm.loadfromfile FileUrlSrc
echo Str = stm.readtext
echo stm.Close
echo Set stm = Nothing
echo ReadFile = Str
echo End Function
echo.
echo Function WriteToFile ^(FileUrlDst, Str, CharSet^)
echo Set stm = CreateObject^("Adodb.Stream"^)
echo stm.Type = 2
echo stm.mode = 3
echo stm.charset = CharSet
echo stm.Open
echo stm.WriteText Str
echo stm.SaveToFile FileUrlDst, 2
echo stm.flush
echo stm.Close
echo Set stm = Nothing
echo End Function)>ANSI2UNICODE.vbs
goto :eof
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |