Page 1 of 1
problem with a .bat file
Posted: 13 Sep 2011 18:19
by swan_x
i have one bat file with a command line for delete one reg key...
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\StillImage\Registered Applications" /f
if run this bat in XY this bat not work, ("error the key not exist"!);
if run same bat on win explorer, this work!!
why this???
Re: problem with a .bat file
Posted: 13 Sep 2011 18:25
by nas8e9
swan_x wrote:i have one bat file with a command line for delete one reg key...
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\StillImage\Registered Applications" /f
if run this bat in XY this bat not work, ("error the key not exist"!);
if run same bat on win explorer, this work!!
why this???
It seems related to WOW64: running a similar script in a 64-bit command prompt does work correctly. As for working around this, I'm not sure at the moment.
Re: problem with a .bat file
Posted: 13 Sep 2011 19:48
by admin
swan_x wrote:i have one bat file with a command line for delete one reg key...
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\StillImage\Registered Applications" /f
if run this bat in XY this bat not work, ("error the key not exist"!);
if run same bat on win explorer, this work!!
why this???
You have a screenshot of the error message?
Re: problem with a .bat file
Posted: 13 Sep 2011 20:16
by swan_x
no screenshot...

if don't write /f (without confirmation) at the end:
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\StillImage\Registered Applications"
i have 2 choices Yes or Not
for every choice, the window closes immediately...but i see the error message:
<error: can not find the registry key or value specified>
this does not happen if i use win explorer...
at the end of my bat i have the message:
<operation completed>
and the key is deleted successfully!!
Re: problem with a .bat file
Posted: 13 Sep 2011 20:17
by swan_x
nas8e9 wrote:swan_x wrote:i have one bat file with a command line for delete one reg key...
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\StillImage\Registered Applications" /f
if run this bat in XY this bat not work, ("error the key not exist"!);
if run same bat on win explorer, this work!!
why this???
It seems related to WOW64: running a similar script in a 64-bit command prompt does work correctly. As for working around this, I'm not sure at the moment.
yes i know! this is the problem!
Re: problem with a .bat file
Posted: 14 Sep 2011 10:53
by swan_x
try this:
run-regedit
in HKEY_LOCAL_MACHINE\SOFTWARE
creates new key 555
now copy this in new txt document, and save to xxx.bat:
REG DELETE HKLM\Software\555
ok, run xxx.bat from XY ---- you have window confirmation Y/N ---- hold Y ---- error (impossible find this key!!)
go to regedit, the key was not deleted !!
now open win explorer, run xxx.bat ----- you have window confirmation Y/N ---- hold Y ---- OK!!
go to regedit, key deleted !!
same result if "run as administartor" xxx.bat file from XY .... the result does not change!
Re: problem with a .bat file
Posted: 14 Sep 2011 11:11
by nas8e9
swan_x wrote:try this:
run-regedit
in HKEY_LOCAL_MACHINE\SOFTWARE
creates new key 555
now copy this in new txt document, and save to xxx.bat:
REG DELETE HKLM\Software\555
ok, run xxx.bat from XY ---- you have window confirmation Y/N ---- hold Y ---- error (impossible find this key!!)
go to regedit, the key was not deleted !!
now open win explorer, run xxx.bat ----- you have window confirmation Y/N ---- hold Y ---- OK!!
go to regedit, key deleted !!
same result if "run as administartor" xxx.bat file from XY .... the result does not change!
I'm not sure my first post in this thread was clear, so:
64-bit versions of Windows basically lie to 32-bit apps in order to preserve compatibility; this functionality is referred to as WOW64. Part of this system is registry virtualisation, where 32-bit apps's registry reads and writes are redirected to different parts of the registry.
The second piece of the puzzle is that when 32-bit apps call the command prompt (by executing a .bat file in your case), they get a 32-bit command prompt rather than the 64-bit one you get when starting one through Windows Explorer. As a result, .bat- or .cmd-files behave differently when run from a 32-bit app instead of (64-bit) Windows Explorer. That's what causes your registry access from a .bat-file to fail.
As for working around this problem, I don't know at the moment.
Re: problem with a .bat file
Posted: 14 Sep 2011 11:32
by Stefan
On 64-bit OS, 32-bit apps have different locations then 64-bit apps
64-bit see and use: HKLM\SOFTWARE\
32-bit see and use: HKLM\SOFTWARE\Wow6432Node\ as there "HKLM\SOFTWARE\"
Take an look if you have an 32-bit version of REG.exe in your %systemroot%\syswow64\ folder.
Perhaps this will work then:
Code: Select all
IF %PROCESSOR_ARCHITEW6432%LEER==LEER (
REM 32
REG DELETE HKLM\Software\555
)else(
REM 64
%systemroot%\syswow64\REG DELETE HKLM\Software\555
)
Re: problem with a .bat file
Posted: 14 Sep 2011 12:14
by nas8e9
Stefan wrote:On 64-bit OS, 32-bit apps have different locations then 64-bit apps
64-bit see and use: HKLM\SOFTWARE\
32-bit see and use: HKLM\SOFTWARE\Wow6432Node\ as there "HKLM\SOFTWARE\"
Take an look if you have an 32-bit version of REG.exe in your %systemroot%\syswow64\ folder.
Perhaps this will work then:
Code: Select all
IF %PROCESSOR_ARCHITEW6432%LEER==LEER (
REM 32
REG DELETE HKLM\Software\555
)else(
REM 64
%systemroot%\syswow64\REG DELETE HKLM\Software\555
)
Thank you for the pointers! I had to make some changes (SysWOW64 vs. Sysnative) and ended up with this:
Code: Select all
@ECHO OFF
IF DEFINED PROCESSOR_ARCHITEW6432 (
REM 32
ECHO "Called from a 32-bit process."
%systemroot%\sysnative\REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\StillImage\Registered Applications" /f
) ELSE (
REM 64
ECHO "Called from a 64-bit process."
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\StillImage\Registered Applications" /f
)
Re: problem with a .bat file
Posted: 14 Sep 2011 15:35
by swan_x
yeahhhh!!!
tnxs nas8e9
now work!!
%systemroot%\sysnative\REG DELETE HKLM\Software\555
............SOLVED !!!