creating a batchfile

shyam pothini
shyam pothini used Ask the Experts™
on
hello all

I am trying to create a batch file to add registry key.
its should run on both 32bit and 64 bit
there are 2 different registry keys for 32bit and 64bit.
so if it is 32-bit, it adds the 32-bit registry key and vice versa

Any ideas?

Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
Give this a try.

for /f "skip=2 tokens=2-5 delims=," %%A in ('wmic os get osarchitecture^,version /format:csv') do set arch=%%A
if "%arch%" EQU "64-bit" (
    rem do 64 bit logic here
) else (
    rem do 32 bit logic here
)

Open in new window


»bp

Author

Commented:
Thanks,

I am confused.
I want to add commnd here
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
so how can I do that
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
Based on your question I thought you knew how to add to the registry from batch, and were just looking for help differentiating between 32 and 64 bits.

If you want the exact registry commands, then I would need to know the key and value you want to add for both 32 and 64 bit.


»bp
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Test your restores, not your backups...
Top Expert 2016
Commented:
The general idea would be:

for /f "skip=2 tokens=2-5 delims=," %%A in ('wmic os get osarchitecture^,version /format:csv') do set arch=%%A
if "%arch%" EQU "64-bit" (
    REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "My App" /t REG_SZ /F /D "C:\MyAppPath\MyApp64.exe"
) else (
    REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "My App" /t REG_SZ /F /D "C:\MyAppPath\MyApp32.exe"
)

Open in new window


»bp

Author

Commented:
thanks

it didn't work
batch file ran but it didn't add reg key

Author

Commented:
yes I know how to add the reg keys in batch file
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
You ran it with elevated privileges, yes?

What errors or output did you get?

What was your final BAT script?


»bp

Author

Commented:
it worked thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial