Strange Issue With REG

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

Strange Issue With REG

#1 Post by alleypuppy » 05 Nov 2011 13:59

Hello,

I'm getting a strange issue with the REG command. If I run the REG command from a batch file, regardless of the syntax, the file will freeze, causing me to have to Control-C my way out, press the red X multiple times, or end the CMD.EXE processes from Task Manager. If I press the red X, the file shows loads of "^C" commands being executed and will sometimes say "The process tried to write to a nonexistent pipe." I usually have to press the X multiple times for the window to actually close.

The same commands typed into a CMD window will run as expected, however. Running the batch file from a CMD window will yield the same results as double-clicking the batch file.

I have not modified anything in the registry but this one value (shown below) which is used for sending messages via MSG.EXE.

Please note that this issue was not occurring earlier today and that this file works on my other Windows 7 machine. Here is the file:

Code: Select all

@ECHO OFF
FOR /F "TOKENS=3" %%a IN ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" ^| FIND "AllowRemoteRPC"') DO SET REG=%%a
IF /I "%REG%"=="0x1" (ECHO The value is already set to 1.
PAUSE
EXIT /B
)
IF /I "%REG%" NEQ "0x1" REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /V "AllowRemoteRPC" /T REG_DWORD /D 1 /F
ECHO The value is now set to 1.
PAUSE
EXIT /B
Thanks for any input regarding this issue! ;)

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

Re: Strange Issue With REG

#2 Post by Ed Dyreen » 06 Nov 2011 00:07

'
Was the command working previously on the machine ?
Is there a file reg.cmd or reg.bat ?
What output do you get from this batch ?

Code: Select all

@echo off
reg /?
pause

alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

Re: Strange Issue With REG

#3 Post by alleypuppy » 06 Nov 2011 09:51

Ed Dyreen wrote:Was the command working previously on the machine ?
Yes it was working correctly in both batch files and when typed into the command prompt.

Ed Dyreen wrote:What output do you get from this batch ?

Code: Select all

@echo off
reg /?
pause


Output:

Code: Select all

C:\Users\[username]\Desktop>FOR /F "TOKENS=3" %a IN ('REG QUERY "HKLM\SYSTEM\Cu
rrentControlSet\Control\Terminal Server" | FIND "AllowRemoteRPC"') DO SET REG=%a


The file freezes and never reaches the PAUSE command. Very strange. It seems like something is saving the erroneous command and whenever I place REG into a batch file it runs it.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Strange Issue With REG

#4 Post by alan_b » 21 Nov 2011 05:05

Most executables that accept DOS commands from CMD.EXE may not on succeed or fail,
they will often give a response such as you hope to process with
^| FIND "AllowRemoteRPC"


Normally any response is determined by the executable's determination of success or failure,
and is issued via StdOut OR ALTERNATIVELY StdErr

REG.EXE is a special animal, it can use BOTH channels simultaneously to announce both success or failure.
I have suffered much grief with
REG.EXE QUERY HKLM\etc\etc\

In my case I had stipulated a registry key that was a parent key from which descended several levels of child and grand-child sub-keys.
REG.EXE listed :-
via StdOut, the existence of the parent key and its child keys ; and
via StdErr the child keys which it could see BUT NOT ACCESS to identifying whether grand-child keys existed.

I was piping both StdOut and StdErr to a status file, and observed that about 0.1% of the results were not repeatable.
When I realised two streams were INSTANTLY SIMULTANEOUSLY writing to the same file I suspected some race hazard conflict in the file system.
I then changed my code to write the status file to the same HDD but the partition most remote from C:\.
As I anticipated, the race hazard was vastly increased by the much greater time that it took for the drive head to travel from reading code in C:\ to writing data in Z:\.

Then I disabled Windows cache for the internal drive and the results were immediately repeatable - no more anomaly.
Obviously the Race Hazard was a problem in the Windows XP cache handling.
With the cache disabled it took twice as long for my Laptop to power up, so I enabled the cache and stopped writing to the same output file.

I do not know how it goes wrong for you,
but REG QUERY on a group of keys with access restrictions at various levels is quite a minefield.

Post Reply