Need proper syntax for converting .vbs script to dos batch file

I'm trying to change the following batch file from this:

if not exist "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" (
	set SourceDB=KNOW64.accdb
) else (
	set SourceDB=KNOW.accdb
)

if not exist "%UserProfile%\My Documents\FEO_TRANSFER\DBS" md "%UserProfile%\My Documents\FEO_TRANSFER\DBS"
xcopy \\fkpdfs05\i\SD\FEO_TRANSFER\DBS\%SourceDB% "%UserProfile%\My Documents\FEO_TRANSFER\DBS\" /d /y
start MSACCESS "%UserProfile%\My Documents\FEO_TRANSFER\DBS\%SourceDB%"

Open in new window


and grab a registry value shown in this website:

http://stackoverflow.com/questions/445167/how-can-i-get-the-value-of-a-registry-key-from-within-a-batch-script

Instead of hardcoding the path of the batchfile I want to set the variable whatever is in for value:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE\Path

I tried this:

FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

\MSACCESS.EXE\Path" /v ValueName`) DO (
    set appdir=%%A %%B
    )
ECHO %appdir%
pause

Open in new window


But the error I get is system was unable to find the specified registry key or value.
Please note attachment A.  Attachment B is provided to show that path actually does exist.
I believe currently I don't have the correct syntax - thus please help!
AttachmentA.PNG
AttachmentB.PNG
LVL 1
stephenlecomptejrAsked:
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.

oBdACommented:
Try it like this:
@echo off
setlocal
for /f "tokens=2*" %%a in ('reg.exe query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.exe" /v Path ^| find /i "Path"') do set AppDir=%%b
echo AppDir: %AppDir%

Open in new window

0

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
stephenlecomptejrAuthor Commented:
Ok that gets me started but how do I use a wildcard to now take the variable AppDir and determine if 64-bit or not?
I'm currently basing that on if the AppDir has (x86) in the variable.

One example if its' C:\Program Files (x86)\Microsoft Office\Office14 then I know it's not 64-bit (as shown in the above vbs script)

So using this:  how would I rearrange the IF statement shown in the .vbs script file within this new batch file syntax?

http://superuser.com/questions/709651/how-to-perform-wildcard-string-comparison-in-batch-file
0
stephenlecomptejrAuthor Commented:
I tell you what - I know this was posted late and I really feel like this should be a two-part question.  So let me give you the correct answer and do part 2 for this.  Cause I really appreciate the reply.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

stephenlecomptejrAuthor Commented:
Great - going to post a second question about this.  Since this person went out of there way to comment during the holidays - the best I can do is post another question to help his score and grade out.   The only issue I see is a free for all for the next commenter so if someone else responds they earn the points if answer first.
0
stephenlecomptejrAuthor Commented:
Sorry oBdA,

I figured it out doing this:

@echo off
setlocal
for /f "tokens=2*" %%a in ('reg.exe query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.exe" /v Path ^| find /i "Path"') do set AppDir=%%b
AppDir = AppDir + "MSACCESS.exe"
echo AppDir: %AppDir%
pause
find "(x86)" %AppDir% >nul
if %errorlevel% equ 1 echo "not 64-bit"
pause

Open in new window


Thank you sincerely for your help!
0
oBdACommented:
That will not work. "find" will either accept input from the console, or search for files passed as command line arguments.
You'd need something like this:
echo %AppDir%| find "(x86)"  >nul

Open in new window

Note that this will only work on 64bit Windows. It will not detect a 32bit Office on a 32bit Windows; do you have this situation?
0
stephenlecomptejrAuthor Commented:
This was the final code and seems to be working...
Are you saying the following won't work still?

@echo off

setlocal

for /f "tokens=2*" %%a in ('reg.exe query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.exe" /v Path ^| find /i "Path"') do set AppDir=%%b

AppDir = AppDir + "MSACCESS.exe"

echo AppDir: %AppDir%

find "(x86)" %AppDir% >nul

if %errorlevel% equ 1 (

set SourceDB=KNOW.accdb

) else (

set SourceDB=KNOW64.accdb

)

if not exist "%UserProfile%\My Documents\FEO_TRANSFER\DBS" md "%UserProfile%\My Documents\FEO_TRANSFER\DBS"

xcopy \\fkpdfs05\i\SD\FEO_TRANSFER\DBS\%SourceDB% "%UserProfile%\My Documents\FEO_TRANSFER\DBS\" /d /y

start MSACCESS "%UserProfile%\My Documents\FEO_TRANSFER\DBS\%SourceDB%"

Open in new window

0
oBdACommented:
This should end up always using KNOW.accdb as SourceDB. Just paste this into a command prompt:
set AppDir=C:\Program Files (x86)\Microsoft Office\Office14\
find "(x86)" %AppDir%

Open in new window

You should see a bunch of error messages.
0
stephenlecomptejrAuthor Commented:
I'm confused by your last comment:
When you say This should end up always using KNOW.accdb as SourceDB - are you talking about my code or the one you are posting below?

I can't use the last code posted because someone installed Office 2013 on another.  And of course that stated path is for Office 2010 only.  

Don't you see in my batch file my If statement checks for any error and if found then

find "(x86)" %AppDir% >nul

if %errorlevel% equ 1 (

set SourceDB=KNOW.accdb

) else (

set SourceDB=KNOW64.accdb

Open in new window

0
stephenlecomptejrAuthor Commented:
So giving your last comment a little more thought....

Are you saying with my code - no matter what an error is thrown and people that actually have C:\Program Files\Microsoft Office\Office14\MSAccess.exe as a valid 64 bit path - will still only open KNOW.accdb instead of KNOW64.accdb?

So with that statement - what is then the fix?  What should I change so there is no error in the find...
0
oBdACommented:
Your code will always throw an error, so the "if errorlevel equ 1" will always be true.
As mentioned in http:#a40471503, if you want to check a string using "find", you need to pass it through the pipe:
echo %AppDir%| find "(x86)"  >nul
if errorlevel 1 (
	echo Office x64 found.
) else (
	echo Office x86 found.
)

Open in new window

0
stephenlecomptejrAuthor Commented:
Ok so I tried your code shown last.  And obviously its picking Office 64 bit when I only have 32-bit.

How do I pass it through the pipe as described?
What syntax do I need then?

[Cause just to emphasize again]

@echo off

setlocal

for /f "tokens=2*" %%a in ('reg.exe query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.exe" /v Path ^| find /i "Path"') do set AppDir=%%b

AppDir = AppDir + "MSACCESS.exe"

echo %AppDir%| find "(x86)"  >nul
if errorlevel 1 (
	set SourceDB=KNOW.accdb
) else (
	set SourceDB=KNOW64.accdb
)

echo %SourceDB%
pause

Open in new window


Yet this still tells me I have 64-bit and I instead have 32-bit.  So the last suggested one doesn't work as well.

Please note error message I'm getting in this screen shot.

Thanks.
ErrorIget.PNG
0
oBdACommented:
@echo off
setlocal

for /f "tokens=2*" %%a in ('reg.exe query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.exe" /v Path ^| find /i "Path"') do set AppDir=%%b

set AppDir=%AppDir%MSACCESS.exe

echo %AppDir%| find "(x86)"  >nul
if errorlevel 1 (
	set SourceDB=KNOW.accdb
) else (
	set SourceDB=KNOW64.accdb
)

echo %SourceDB%
pause

Open in new window

0
stephenlecomptejrAuthor Commented:
ok.  So that last code works without throwing an error.
But the problem is that its trying to select KNOW64.accdb when I it should be showing KNOW.accdb for 32-bit.
Please note attachment to show you what I"m getting and what the registry value path is.

I really do appreciate all the replies on this...
nomoreerrorbutnotrightpath.PNG
0
oBdACommented:
@echo off
setlocal
for /f "tokens=2*" %%a in ('reg.exe query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.exe" /v Path ^| find /i "Path"') do set AppDir=%%b
set AppDir=%AppDir%MSACCESS.exe
echo %AppDir%| find "(x86)"  >nul
if errorlevel 1 (
	set SourceDB=KNOW64.accdb
) else (
	set SourceDB=KNOW.accdb
)
echo %SourceDB%
pause

Open in new window

0
stephenlecomptejrAuthor Commented:
oBda - thank you for your help.  Now it's working fantastic.
Thank you again for your patience on this.
0
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
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.