windows batch script for updating a game license file

The below script searches for and replaces a file called “licenseUpdate” in a folder called qbattle in several drives.  I need to advance this script a bit.

I need this script to also do the following:

Only replace/install “licenseUpdate” if the file does not already exist

Then after that completes I need the batch to check for a folder called C:\Program Files\Xfire and if found it will launch a web link called “rejoin.url” which exists in same directory as batch.  

However if it does not find the xfire directory, I need it to launch “c:\games\qbattle.exe”

Aside from 500 points i will give major kudos and a fat THANKS for this.  

My current script…
echo.
echo. please wait...
echo.
IF EXIST dir_search.txt del /q /f dir_search.txt
FOR %%i in (C D E F G) do @dir %%i:\*qbattle /s /b /ad>> dir_search.txt
FOR /F "tokens=* delims=" %%x in (dir_search.txt) do @copy /v /y licenseUpdate "%%x\licenseUpdate"
del /q /f dir_search.txt
icecom4Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

Steve KnightIT ConsultancyCommented:
Just passing .... but think this is what you want, without changing the logic of what you already have working too much (there are other ways but if it works...).

I think this is what you mean.... if there is a program called the below then launch the url file, otherwise start the exe?

IF EXIST "C:\Program Files\Xfire.exe" (
  START rejoin.url
) ELSE (
  START c:\games\qbattle.exe
)
@echo off
echo.
echo. please wait...
echo.

IF EXIST dir_search.txt del /q /f dir_search.txt
FOR %%i in (C D E F G) do @dir %%i:\*qbattle /s /b /ad>> dir_search.txt

FOR /F "tokens=* delims=" %%x in (dir_search.txt) do if not exist "%%x\licenseUpdate" copy /v /y licenseUpdate "%%x\licenseUpdate"

IF EXIST "C:\Program Files\Xfire.exe" (
  START rejoin.url
) ELSE (
  START c:\games\qbattle.exe
)


del /q /f dir_search.txt

Open in new window

0
BillDLCommented:
Only one issue I can see is that the command:
start "filename.url"
or
start /b "filename.url"
doesn't launch anything on my WinXP PC.

If I lose the start command and just have the full name of the *.URL file on the line by itself, or even just the actual web address, it works.  IE9 and Vista/Win7 might differ though, and if the default browser is not IE then it may not work either.


So, if this:
IF EXIST "C:\Program Files\Xfire.exe" (
  START rejoin.url
) ELSE (
  START c:\games\qbattle.exe
)

doesn't work, try replacing it with this:
IF EXIST "C:\Program Files\Xfire.exe" (
  rejoin.url
) ELSE (
  START c:\games\qbattle.exe
)

or this:
IF EXIST "C:\Program Files\Xfire.exe" (
  http://www.fullurl.com
) ELSE (
  START c:\games\qbattle.exe
)
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
Steve KnightIT ConsultancyCommented:
Yes a lot of maybes here....  I don't think this one will work though Bill?

IF EXIST "C:\Program Files\Xfire.exe" (
  http://www.fullurl.com
) ELSE (
  START c:\games\qbattle.exe
)
 
Perhaps

IF EXIST "C:\Program Files\Xfire.exe" (
  START "" "http://www.fullurl.com"
) ELSE (
  START c:\games\qbattle.exe
)

or

IF EXIST "C:\Program Files\Xfire.exe" (
  iexplore "ttp://www.fullurl.com"
) ELSE (
  START c:\games\qbattle.exe
)
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

BillDLCommented:
Yes, you're right.  A fully qualified URL pasted into the Start menu > Run does work, but does not work as a standalone "command" in a batch file. Your second example works perfectly.
0
Steve KnightIT ConsultancyCommented:
Well it would have done with a h before the ttp :-)



Steve
0
icecom4Author Commented:
Does the "C:\Program Files\Xfire.exe" have to be short dos command line or does it matter?
0
Steve KnightIT ConsultancyCommented:
Not sure what you mean, sorry?
0
icecom4Author Commented:
ok, launching a .url link from batch is just buggy, it worked once out of like 20 tries.  So I changed the command line to START iexplore.exe "http://..." and that works but now I have a new issue.

That calls internet explorer, even if another browser is default, as long internet explorer is still installed on the machine.  Thats good...just worried about players that do not have internet explorer installed for what ever reason.  Any thoughts on this?  
0
Steve KnightIT ConsultancyCommented:
yes, using

start "" "http://whatever"

should use the default browser in the same way as typing it in the run box on start menu.

0
icecom4Author Commented:
Thanks guys.  Wish I could give 500 to both.  

Works like a charm.  

THANK YOU!
0
Steve KnightIT ConsultancyCommented:
No problem, glad it helped.
0
BillDLCommented:
Thank you icecom4.
0
BillDLCommented:
You asked earlier:
"Does the "C:\Program Files\Xfire.exe" have to be short dos command line or does it matter?"

I think you were asking whether the path in the command had to be the DOS 8.3 short name like:
C:\Progra~1\Xfire.exe

Sometimes in operating systems from XP onwards a path will be accepted if the names have spaces in them, but it depends entirely on what command is being run.  It is good practice, and a safe bet, to always enclose the path in double quotes in which case the names can have spaces:
"C:\Program Files\Xfire.exe".

There is the very odd occasion where a 3rd-party program doesn't like double quotes and you have to use the short names, but that is rare and normally only happens with old programs.

As far as web addresses are concerned, they CANNOT contain spaces.  If you ever see the   %20   symbol in a web address it is usually where somebody has uploaded files with spaces in the names to the web server, and the spaces need to be replaced in the address by the   %20   symbol.  You will most often see this in a link to files like MP3s that are being made available for download.   Speaking of other symbols used in web addresses you might also see this type of thing:

http%3A%2F%2Fwww%2Eexperts%2Dexchange%2Ecom%2FProgramming%2FLanguages%2FVisual_Basic%2FVB_Script%2FQ_27509623%2Ehtml%23a37343655

This gives a chart of characters:
http://www.werockyourweb.com/url-escape-characters

Nevertheless, it is good practice to enclose URLs in double quotes in a batch file like yours.  There may be the odd character that could end up being treated as one reserved for commands unless you double quote the URL, and it also makes each parameter of the command more visible.

dragon-it's little trick of using the START.exe command followed by "" then the URL is useful to know when troubleshooting batch files.  type   start /?    in a CMD window to see the available switches and parameters.  The "" is used for the "Window Title" and sometimes it can make a non-functioning command work for you.

I was also just wondering what the purpose in sending the user to site in the "rejoin.url" was.  If it is to log on or something, then I suppose you would have to send them there, but if it is to download and install the "Xfire.exe" program, then there might be a way of automating this by using a little program to download the file from the web server without actually having to launch a page in a browser and click a link.

If you are interested, then the program I use for this is called URL2File.exe (the ZIP file version) and the usage is quite simple:
URL2File.exe "FullURL" "C:\FullPath\FileNameToSaveAs.exe"
It also allows you to send a login username and password if the site supports it.

Just some additional information that you might find helpful.
0
BillDLCommented:
I think I can see what your "rejoin.url" does now:
http://www.xfire.com/xfire_urls/
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
VB Script

From novice to tech pro — start learning today.