problem with a .bat file

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
swan_x
Posts: 335
Joined: 08 Oct 2009 12:27

problem with a .bat file

Post 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???

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: problem with a .bat file

Post 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.

admin
Site Admin
Posts: 66366
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: problem with a .bat file

Post 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?

swan_x
Posts: 335
Joined: 08 Oct 2009 12:27

Re: problem with a .bat file

Post 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!!

swan_x
Posts: 335
Joined: 08 Oct 2009 12:27

Re: problem with a .bat file

Post 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!

swan_x
Posts: 335
Joined: 08 Oct 2009 12:27

Re: problem with a .bat file

Post 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!

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: problem with a .bat file

Post 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.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: problem with a .bat file

Post 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
)

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: problem with a .bat file

Post 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
)

swan_x
Posts: 335
Joined: 08 Oct 2009 12:27

Re: problem with a .bat file

Post by swan_x »

yeahhhh!!!
tnxs nas8e9

now work!!

%systemroot%\sysnative\REG DELETE HKLM\Software\555


............SOLVED !!!

Post Reply