Home PageFacebookRSS News Feed
PocketGPS
Web
Read the current newsletter! Weekly
Newsletter
SatNav,GPS,Navigation
Pocket GPS World - SatNavs | GPS | Speed Cameras: Forums

Pocket GPS World :: View topic - Getting a Windows batch file to read a .ini file?
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in for private messagesLog in for private messages   Log inLog in 

Getting a Windows batch file to read a .ini file?

 
Post new topic   Reply to topic    Pocket GPS World Forum Index -> Lost Satellite Fix - Off Topic Area
View previous topic :: View next topic  
Author Message
Privateer
Pocket GPS Moderator
Pocket GPS Moderator


Joined: 30/12/2002 17:36:20
Posts: 4850
Location: Oxfordshire, England, UK

PostPosted: Sat Jan 17, 2015 8:03 pm    Post subject: Getting a Windows batch file to read a .ini file? Reply with quote

I'm looking for help in getting a batch file to read a .ini file

I'm not that good at coding, although I can Cut & Paste and edit if I can understand the code. Wink

I've found a website that shows how to get a batch file to read keys in a .ini file, it's the Almanac Hackers "Reading an ini config file from a batch file" website.

My problem is that I can get the example in the above URL to work but, I'm getting trouble with getting any of my code that I place after the subroutine to work.

Here's my .ini file:

Code:
; anything after a semi-colon is a comment
; some implementations do not recognize comments, some start them with #
; start a section with a line beginning with a text string inside square brackets
; sections [general] are useful divisions, however always use unique keys throughout whole file.
[general] 
; "Windows XP"
; "Windows Vista"
; "Windows 7"
; "Windows 8"
; "Windows 8.1"
pc_opsy="Windows 7"
driveprog=c
drivedata=c
driveflash=e


Here's my batch file:

Code:
@echo off
:: putting a @ at the start of a line prevents the command on that line from being shown (echoed) on the screen.

echo ### Backup Pro Version 1.00
echo.

:: Version 1.00
:: Last updated 14/01/2015
::
:: History (latest first)
::
:: 1.00 (14/01/2015)
:: Completely new backup file that uses .ini file as well as exclude file

:readini
:: Read the ini file for values such as: PC Operating System; Drive of progame files; Drive of data; Drive of flash USB; etc
echo Reading .ini file ... Please wait!
echo.

set INIFILE="%~dp0settings.ini"
:: %0 is the script file name (with path), %~0 removes the surrounding " " ("%~0" == %0)
:: Adding dp returns the drive and path to the file, instead of the file name itself

call:getvalue %INIFILE% "pc_opsy" "" PC_OPSY
call:getvalue %INIFILE% "driveprog" "" DRIVEPROG
call:getvalue %INIFILE% "drivedata" "" DRIVEDATA
call:getvalue %INIFILE% "driveflash" "" DRIVEFLASH

echo PC Operating System: %PC_OPSY%
echo Program Drive:       %DRIVEPROG%
echo Data Drive:          %DRIVEDATA%
echo USB Drive:           %DRIVEFLASH%
echo.

goto:exit

:getvalue
::@echo off
rem This function reads a value from an INI file and stored it in a variable
rem %1 = name of ini file to search in.
rem %2 = search term to look for
rem %3 = group name (not currently used)
rem %4 = variable to place search result
FOR /F "eol=; eol=[ tokens=1,2* delims==" %%i in ('findstr /b /l /i %~2= %1') DO set %~4=%%~j
goto:eof

:backuptype
:: Here we ask the user whether it's an incremental or full backup
:: Incremental = A backup of all changed and new files since the last backup
:: Full        = A backup of all files in a specified backup set or job

:setpaths
:: The path of Microsoft Outlook and others are different in each version of Windows

if %PC_OPSY% EQU "Windows XP"    goto ver_xp
if %PC_OPSY% EQU "Windows Vista" goto ver_vista
if %PC_OPSY% EQU "Windows 7"     goto ver_7
if %PC_OPSY% EQU "Windows 8"     goto ver_8
if %PC_OPSY% EQU "Windows 8.1"   goto ver_8

goto warnthenexit

:ver_xp
:Run Windows XP specific commands here.
echo Operating System is: Windows XP
::set pc_opsy=Windows XP
set syspath1=Local Settings\Application Data
set syspath2=Application Data
goto step1

:ver_vista
:Run Windows Vista specific commands here.
echo Operating System is: Windows Vista
::set pc_opsy=Windows Vista
set syspath1=AppData\Local
set syspath2=AppData\Roaming
goto step1

:ver_7
:Run Windows 7 specific commands here.
echo Operating System is: Windows 7
::set pc_opsy=Windows 7
set syspath1=AppData\Local
set syspath2=AppData\Roaming
goto step1

:ver_8
:Run Windows 8 specific commands here.
echo Operating System is: Windows 8
::set pc_opsy=Windows 8
set syspath1=AppData\Local
set syspath2=AppData\Roaming
goto step1

:warnthenexit
echo Operating System is: Machine undetermined.
goto exit

:step1
echo hello world



:exit
@pause


The purpose of the batch file is to backup data on a PC and it also needs to work out where the Outlook files are.

If anybody can advise (in simple English) I would appreciate it.

Many thanks,

Update:

On my PC, I try to keep all of my data under a single folder (C:\Data\). A few years ago, I wrote (cobbled together) a batch file script that does the following:

Arrow Determine versions of Windows (as that determines where MS Outlook files are found)
Arrow Set the path of the Outlook 2007 files
Arrow Copy important Outlook files to C:\Data\z DR Backups
Arrow Copy C:\Data\ and sub-folders to USB stick

NB1 An external "exclude" file is used by the batch file to stop large folders i.e. photos being backed up to the USB stick.

NB2 Whilst the versions of Windows (from XP to 8.1) might be different, it's always up until now been just Outlook 2007 that I have to backup. Now I need to cope with different versions of Outlook as well as different versions of Windows.

When I want to make a full backup, I run the batch file and then copy all of the C:\Data folder and all of its sub-folders to an external hard drive.

I could use a piece of software but I like the challenge of doing this via a batch file.

My wife has just got a new PC (Windows 8.1 and Office 2013) so the Outlook files are in yet another location. This time I'd like a batch file that I can easily configure for any version of Office and any version of Windows by an external config/ini file.

_________________
Robert.
iPhone 6s Plus, iOS 14.0.1: iOS CamerAlert v2.0.7
TomTom GO Mobile iOS 2.3.1; TomTom (UK & ROI and Europe) iOS apps v1.29
Garmin Camper 770 LMT-D


Last edited by Privateer on Sun Jan 18, 2015 8:10 pm; edited 3 times in total
Back to top
View user's profile Send private message Send e-mail
DennisN
Tired Old Man
Tired Old Man


Joined: Feb 27, 2006
Posts: 14830
Location: Keynsham

PostPosted: Sat Jan 17, 2015 9:05 pm    Post subject: Re: Getting a Windows batch file to read a .ini file? Reply with quote

Privateer wrote:
If anybody can advise (in simple English) I would appreciate it.

Just give up?
_________________
Dennis

If it tastes good - it's fattening.

Two of them are obesiting!!
Back to top
View user's profile Send private message
sussamb
Pocket GPS Verifier
Pocket GPS Verifier


Joined: Mar 18, 2011
Posts: 4356
Location: West Sussex

PostPosted: Sat Jan 17, 2015 9:19 pm    Post subject: Reply with quote

I just use SyncToy ... Confused
_________________
Where there's a will ... there's a way.
Back to top
View user's profile Send private message
Oldboy
Pocket GPS Moderator
Pocket GPS Moderator


Joined: Dec 08, 2004
Posts: 10615
Location: Suffolk, UK

PostPosted: Sat Jan 17, 2015 10:23 pm    Post subject: Reply with quote

At first glance the only thing I can see is that you have a goto:eof but no Label :eof

Most batch files would stop with an error at this point.
_________________
Richard

TT 910 V7.903 (9183/081205) OS:2344
Europe version 1045.10005
TT Via 135 App 12.075
Europe v 1065.10740
Back to top
View user's profile Send private message Visit poster's website
Kremmen
Pocket GPS Verifier
Pocket GPS Verifier


Joined: Mar 03, 2006
Posts: 6289
Location: West London & Reading

PostPosted: Sun Jan 18, 2015 5:50 am    Post subject: Reply with quote

sussamb wrote:
I just use SyncToy ... Confused


Ditch Synctoy and get SyncBackFree ASAP from 2brightsparks. Synctoy has numerous bugs that we discovered that can delete source files instead of backing them up.

SyncBackFree works in a similar manner as it does a 1 2 1 copy.
_________________
Satnav:
Garmin DS61 LMT-D (In the car)
Garmin 2599 LMT-D (Indoor test rig)
DashCam:
Viofo A119 V3
Back to top
View user's profile Send private message
Kremmen
Pocket GPS Verifier
Pocket GPS Verifier


Joined: Mar 03, 2006
Posts: 6289
Location: West London & Reading

PostPosted: Sun Jan 18, 2015 5:59 am    Post subject: Reply with quote

As far as trying to debug the vbs script I agree with getting a backup tool. For Outlook files I use pstbackup from Microsoft but if you know where your .pst or .ost files are you can use SyncBackFree to ensure they are backed up on a schedule.

Also don't forget to have a second backup on a portable drive that is only connected during a non scheduled manual backup. That prevents these crypto viruses corrupting all backups.
_________________
Satnav:
Garmin DS61 LMT-D (In the car)
Garmin 2599 LMT-D (Indoor test rig)
DashCam:
Viofo A119 V3
Back to top
View user's profile Send private message
M8TJT
The Other Tired Old Man
The Other Tired Old Man


