Page 1 of 2

Registry Query not working correctly :-/

Posted: 14 Aug 2012 08:52
by sourbread
Any idea what is going on here? Each time, it automatically assumes the value does not exist, even when it does and therefore is skipping to the "goto :quit" portion of the script.

Just for clarification - as I've read it, HKCR is not applicable if you perform a normal reg query. So, Admins have rcmd added to their environment variables and have the correct permissions on all PC's in the domain. Running the query by itself, using rcmd, yields the correct string value. It's just when I run the script, for whatever reason it continues to assume it doesn't exist even when the output is shown to have it there.

Any ideas?

Portion of script below:
~~~~~~~~~~~~~~~

2>nul rcmd \\%enduser% reg query "hkcr\mime\database\content type\image/tiff" /v CLSID &&(
cls
echo ===========================================================================
echo %enduser% has incorrect Registry Value, patching now...
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
cls
goto :fix
) || (
cls
echo ===========================================================================
echo %enduser% does not have an invalid Registry key...
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
goto :quit
)

:fix
echo.
echo.
echo.
rcmd \\%enduser% reg delete "hkcr\mime\database\content type\image/tiff" /v CLSID
if %errorlevel% == 0 (
echo.
echo.
echo ===========================================================================
echo Okay, computer has been fixed. Verify Tiffs are now loading correctly...
echo ===========================================================================
echo.
ping 172.0.0.1 -n 1 -w 4000 >nul
goto :quit
)
else if %errorlevel% == 1 (
echo.
echo ===========================================================================
echo ERROR! Registry Value was not removed, please remove manually!
echo ===========================================================================
echo.
ping 172.0.0.1 -n 1 -w 4000 >nul
goto :quit
)

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 09:05
by Squashman
RCMD is new to me and doesn't seem to be on my system. Where did you get that from?

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 09:13
by sourbread
http://www.petri.co.il/download_free_reskit_tools.htm

Scroll down to Remote Command Service and download it. Basically, allows you to open up a "remote command prompt". The service has to be enabled on the other machine in order for it to work.

This was the only way I could think of querying HKCR on a remote computer. Unless, there is another way that I do not know how?

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 10:27
by abc0502
your problem is in the [ If ... Else ] statement, see the colored text

2>nul rcmd \\%enduser% reg query "hkcr\mime\database\content type\image/tiff" /v CLSID &&(
cls
echo ===========================================================================
echo %enduser% has incorrect Registry Value, patching now...
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
cls
goto :fix
) || (
cls
echo ===========================================================================
echo %enduser% does not have an invalid Registry key...
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
goto :quit
)

:fix
echo.&echo.&echo.
rcmd \\%enduser% reg delete "hkcr\mime\database\content type\image/tiff" /v CLSID
if %errorlevel% == 0 (
echo.&echo.
echo ===========================================================================
echo Okay, computer has been fixed. Verify Tiffs are now loading correctly...
echo ===========================================================================
echo.
ping 172.0.0.1 -n 1 -w 4000 >nul
goto :quit
) else (
if %errorlevel% == 1 (
echo.
echo ===========================================================================
echo ERROR! Registry Value was not removed, please remove manually!
echo ===========================================================================
echo.
ping 172.0.0.1 -n 1 -w 4000 >nul
goto :quit
))


and may i suggest something, see the green lines i use this when adding multi-empty lines in a batch. :)

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 10:42
by sourbread
Tried your fix and it's still behaving the same way :-/ Instantly jumps to %enduser% does not have an invalid Registry key.. even though I know the key itself exist.

For the time being, I've simply removed the query process and forced the script to delete the entry regardless if it exists or not. Not the way I was wanting to go with it, but it works. This is how I have it right now...

~~~~~~~~~~~~~~~~~~
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 (
echo.
echo ===========================================================================
echo User is Online!
echo ===========================================================================
echo.
ping 172.0.0.1 -n 1 -w 4000 >nul
goto :regcheck
) else if %errorlevel% == 1 (
echo.
echo ===========================================================================
echo User is OFFLINE!
echo ===========================================================================
echo.
ping 172.0.0.1 -n 1 -w 4000 >nul
echo %enduser% >> %lnm%
echo =========================================================================== >> %lnm%
echo %enduser% is Offline - %date% %time% >> %lnm%
echo ===========================================================================
)
cls
goto :endscript

