Hey everyone, I'm trying to find a solution to this problem. Basically, I'm trying to create an if/else if argument in a batch that does the following:
1.) If the following registry value exist /v AllowRemoteRPC /t REG_DWORD /d 1 in "hklm\system\currentcontrolset\control\terminal server" then move on to :sendmessage
2.) If it does not exist, then prompt the user to run the regfix.bat file
I have something like this (Mind you, I'm still learning the ways of batch scripting, so if it seems newbish I apologize)
:regcheck
echo ===========================================================================
echo Checking Registry of %enduser%
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
reg query "\\%enduser%\hklm\system\currentcontrolset\control\terminal server" /v AllowRemoteRPC
if %errorlevel% == 0 (
echo ===========================================================================
echo Okay! %enduser% is set for receiving Administrator Messages
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
cls
goto :sendmessage
) else if %errorlevel% == 1 (
echo ===========================================================================
echo %enduser% does not have the Registry Fix, please run regfix.bat!
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 5000
goto :quit
Should I use a findstr? I've seen a lot of this For /F stuff but honestly, I'm having a hard time finding someone or website explaining to me how I can use it.
Any help is appreciated!
Findstr in Registry
Moderator: DosItHelp
Re: Findstr in Registry
) ELSE ( IF .......
Re: Findstr in Registry
No dice :-/
did the following modification
:regcheck
echo ===========================================================================
echo Checking Registry of %enduser%
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
reg query "\\%enduser%\hklm\system\currentcontrolset\control\terminal server" /v AllowRemoteRPC
if %errorlevel% == 0 (
echo ===========================================================================
echo Okay! %enduser% is set for receiving Administrator Messages
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
cls
goto :sendmessage
) else ( if %errorlevel% == 1 (
echo ===========================================================================
echo %enduser% does not have the Registry Fix, please run regfix.bat!
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 5000
)
goto :quit
did the following modification
:regcheck
echo ===========================================================================
echo Checking Registry of %enduser%
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
reg query "\\%enduser%\hklm\system\currentcontrolset\control\terminal server" /v AllowRemoteRPC
if %errorlevel% == 0 (
echo ===========================================================================
echo Okay! %enduser% is set for receiving Administrator Messages
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
cls
goto :sendmessage
) else ( if %errorlevel% == 1 (
echo ===========================================================================
echo %enduser% does not have the Registry Fix, please run regfix.bat!
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 5000
)
goto :quit
Re: Findstr in Registry
You don't need to check the errorlevel after the else. You already know it is not zero if it executes the else.
Re: Findstr in Registry
'
I'm not that good as you that I could go without indention
No need to check errorLevels, reg query only returns True or False.
ps: according to MS, it's not a bug, it's a feature !
I'm not that good as you that I could go without indention
Code: Select all
:regcheck
echo ===========================================================================
echo Checking Registry of %enduser%
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
:: sending stderr to nul device, I'll echo a custom message later...
2>nul reg query "\\%enduser%\hklm\system\currentcontrolset\control\terminal server" /v AllowRemoteRPC &&(
echo ===========================================================================
echo Okay! %enduser% is set for receiving Administrator Messages
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
cls
goto :sendmessage
) || (
echo ===========================================================================
echo %enduser% does not have the Registry Fix, please run regfix.bat!
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 5000
)
goto :quit
:sendmessage ...
:quit ...
pause
exit
ps: according to MS, it's not a bug, it's a feature !
Re: Findstr in Registry
Good use of the batch operators there Ed.
Re: Findstr in Registry
Works like a charm! Thank you! I'm still trying to learn as much as I can so I can actually be of benefit on these forums rather than mooching
Thank you again!
Thank you again!