Joined: Apr 04, 2006
Posts: 10118
Location: Bexhill, South Sussex, UK

PostPosted: Sun Jan 18, 2015 10:13 am    Post subject: Reply with quote

I suspect that privateer actually wants a clue as to why his code does not work, rather than a bunch of suggestions on what software to use to do backups. Very Happy
Is a double colon the same as a semi colon for a REM?
Back to top
View user's profile Send private message
Kremmen
Pocket GPS Verifier
Pocket GPS Verifier


Joined: Mar 03, 2006
Posts: 6289
Location: West London & Reading

PostPosted: Sun Jan 18, 2015 12:56 pm    Post subject: Reply with quote

Yep, a 'comment' statement.

I've not dabbled that much in .vbs as I used to prefer VB6.
_________________
Satnav:
Garmin DS61 LMT-D (In the car)
Garmin 2599 LMT-D (Indoor test rig)
DashCam:
Viofo A119 V3
Back to top
View user's profile Send private message
sussamb
Pocket GPS Verifier
Pocket GPS Verifier


Joined: Mar 18, 2011
Posts: 4356
Location: West Sussex

PostPosted: Sun Jan 18, 2015 1:25 pm    Post subject: Reply with quote

Kremmen wrote:
sussamb wrote:
I just use SyncToy ... Confused


Ditch Synctoy and get SyncBackFree ASAP from 2brightsparks. Synctoy has numerous bugs that we discovered that can delete source files instead of backing them up.

SyncBackFree works in a similar manner as it does a 1 2 1 copy.


Thanks, good tip Very Happy
_________________
Where there's a will ... there's a way.
Back to top
View user's profile Send private message
Privateer
Pocket GPS Moderator
Pocket GPS Moderator


Joined: 30/12/2002 17:36:20
Posts: 4850
Location: Oxfordshire, England, UK

PostPosted: Sun Jan 18, 2015 7:42 pm    Post subject: Reply with quote

I've add an update to the original post to hopefully explain my requirements a little better.

Thanks for everybody's comments so far, please keep them coming.

M8TJT wrote:
I suspect that privateer actually wants a clue as to why his code does not work, rather than a bunch of suggestions on what software to use to do backups. Very Happy

That's right. Thumbs Up

M8TJT wrote:
Is a double colon the same as a semi colon for a REM?

I believe that in an ini file a semi colon is used for a REM, whilst in a windows batch file a double colon is used for a REM. That's what I've picked up from some web pages - but we all know how accurate and truthful the internet is!Wink

Kremmen wrote:
Ditch Synctoy and get SyncBackFree ASAP from 2brightsparks. Synctoy has numerous bugs that we discovered that can delete source files instead of backing them up.

SyncBackFree works in a similar manner as it does a 1 2 1 copy.

Thanks for that I may resort to using SyncBackFree if I can't get my batch file to work.

Kremmen wrote:
As far as trying to debug the vbs script I agree with getting a backup tool. For Outlook files I use pstbackup from Microsoft but if you know where your .pst or .ost files are you can use SyncBackFree to ensure they are backed up on a schedule.

Thanks for that. I'll also have a look at pstbackup.

Kremmen wrote:
Also don't forget to have a second backup on a portable drive that is only connected during a non scheduled manual backup. That prevents these crypto viruses corrupting all backups.

Excellent advice, I generally run a full virus scan first and then copy to an external portable hard drive that is only connected for the duration of the backup.

The section of the batch file that reads the ini file works well. However the batch file does not appear to run any of the code that follows the ini reading sub-routine.
_________________
Robert.
iPhone 6s Plus, iOS 14.0.1: iOS CamerAlert v2.0.7
TomTom GO Mobile iOS 2.3.1; TomTom (UK & ROI and Europe) iOS apps v1.29
Garmin Camper 770 LMT-D
Back to top
View user's profile Send private message Send e-mail







Posted: Today    Post subject: Pocket GPS Advertising

Back to top
Display posts from previous:   
Post new topic   Reply to topic    Pocket GPS World Forum Index -> Lost Satellite Fix - Off Topic Area All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB 2.0.11 © 2001 phpBB Group
phpBB port v2.1 based on Tom Nitzschner's phpbb2.0.6 upgraded to phpBB 2.0.4 standalone was developed and tested by:
ArtificialIntel, ChatServ, mikem,
sixonetonoffun and Paul Laudanski (aka Zhen-Xjell).

Version 2.1 by Nuke Cops 2003 http://www.nukecops.com

Make a Donation



CamerAlert Database

Click here for the PocketGPSWorld.com Speed Camera Database

Download Speed Camera Database
19.052 (12 May 21)



WORLDWIDE SPEED CAMERA SPOTTERS WANTED!

Click here to submit camera positions to the PocketGPSWorld.com Speed Camera Database


12mth Subscriber memberships awarded every week for verified new camera reports!

Submit Speed Camera Locations Now


CamerAlert Apps



iOS QR Code






Android QR Code







Terms & Privacy


GPS Shopping