:regcheck
cls
echo ===========================================================================
echo Fixing Registry of %enduser%
echo ===========================================================================
ping 172.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

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 10:45
by Squashman
Fix your code like he showed you.
This is not correct.
) else if %errorlevel% == 1 (

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 10:52
by Squashman
I see no point in checking the errorlevel twice. You already know what you want to do if it is NOT zero. The way you are writing it you then need an extra set of paranthesis besides the one you are missing.

Why not do this.

Code: Select all

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

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 11:07
by sourbread
Still no dice.. I think I caught everywhere the suggested fix should be, but it's still jumping the gun.

~~~~~~~~~~~~~~~
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 (
echo.
echo ===========================================================================
echo User is Online!
echo ===========================================================================
echo.
ping 172.0.0.1 -n 1 -w 4000 >nul
goto :regcheck
) else (
echo.
echo ===========================================================================
echo User is OFFLINE!
echo ===========================================================================
echo.
ping 172.0.0.1 -n 1 -w 4000 >nul
echo %enduser% >> %lnm%
echo =========================================================================== >> %lnm%
echo %enduser% is Offline - %date% %time% >> %lnm%
echo =========================================================================== >> %lnm%
)
goto :endscript

:regcheck
2>nul rcmd \\%enduser% reg query "hkcr\mime\database\content type\image/tiff" /v CLSID &&(
cls
echo ===========================================================================
echo %enduser% has incorrect Registry Value, patching now...
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
cls
goto :fix
) || (
cls
echo ===========================================================================
echo %enduser% does not have an invalid Registry key...
echo ===========================================================================
ping 172.0.0.1 -n 1 -w 2000 >nul
goto :quit
)

:fix
echo.echo.echo.
rcmd \\%enduser% reg delete "hkcr\mime\database\content type\image/tiff" /v CLSID
if %errorlevel% == 0 (
echo.echo.
echo ===========================================================================
echo Okay, computer has been fixed. Verify Tiffs are now loading correctly...
echo ===========================================================================
echo.
ping 172.0.0.1 -n 1 -w 4000 >nul
goto :quit
) else (
if %errorlevel% == 1 (
echo.
echo ===========================================================================
echo ERROR! Registry Value was not removed, please remove manually!
echo ===========================================================================
echo.
ping 172.0.0.1 -n 1 -w 4000 >nul
goto :quit
))

:quit
cls
exit

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

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 11:14
by abc0502
are you sure you have the right %enduser%, it could have the wrong name or non existing one
and how do you know if the clsid is right or wrong?
the reg query inport the value of the clsid and you don't compare it with the right value to tell if it right or wrong

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 11:18
by abc0502
sorry i missed reading the deletion command, so you delete the CLSID if it exist, so try remotely delete that key using that code

Code: Select all

rcmd \\%enduser% reg delete "hkcr\mime\database\content type\image/tiff" /v CLSID

and replace the %enduser% with the remote name, and see what will happen

and shouldn't you put the full directory to the rcmd like C:\folder\rcmd.exe

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: "

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 11:24
by sourbread
Right, basically, the only way that value is going to exist on our machines is if someone loads Quicktime on their machine, Quicktime will then add a CLSID reg value to that container. So, I didn't feel the need to specify a value since it will only exist under these conditions.

When I run the rcmd reg delete etc. command it works flawlessly. The %enduser% variable is also before this portion of the script, it pings the user and if they are offline, prompts and also creates a text file. The problem I'm facing, is when it performs the query. The query should yield an error of 0 since it found the registry value, however, for whatever reason the script is assuming otherwise and therefore jumping the gun that the value doesn't exist.

I wanted the script to query if the registry value exists first, if it does, then proceed on to removing the key. If it does not, prompt the user that the value does not exist.

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 11:25
by sourbread
EDIT* RCMD has been added to my environment variables, so no need to specify the directory.

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 11:40
by abc0502
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

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 11:49
by Squashman
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.

Re: Registry Query not working correctly :-/

Posted: 14 Aug 2012 12:11
by abc0502
YOU Won't belive what was the problem :lol:
it is in the first line see this
set /p Enduser=Please enter end-user IP address or Machine Name:

the letter "E" it is capital and the rest of the variable "%enduser%" all are starting with small letter
variables are case sensitive so change the Capital "E" letter to small and run it with your original, and notice that your are missing the "&" in
echo.&echo.&echo.