Registry Query not working correctly :-/

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Registry Query not working correctly :-/

#16 Post by Ed Dyreen » 14 Aug 2012 12:19

abc0502 wrote:variables are case sensitive
That's obviously wrong

Code: Select all

set _var=world
set _VAR=hello
set _
abc0502 wrote:Edit, and one more thing, in this command you should add the double Quotes
set /p "Enduser=Please enter end-user IP address or Machine Name: "
Why ?

Code: Select all

>set /p Enduser=Please enter end-user IP address or Machine Name: 
Please enter end-user IP address or Machine Name: ttt

>set end
Enduser=ttt

>set /p this works=enter input:
enter input: yes

>set this
this works=yes

>

sourbread
Posts: 23
Joined: 26 Apr 2012 09:10

Re: Registry Query not working correctly :-/

#17 Post by sourbread » 14 Aug 2012 12:21

Squashman wrote:
abc0502 wrote:ok try this remove the 2>nul at the begining and add it at the end like this

Code: Select all

rcmd \\%enduser% reg query "hkcr\mime\database\content type\image/tiff" /v CLSID >nul &&(

i don't get the 2>nul thing but if you don't want output add the nul at the end

I think Ed showed him that in another thread.


Yes! You are correct, he showed me that and it worked so I was recycling. I figured, all I had to do was change the registry values and it should work. Except, the only values I can run "reg query" on are HKLM or HKU, so I had to improvise with the RCMD. Which, by itself works. It can run the query and yield the output, I"m guessing the error handling of Batch is what is causing me a problem...

And.. I made the change to Enduser, still does not work.. The script finds the registry value yet assumes the errorlevel is still 1 and promptly says %enduser% does not have an invalid Registry key...

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Registry Query not working correctly :-/

#18 Post by abc0502 » 14 Aug 2012 12:39

hi Ed, i thought that the varible here in dos like python case sensitive and when i tested his first part of the code it didn't work till i changed the E to e

and using a double quotes in case there was spaces in the machine names, but i forgot that the machine names does't have spaces :oops:

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Registry Query not working correctly :-/

#19 Post by abc0502 » 14 Aug 2012 13:00

OK, try this all changes are in red

set /p "enduser=Please enter end-user IP address or Machine Name:"

echo.
echo ===========================================================================
echo Checking to see if user is online
echo ===========================================================================

ping -n 2 %enduser%

if %errorlevel% == 0 (
cls
echo.
echo ===========================================================================
echo User is Online!
echo ===========================================================================
echo.
ping 127.0.0.1 -n 1 -w 4000 >nul
goto regcheck
) else (
if %errorlevel% == 1 (
cls
echo.
echo ===========================================================================
echo User is OFFLINE!
echo ===========================================================================
echo.
ping 127.0.0.1 -n 1 -w 4000 >nul
echo %enduser% >> %lnm%
echo =========================================================================== >> %lnm%
echo %enduser% is Offline - %date% %time% >> %lnm%
echo ===========================================================================
goto endscript
))

:regcheck
cls
echo ===========================================================================
echo Fixing Registry of %enduser%
echo ===========================================================================
ping 127.0.0.1 -n 1 -w 2000 >nul
rcmd \\%enduser% reg delete "hkcr\mime\database\content type\image/tiff" /v CLSID /f
echo.
echo.
echo.
echo ===========================================================================
echo Okay, Registry has been fixed!
echo ===========================================================================
echo.
echo.
timeout 5
goto quit
)
cls

:quit
cls
exit

:endscript
echo.
echo ===========================================================================
echo Please verify that user is on network and try again
echo ===========================================================================
echo.
pause
timeout 2
cls
exit

Squashman
Expert
Posts: 4487
Joined: 23 Dec 2011 13:59

Re: Registry Query not working correctly :-/

#20 Post by Squashman » 14 Aug 2012 13:11

Read a post on another forum where the person always received an errorlevel 1 even when the RCMD was successful. He was running it against a Windows 2003 server from a Windows 2000 client.
I am wondering if it is just not compatible with the newer operating systems. Maybe you should give psexec a try.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Registry Query not working correctly :-/

#21 Post by foxidrive » 14 Aug 2012 18:23

Ed is right of course, variables don't care what case they are.


This section doesn't need the extra checking for errorlevel 1 so this would work.

Code: Select all

if %errorlevel% == 0 (
cls
echo.
echo ===========================================================================
echo User is Online!
echo ===========================================================================
echo.
ping 127.0.0.1 -n 1 -w 4000 >nul
goto regcheck
) else (
cls
echo.
echo ===========================================================================
echo User is OFFLINE!
echo ===========================================================================
echo.
ping 127.0.0.1 -n 1 -w 4000 >nul
echo %enduser% >> %lnm%
echo =========================================================================== >> %lnm%
echo %enduser% is Offline - %date% %time% >> %lnm%
echo ===========================================================================
goto endscript
)

sourbread
Posts: 23
Joined: 26 Apr 2012 09:10

Re: Registry Query not working correctly :-/

#22 Post by sourbread » 15 Aug 2012 05:43

Yeah, looks like my problem is with the errorhandling of rcmd. Essentially, what I did was use psexec to copy over the script and launch it that way, and the if argument is working as expected.

Thanks for the tip on the RCMD!

Post Reply