[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 【已解决】批处理删除 某一段代码

本帖最后由 lovekix 于 2023-7-19 19:13 编辑

比如我有一段代码
]通过批处理  能删除吗?  每次都手动查找 然后删除太麻烦
  1. <Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">
  2. <uap:VisualElements DisplayName="ms-resource:WindowsBackup/Resources/WindowsBackupHostName" Description="ms-resource:WindowsBackup/Resources/WindowsBackupDescription" Square150x150Logo="WindowsBackup\Assets\MedTile.png" Square44x44Logo="WindowsBackup\Assets\AppList.png" BackgroundColor="transparent">
  3. ...
  4. </uap:VisualElements>
  5. <Extensions>
  6. <uap:Extension Category="windows.protocol">
  7. <uap:Protocol Name="ms-windowsbackup" ReturnResults="optional"/>
  8. </uap:Extension>
  9. <uap3:Extension Category="windows.appExtension">
  10. <uap3:AppExtension Name="com.microsoft.windows.extensionpackage" Id="WindowsBackup" DisplayName="Extension Metadata">
  11. <uap3:Properties>
  12. <PackageAliases>
  13. <PackageAlias>WindowsBackupAlias</PackageAlias>
  14. </PackageAliases>
  15. </uap3:Properties>
  16. </uap3:AppExtension>
  17. </uap3:Extension>
  18. <uap3:Extension Category="windows.appExtension">
  19. <uap3:AppExtension Name="com.microsoft.windows.app.windowsbackup" Id="WindowsBackup" DisplayName="Extension Metadata"/>
  20. </uap3:Extension>
  21. <uap3:Extension Category="windows.appExtension">
  22. <uap3:AppExtension Name="com.microsoft.windows.extensions.xaml" Id="WindowsBackup" DisplayName="Microsoft Windows Extensions">
  23. <uap3:Properties>
  24. <Classes>
  25. <WindowsBackupControl>WindowsBackup.WindowsBackupControl</WindowsBackupControl>
  26. </Classes>
  27. <MetadataProviders>
  28. <Provider>WindowsBackup.XamlMetaDataProvider</Provider>
  29. </MetadataProviders>
  30. <ResourceDictionaries>
  31. <ResourceDictionary>WindowsBackup.WindowsBackupResources</ResourceDictionary>
  32. </ResourceDictionaries>
  33. </uap3:Properties>
  34. </uap3:AppExtension>
  35. </uap3:Extension>
  36. </Extensions>
  37. <uap:ApplicationContentUriRules>
  38. <uap:Rule Type="include" Match="https://login.live.com/"/>
  39. <uap:Rule Type="include" Match="https://signup.live.com/"/>
  40. <uap:Rule Type="include" Match="https://account.live.com/"/>
  41. </uap:ApplicationContentUriRules>
  42. </Application>
复制代码
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

回复 37# lovekix
可以将echo %%b改成echo;%%b试一下

另外,要加关键词 第4至8行这样改
  1. set "str3=<Application Id="FESearchUI" Executable="FESearchHost.exe" EntryPoint="CortanaUI.App">"
  2. set "str1=%str1:"=\"%"
  3. set "str2=%str2:"=\"%"
  4. set "str3=%str3:"=\"%"
  5. for /f "delims=:" %%a in ('findstr /ibnrc:"[ ]*%str1%"   /c:"[ ]*%str2%"  /c:"[ ]*%str3%" "appxmanifest.xml"') do set _%%a=1
复制代码

TOP

本帖最后由 lovekix 于 2023-12-2 16:24 编辑

回复 36# terse


要是  以后删除第三段  代码 需要怎么弄?

还有 莫名多出  2个   ECHO 处于关闭状态

TOP

