creating a batchfile

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
shyam pothiniAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
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
shyam pothiniAuthor 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 PrewIT / Software Engineering ConsultantCommented:
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
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Bill PrewIT / Software Engineering ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shyam pothiniAuthor Commented:
thanks

it didn't work
batch file ran but it didn't add reg key
shyam pothiniAuthor Commented:
yes I know how to add the reg keys in batch file
Bill PrewIT / Software Engineering ConsultantCommented:
You ran it with elevated privileges, yes?

What errors or output did you get?

What was your final BAT script?


»bp
shyam pothiniAuthor Commented:
it worked thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.