我想在注册表值中搜索“United States”,如果存在则运行.bat
文件,否则退出脚本。
Reg键:
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Distinguished-Name"
Reg Value:(其中US = United States)
CN=machinename,OU=Computers,OU=US,OU=Sites,DC=brand,DC=com
我的powershell脚本:
$Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Distinguished-Name" -Recurse |
ForEach-Object {if ($_ -match "United States"){start-process "C:\US_Keyboard_Remove\US_Keyboard_Remove_ActivSetup.bat"}}
我的批处理脚本:
$set "key=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Distinguished-Name"
set "search=United States"
for /f "delims=" %%a in ('reg query "%key%" /s^| findstr "%search%"') do reg delete "%key%" /v "%%~a"
请帮我修复代码。
答案 0 :(得分:0)
以下批处理脚本示例应该只运行您指定的命令'如果找到了搜索字符串:
@Echo Off
Set "Key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine"
Set "Val=Distinguished-Name"
Set "Str=OU=US"
Reg Query "%Key%" /V "%Val%" | Find /I "%Str%" > Nul || GoTo :EOF
Rem your specified commands below here
如果您需要运行指定的命令'如果找不到%Str%
,请将||
上的5
更改为&&
。