回复 34# lovekix
PE下没测试,35楼是想是删除两节吗
  1. @echo off
  2. set "str1=<Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10/*[0-9]*:TrustLevel="mediumIL" uap10/*[0-9]*:RuntimeBehavior="windowsApp">"
  3. set "str2=<Application Id="WebExperienceHost" Executable="WebExperienceHostApp.exe" EntryPoint="WebExperienceHostApp.App""
  4. set "str1=%str1:"=\"%"
  5. set "str2=%str2:"=\"%"
  6. for /f "delims=:" %%a in ('findstr /ibnrc:"[ ]*%str1%"   /c:"[ ]*%str2%" "appxmanifest.xml"') do set _%%a=1
  7. set "flag="
  8. (for /f "tokens=1* delims=:" %%a in ('findstr /n .* "appxmanifest.xml"') do (
  9.      if defined flag (
  10.            for /f %%i in ("%%b") do  if "%%i" == "</Application>" set "flag="
  11.      ) else if defined _%%a (
  12.            set "flag=1"
  13.      ) else echo %%b
  14. ))>new_appxmanifest.xml
  15. pause
复制代码

TOP

回复 28# 77七


    如果想多删除
<Application Id="WebExperienceHost" Executable="WebExperienceHostApp.exe" EntryPoint="WebExperienceHostApp.App"
这段

需要 怎么弄?

TOP

回复 33# terse


    PE 下没有cscript。exe 这个文件

TOP

回复 32# lovekix
怎么后面跟个v? 将代码里cscript改为cscript.exe试,或者检测一下,
  1. for %%i in (cscript.exe) do echo;文件路径 %%~$PATH:i
复制代码

TOP

回复 31# terse


    cscript v 不是内部命令

TOP

本帖最后由 terse 于 2023-12-1 19:39 编辑

直接删除节点呢 修改把文件名传进去
  1. @set @n=0;/* & echo off & cscript -nologo -e:jscript "%~0" "appxmanifest.xml" "appxmanifest2.xml"&pause & exit  */
  2. var xml = new ActiveXObject("Msxml2.DOMDocument");
  3. xml.load(WScript.Arguments(0));
  4. var node = xml.selectSingleNode("//Application[@Id='WindowsBackup' and @Executable='WindowsBackupClient.exe' and @EntryPoint='WindowsBackup.App']");
  5. if (node != null) {
  6.     node.parentNode.removeChild(node);
  7. }
  8. xml.save(WScript.Arguments(1));
复制代码

TOP

回复 29# lovekix


   .*
前面加个.
bat小白,请多指教!谢谢!

TOP

回复 28# 77七

这行代码  可以用* 代替后面的吗?
  1. set "str1=<Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10[/]*[4]*:TrustLevel="mediumIL" uap10[/]*[4]*:RuntimeBehavior="windowsApp">"
复制代码
  1. set "str1=<Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App"*>"
复制代码

TOP

本帖最后由 77七 于 2023-12-1 14:54 编辑

回复 27# lovekix


  1. @echo off
  2. set "str1=<Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10[/]*[4]*:TrustLevel="mediumIL" uap10[/]*[4]*:RuntimeBehavior="windowsApp">"
  3. set "str2=</Application>"
  4. set "str1=%str1:"="""%"
  5. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"[ ]*%str1%" "appxmanifest.xml"') do set start=%%a
  6. for /f "tokens=1 delims=:" %%a in ('findstr /nxr /c:"[ ]*%str2%" "appxmanifest.xml"') do (
  7. if %%a gtr %start% (
  8. set end=%%a
  9. goto :next
  10. )
  11. )
  12. :next
  13. (for /f "tokens=1* delims=:" %%a in ('findstr /n .* "appxmanifest.xml"') do (
  14. if %%a lss %start% echo=%%b
  15. if %%a gtr %end% echo=%%b
  16. ))>"appxmanifest-2.xml"
  17. pause
复制代码
bat小白,请多指教!谢谢!

TOP

本帖最后由 lovekix 于 2023-12-1 08:52 编辑

回复 26# 77七


https://wwrj.lanzouu.com/i461Y1ggo9zc

TOP

回复 25# lovekix


   请把出现问题的文件传上来,看看是什么原因。
bat小白,请多指教!谢谢!

TOP

回复 9# 77七


    微软总把 制表符  换成  空格   (有时候 9个   有时候8个)

有时候  还在会把
<Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10:TrustLevel="mediumIL" uap10:RuntimeBehavior="windowsApp">"

替换成
<Application Id="WindowsBackup" Executable="WindowsBackupClient.exe" EntryPoint="WindowsBackup.App" uap10/4:TrustLevel="mediumIL" uap10/4:RuntimeBehavior="windowsApp">"

还有其他办法吗?

TOP

返回列表