Discussion:
Is there any way of mimicking the behaviour of 'choice.exe' with just standard commands and variables?
(too old to reply)
Arpeggio
2011-06-09 17:34:16 UTC
Permalink
Hi, I'm writing a batch that makes compressed backups from all the folders listed in it, with lots of options and safeguards. For certain things I need 'choice.exe' because it's the only one that let's you choose by inputing your option, waiting for a programmed amount of time for it, and then defaults to a pre-determined default option.

The thing is I want to have just my batch, just 1 file, and not making it dependent on external commands (not all MS Windows come with 'choice.exe'). Besides 'choice.exe' has the irritating tendency of not working as expected if the console window is out of focus, or hidden (the programmed waiting time becomes infinite :P)

I could use the 'SET' instruction to wait for an input, but unfortunately this one waits forever and I want to make my batch completely automated with no mandatory user input: pre-programmed options, some wait time for last minute choices in case the user is seeing the console screen, but those choices will turn to the default in case of no input is given. Completely independent of user action, completely automated.

So I would like to know if is it possible, with a set of instructions, to have the same effect of the CHOICE command, but without it?

Thank you very much in advance

Pedro
Tom Lavedas
2011-06-09 19:15:00 UTC
Permalink
Post by Arpeggio
Hi, I'm writing a batch that makes compressed backups from all the folders listed in it, with lots of options and safeguards. For certain things I need 'choice.exe' because it's the only one that let's you choose by inputing your option, waiting for a programmed amount of time for it, and then defaults to a pre-determined default option.
The thing is I want to have just my batch, just 1 file, and not making it dependent on external commands (not all MS Windows come with 'choice.exe'). Besides 'choice.exe' has the irritating tendency of not working as expected if the console window is out of focus, or hidden (the programmed waiting time becomes infinite :P)
I could use the 'SET' instruction to wait for an input, but unfortunately this one waits forever and I want to make my batch completely automated with no mandatory user input: pre-programmed options, some wait time for last minute choices in case the user is seeing the console screen, but those choices will turn to the default in case of no input is given. Completely independent of user action, completely automated.
So I would like to know if is it possible, with a set of instructions, to have the same effect of the CHOICE command, but without it?
Thank you very much in advance
Pedro
I wrote a hybrid batch/JScript routine a little while back that does
this. However, it relies on the keystroke stuffer, Sendkeys, to
implement the timeout function, so it does need to keep the focus for
the timeout to work. But, you're welcome to consider it ...

@if (@X)==(@Y) @goto :Dummy @end/* Batch part
@echo off
:: Syntax: call :GetInput VarName DelayInMS
call :GetInput Input 3000
:: Your code to use the input gores here ...
echo.For example: "%Input%"
exit /b

:GetInput
set "%1="&setlocal&set delay=%2 %/ milliseconds /%
set _d=>%temp%.\tmp1&set _d=>%temp%.\tmp2
set /p %1=Enter key here: < nul
for /f "delims=" %%I in (
'cscript //nologo //e:jscript "%~f0" %delay%'
) do endlocal & set "Input=%%I"
del %temp%.\tmp?.
echo.
goto :EOF

Jscript part */
var sh= new ActiveXObject('WScript.Shell');
var con=new ActiveXObject('Scripting.filesystemobject')
.opentextfile("con",2);
var d=WSH.Arguments(0),t=0,s='\x01';
var cmd='xcopy %temp%.\\tmp1 %temp%.\\tmp2 /p /y<con';

with(sh.Exec('%comspec% /k '+cmd+'&pause<con')){
while(s=='\x01'){
s='\x01';WSH.Sleep(240);t+=250;sh.sendkeys('\x01');
while(s!='?')s=StdOut.Read(1);
StdOut.Read(1); s=StdOut.Read(1);
if(t>d){
s='Timeout';sh.sendkeys('n');
WSH.Sleep(100);sh.sendkeys('.')
}
}
if('nNyYTimeout'.indexOf(s)==-1){
sh.sendkeys('n');WSH.Sleep(100);sh.sendkeys('.')
}
}
con.Write(s); // shows keyed character [optional]
WSH.Echo(s)
_____________________
Tom Lavedas
Tom Lavedas
2011-06-09 19:27:40 UTC
Permalink
Post by Tom Lavedas
Post by Arpeggio
Hi, I'm writing a batch that makes compressed backups from all the folders listed in it, with lots of options and safeguards. For certain things I need 'choice.exe' because it's the only one that let's you choose by inputing your option, waiting for a programmed amount of time for it, and then defaults to a pre-determined default option.
The thing is I want to have just my batch, just 1 file, and not making it dependent on external commands (not all MS Windows come with 'choice.exe'). Besides 'choice.exe' has the irritating tendency of not working as expected if the console window is out of focus, or hidden (the programmed waiting time becomes infinite :P)
I could use the 'SET' instruction to wait for an input, but unfortunately this one waits forever and I want to make my batch completely automated with no mandatory user input: pre-programmed options, some wait time for last minute choices in case the user is seeing the console screen, but those choices will turn to the default in case of no input is given. Completely independent of user action, completely automated.
So I would like to know if is it possible, with a set of instructions, to have the same effect of the CHOICE command, but without it?
Thank you very much in advance
Pedro
I wrote a hybrid batch/JScript routine a little while back that does
this.  However, it relies on the keystroke stuffer, Sendkeys, to
implement the timeout function, so it does need to keep the focus for
the timeout to work.  But, you're welcome to consider it ...
{code snipped}
Post by Tom Lavedas
_____________________
Tom Lavedas
There is an error in the initial routine in the GetInput routine. I
failed to remove a hard coded variable name when I modified the
routine to accept the name of the output variable. It should read
like this ...

:GetInput
set "%1="&setlocal&set delay=%2 %/ milliseconds /%
set _d=>%temp%.\tmp1&set _d=>%temp%.\tmp2
set /p %1=Enter key here: < nul
for /f "delims=" %%I in (
'cscript //nologo //e:jscript "%~f0" %delay%'
) do endlocal & set "%1=%%I"
del %temp%.\tmp?.
echo.
goto :EOF

The word "Input" in the last SET statement should be %1.

BTW, the routine returns the letter, not an errorlevel.
_____________________
Tom Lavedas
Todd Vargo
2011-06-09 20:36:24 UTC
Permalink
Post by Arpeggio
Hi, I'm writing a batch that makes compressed backups from all the folders
listed in it, with lots of options and safeguards. For certain things I
need 'choice.exe' because it's the only one that let's you choose by
inputing your option, waiting for a programmed amount of time for it, and
then defaults to a pre-determined default option.
The thing is I want to have just my batch, just 1 file, and not making it
dependent on external commands (not all MS Windows come with
'choice.exe'). Besides 'choice.exe' has the irritating tendency of not
working as expected if the console window is out of focus, or hidden (the
programmed waiting time becomes infinite :P)
I could use the 'SET' instruction to wait for an input, but unfortunately
this one waits forever and I want to make my batch completely automated
with no mandatory user input: pre-programmed options, some wait time for
last minute choices in case the user is seeing the console screen, but
those choices will turn to the default in case of no input is given.
Completely independent of user action, completely automated.
So I would like to know if is it possible, with a set of instructions, to
have the same effect of the CHOICE command, but without it?
Thank you very much in advance
"wait for an input" and "Completely independent of user action" are in
direct conflict by definition. I would use a parameter when automated to
bypass the user input section. As far as the one file issue goes, well, I
usually say if you can distribute one file, then two can be distributed just
as easily. OTOH, you could write your own executable to control the entire
process but that would not be very batch like.
--
Todd Vargo

(Post questions to group only. Remove "z" to email personal messages)
Arpeggio
2011-06-10 02:17:56 UTC
Permalink
Thanks :), it seems to work, a pity about the fact that has to be on focus, perhaps it's not a big deal, but that means the backups won't happen if I'm on a fullscreen app like a film or game.
Also, for some strange reason the script doesn't work with 'e', 'm' and 't' through 'p' (in querty sequence). Although that doesn't matter much, I'm a litle more concerned about the focus issue (not even 'choice' by Microsoft can deal with it right)
Anyway, amazing code, completely out of my league, I'll make more tests with it.

Thank you again,

Pedro
Tom Lavedas
2011-06-10 12:15:42 UTC
Permalink
Thanks :), it seems to work, a pity about the fact that has to be on focus, perhaps it's not a big deal, but that means the backups won't happen if I'm  on a fullscreen app like a film or game.
Also, for some strange reason the script doesn't work with 'e', 'm' and 't' through 'p' (in querty sequence). Although that doesn't matter much, I'm a litle more concerned about the focus issue (not even 'choice' by Microsoft can deal with it right)
Anyway, amazing code, completely out of my league, I'll make more tests with it.
Thank you again,
Pedro
Yeah, that bugged me when I went back and did a few tests. Then I
figured out the problem (which is one I thought I had fixed once
before). This statement has a string in it that it should not ...

if('nNyYTimeout'.indexOf(s)==-1){
sh.sendkeys('n');WSH.Sleep(100);sh.sendkeys('.')

It should not have the word "Timeout" in it. I don't know what I was
thinking when I did that. It should read ...

if('nNyY'.indexOf(s)==-1){
sh.sendkeys('n');WSH.Sleep(100);sh.sendkeys('.')

Then the letters T, i, m, e, o, u & t will work as expected.
_____________________
Tom Lavedas
foxidrive
2011-06-10 12:33:23 UTC
Permalink
Post by Tom Lavedas
before). This statement has a string in it that it should not ...
if('nNyYTimeout'.indexOf(s)==-1){
sh.sendkeys('n');WSH.Sleep(100);sh.sendkeys('.')
It should not have the word "Timeout" in it. I don't know what I was
thinking when I did that. It should read ...
if('nNyY'.indexOf(s)==-1){
sh.sendkeys('n');WSH.Sleep(100);sh.sendkeys('.')
Then the letters T, i, m, e, o, u& t will work as expected.
Tom, it'd be nice if you could post a full copy with the two changes,
for peeps of the future. And me.


Cheers
Mic
Tom Lavedas
2011-06-10 13:09:09 UTC
Permalink
Post by foxidrive
before).  This statement has a string in it that it should not ...
     if('nNyYTimeout'.indexOf(s)==-1){
       sh.sendkeys('n');WSH.Sleep(100);sh.sendkeys('.')
It should not have the word "Timeout" in it.  I don't know what I was
thinking when I did that.  It should read ...
     if('nNyY'.indexOf(s)==-1){
       sh.sendkeys('n');WSH.Sleep(100);sh.sendkeys('.')
Then the letters T, i, m, e, o, u&  t will work as expected.
Tom, it'd be nice if you could post a full copy with the two changes,
for peeps of the future.  And me.
Cheers
Mic
Here is a further update, with some other improvements (I got rid of
the temporary files and a little bug in the Timeout part) ...

@if (@X)==(@Y) @goto :Dummy @end/* Batch part
@echo off
:: Syntax: call :GetInput VarName DelayInMS
call :GetInput Ltr 3000
:: Your code to use the input goes here ...
echo.For example: "%Ltr%"
exit /b

:GetInput
set "%1="&setlocal&set /a delay=%2 %/ milliseconds /%
set "_d="
set /p %1=Enter key here: < nul
for /f "delims=" %%I in (
'cscript //nologo //e:jscript "%~f0" %delay% "%~f0"'
) do endlocal & set "%1=%%I"
echo.
exit /b

Jscript part */
var sh= new ActiveXObject('WScript.Shell');
var d=WSH.Arguments(0),t=0,s='\x01',n=WSH.Arguments(1);
var cmd='xcopy "'+n+'" "'+n+'" /p /y<con';
with(sh.Exec('%comspec% /k '+cmd+'&pause<con')){
while(s=='\x01'){
s='\x01';WSH.Sleep(240);t+=250;sh.sendkeys('\x01');
while(s!='?')s=StdOut.Read(1);
StdOut.Read(1);s=StdOut.Read(1);if(t>d){s='Timeout'}}
if('nNyY'.indexOf(s)==-1){
sh.sendkeys('n');WSH.Sleep(100);sh.sendkeys('.')}}
// shows keyed character [optional]
new ActiveXObject('Scripting.filesystemobject')
.opentextfile("con",2).Write(s);
//
WSH.Echo(s)
_____________________
Tom Lavedas
foxidrive
2011-06-10 13:25:21 UTC
Permalink
Post by Tom Lavedas
Post by foxidrive
Tom, it'd be nice if you could post a full copy with the two changes,
for peeps of the future. And me.
Here is a further update, with some other improvements (I got rid of
the temporary files and a little bug in the Timeout part) ...
Saved. Ta.
Arpeggio
2011-06-10 02:32:22 UTC
Permalink
My batch will display several times a message saying something like "it will be chosen the option 'X', you have 10 seconds to choose Y or Z instead", and then execute the proper code. The key here is the "it will be chosen", meaning it's independent from user input; yes, you can change a little something, but if not then by default the batch will chose one for you and run from the beginning to the end. It doesn't actually need input, although it may use it to customize itself a little more, that's it.
So, as Vader would say, there is no conflit ;)

I could put it in 2 files, yes, but someone (not me) would sooner or later loose the track of one of them. Besides it's much more cohese that way.
As for compiling it into an .exe, the out-of-focus problem of CHOICE would still remain for sure.

Pedro
foxidrive
2011-06-10 11:16:47 UTC
Permalink
Post by Arpeggio
My batch will display several times a message saying something like "it will be chosen the option 'X', you have 10 seconds to choose Y or Z instead", and then execute the proper code. The key here is the "it will be chosen", meaning it's independent from user input; yes, you can change a little something, but if not then by default the batch will chose one for you and run from the beginning to the end. It doesn't actually need input, although it may use it to customize itself a little more, that's it.
So, as Vader would say, there is no conflit ;)
As for compiling it into an .exe, the out-of-focus problem of CHOICE would still remain for sure.
I think Todd means to write the application entirely in a High level
language.

You can control timeout etc...
Todd Vargo
2011-06-11 04:13:29 UTC
Permalink
Post by foxidrive
Post by Arpeggio
My batch will display several times a message saying something like "it
will be chosen the option 'X', you have 10 seconds to choose Y or Z
instead", and then execute the proper code. The key here is the "it will
be chosen", meaning it's independent from user input; yes, you can change
a little something, but if not then by default the batch will chose one
for you and run from the beginning to the end. It doesn't actually need
input, although it may use it to customize itself a little more, that's
it.
So, as Vader would say, there is no conflit ;)
As for compiling it into an .exe, the out-of-focus problem of CHOICE
would still remain for sure.
I think Todd means to write the application entirely in a High level
language.
Correct.
Post by foxidrive
You can control timeout etc...
As mentioned in the original post, the batch can be run out of focus or even
hidden. In these cases, while a user is doing other things, the delay to
choose another option will not be visible to the user. I can appreciate the
need to have a timed message to allow the user an opportunity to abort while
I am in the middle of working on a deadline, but the message should be never
be presented out of focus or worse, hidden. ISTM, a VBScript .popup could be
used to provide a timeout with limited options, unfortunately, not the ones
the OP desires but here goes anyway.

@echo off
set msg="Do you want it to continue?"
set title="Backup will begin in 5 seconds."
echo> tmp.vbs Set WshShell = WScript.CreateObject("WScript.Shell")
echo>>tmp.vbs BtnCode = WshShell.Popup(%msg%, 5, %title%, 4 + 32)
echo>>tmp.vbs Wscript.Quit BtnCode
wscript tmp.vbs
if errorlevel 7 del tmp.vbs & goto :eof
del tmp.vbs
echo Continuing with backup...
--
Todd Vargo

(Post questions to group only. Remove "z" to email personal messages)
Arpeggio
2011-06-10 12:09:59 UTC
Permalink
Ah, well, my days of visualbasic, pascal and C++ are long gone :D
Besides I'm so close to finish it, it would be a hassle to start from 0 again.

Best regards,
Pedro
Arpeggio
2011-06-10 18:06:54 UTC
Permalink
I had an idea, an out-of-the-box way of achieving this (getting an input into variable within a certain amount of time, or else the variable will default to other value).
It's very clumbersome, but I intend to create a temporary batch by echoing commands and redirecting them to the temp batch:

Temporary batch will looks like this:

@ping 127.0.0.1 -n 5 -w 1000)
set "tempBatchVAR=%1"
exit
--------
then in the main batch I call it with:

Start "SOME TITLE" /WAIT tempz.cmd XPTO

(the XPTO will be the %1 of the 2nd batch)
From here 2 things can happen:
I let the temp batch complete the 5 sec delay and set that tempBatchVAR variable; or I press ctrl+C, the delay and the temp batch are interrupted and the tempBatchVAR variable will never be set. In the main batch I can then check this var value, which will either exist or not , so in essence I made an delayed input checker with a default in case of no input, depending on the satus of the variable.

Easier said than done:
1) If I interrupt the 2nd window batch by pressing ctrl+C, the 'Exit' command won't be executed so I have to manually write on the 2nd console for it to disappear.
2) I forgot that I can't aquire a variable that's inside a second batch process, but at least I can use the value of %errorlevel% instead.
3) When I press ctrl+C in the 2nd (temporary) console it asks me to confirm it with Y/N, but when exiting this window manually, the main one also asks for the same confirmation.

Do you guys know how to improve these 3 points, specially the 1 and 3?
Thanks

I hope you like my method, it's lame, but input with delays and/or with default values are extremely rare/difficult/unreliable in MS-DOS batch, so the more the merrier, right? :D

Best regards,

Pedro
foxidrive
2011-06-11 00:08:17 UTC
Permalink
Post by Arpeggio
3) When I press ctrl+C in the 2nd (temporary) console it asks me to
confirm it with Y/N, but when exiting this window manually, the main
one also asks for the same confirmation.
In the past this was eliminated by patching command.com
Post by Arpeggio
I hope you like my method, it's lame, but input with delays and/or
with default values are extremely rare/difficult/unreliable in MS-DOS
batch, so the more the merrier, right? :D
How about creating a text.ini file with the default values that you read
at the appropriate point in the batch file - this can be changed by
another batch file using choice to set all the entries, at launch time.
Arpeggio
2011-06-11 01:17:38 UTC
Permalink
But again, if someone is using a fullscreen app, either a movie, a youtube film, a game, or just working in a document in which it clicks back to the MSWord window right after the 2nd console appears because it doesn't want to be interrupted, the console window looses focus and Choice will be there forever waiting, even if you put just 3 seconds delay. And that's the most stupid thing about Choice: it needs focus. Why the hell needs it? I have never seen a program, with or without GUI that needs focus to work, unless done on purpose derived from the program's own concept. I really don't know what the MS guys were thinking when they programmed that 'thing', or why with such a BUG they never really upgraded it (just like IE6, I guess). At least they could add more options to the 'SET' command. Perhaps they were the same team behind Windows Millenium...
It doesn't even happens always, but +- 50-50% and I can't discover why. It's not even coherent, what kind of app is that? it's pathetic! Some guys made a Choice clone, "CHOOSE.exe", but the behaviour is exactly the same, I don't know why they even bothered...

Anyway, I'm thinking of using the configs in the batch file itself (1st page, very visible, some examples within REM comments, etc). Afterall, the paths to be backed up are stored in the batch, why not the rest of the configs too?
Not to mention that, having to press ctrl+C, confirm it, writing 'exit', and negate the confirm at the main window (not everybody will have the patched command.com), all that just to simulate a keypress is more than just clumbersome... it's bloody awful :(

Best regards,
Pedro
Arpeggio
2011-06-12 02:55:01 UTC
Permalink
Another good piece of software Todd, and it works even when out of focus; thanks.

As for what you mentioned about the need of of the message beeing in focus, that is true for important settings or preferences, not for small last minute changes. One of them could be the choosing of the type of compressor (rar, 7zip). One of the things I will implement it with, is an error check for some preferences, e.g. if the code detects an error in one of them, an error message will be displayed, with the option to choose a default preference, abort the script altoghether, and a timeout to that default pref. That way even if the user doesn't see or cares of the warning, the backup will still be made, which I think is the most important.

Best regards,
Pedro
foxidrive
2011-06-12 10:08:02 UTC
Permalink
Post by Arpeggio
user doesn't see or cares of the warning, the backup will still be
made, which I think is the most important.
I have a friend who loves automated things, including backups - but I
think backups should be looked after manually because if something fails
and then down the track you discover that you *need* that backup - and
the backup is not there...


Scheduling backups is fine - but I like to check that it's happening
*every time*.


Cheers
Mic
Auric__
2011-06-12 14:24:57 UTC
Permalink
Post by foxidrive
Post by Arpeggio
user doesn't see or cares of the warning, the backup will still be
made, which I think is the most important.
I have a friend who loves automated things, including backups - but I
think backups should be looked after manually because if something fails
and then down the track you discover that you *need* that backup - and
the backup is not there...
Scheduling backups is fine - but I like to check that it's happening
*every time*.
In cases like that, I'd have the backup program send some sort of
notification (email, text message to phone, whatever) when it ends, for good
or bad. Something like:
BACKUPAPP: Finished backing up files listed in "whatever.txt" at %TIME%.
BACKUPAPP: Unable to finish backing up files. See ERROR.LOG for details.
BACKUPAPP: Unable to start. See ERROR.LOG for details.
--
God kills indiscriminately and so shall we.
Arpeggio
2011-06-12 11:47:11 UTC
Permalink
In the end I'll put a final report, like if it succeeded, how well it succeeded, how many errors it encountered (only 2 will be allowed, at 3 it will abort).
Also some security measures like, if the archives deletetion from the harddrivewill only happen if they were successfully sended by email (errorlevel 0), etc. Of course I have options to always leave the archives in the harddrive, and for the report to be shown or leave immediatly.

Something that 's bothering me is the password of the sending mail account: Blat will send emails to your destination account, but for that will need a sender account *and* it's password. I think it's a too big of a security hole leaving the password in the batch as a variable, because in case someone copies the batch to a friend and forgets to delete that sensitive data, the friend will have complete access to that email account.
I can't ask for password input since the whole thing wouldn't be automated anymore, so I'm thinking of having a text file stored somewhere in the user harddisk, with the password. I'm just afraid that for newbies it's already too complicated.
I am thinking of the email password as an argument of the batch, like entering "backup.bat mypasswd012345", which I could use in blat as a "%1" argument. At windows task manager one would have to write that password along the path and name of the '.bat'. What do you think? I don't see anymore options.
I wich Blat was like this: http://www.webpagescreenshot.info/extensions/anonymousEmail/
it sends anonimously email wthout the need of a sending account.

Best regards,

Pedro
foxidrive
2011-06-12 12:05:42 UTC
Permalink
Post by Arpeggio
In the end I'll put a final report, like if it succeeded, how well it
succeeded, how many errors it encountered (only 2 will be allowed, at
3 it will abort). Also some security measures like, if the archives
deletetion from the harddrivewill only happen if they were
successfully sended by email (errorlevel 0), etc. Of course I have
options to always leave the archives in the harddrive, and for the
report to be shown or leave immediatly.
Something that 's bothering me is the password of the sending mail
account: Blat will send emails to your destination account, but for
that will need a sender account *and* it's password. I think it's a
too big of a security hole leaving the password in the batch as a
variable, because in case someone copies the batch to a friend and
forgets to delete that sensitive data, the friend will have complete
access to that email account. I can't ask for password input since
the whole thing wouldn't be automated anymore, so I'm thinking of
having a text file stored somewhere in the user harddisk, with the
password. I'm just afraid that for newbies it's already too
complicated. I am thinking of the email password as an argument of
the batch, like entering "backup.bat mypasswd012345", which I could
use in blat as a "%1" argument. At windows task manager one would
have to write that password along the path and name of the '.bat'.
Cmd history will have the password as well as the person looking over
your shoulder.

I forgot you were the guy using Gmail for backups. It'd be ok for small
things... otherwise the 30% encoding overhead and sending time would
blow out.

While I think having PD code is a good principal, I also think that
backups are too specific to each person for someone to just
drop-in-a-batch-file-and-run.

In many cases there would need to be extensive editing of files and
folders - and then testing of the created archives - to make sure
everything is accounted for and no typos have crept in.

What sort of things are you planning to backup? Text and docs are good
candidates as they compress well - but would you want your doc files to
end up as public documents? Gmail will be hacked one day, as Sony and
other places are being hacked currently.

JPG Pictures and MP3 don't compress well - and the size of the archive
would quickly mount. And I assume you can't going to archive your DVD
collection. :)

There's a few comments to kick start with...
--
Regards,
Mic
Arpeggio
2011-06-12 14:45:02 UTC
Permalink
(...) I also think that
backups are too specific to each person for someone to just
drop-in-a-batch-file-and-run.
The users will drop there the several paths they want to be compressed, with a bonus: you can add several specific files/folders to the main path, e.g. C:\library\ , now suposing that "library" is a huge folder with lots of subfolders and filetypes and you don't want to backup everything in there, just the .cpp, .txt and a subfolder named samples3, then you would write in one of the path vars MY_PATH3=C:\library\?*.cpp *.txt samples3\* , because rar, 7zip and others will understand that as inclusions. You can even add specific arguments for that path like -r -ms -x<exclusion folder> etc, that they will be understood by the compressor as switches. You can't be much more specific than that :) And the '?' will be used only by the routine that will guess the proper backup filename based on the actual path, to distinguish it from arguments, inclusions and switches, and will be removed at execution.
In many cases there would need to be extensive editing of files and
folders - and then testing of the created archives - to make sure
everything is accounted for and no typos have crept in.
In many cases there would need to be extensive editing of files and
folders - and then testing of the created archives - to make sure
everything is accounted for and no typos have crept in.

I guess you could do that in the first times, but at the 4th routinly scheduled backup, if you didn't change anything in the script, all things being equal and all that, it wouldn't be necessary. A litle like 'Time Machine' on OSX, or 'Restore points' in XP, they are completly made in the background, but you can check them if you want.

As for the things I want to compress, well, everything, but nothing too overkill like my DVD collection :)
You can also use skydrive, it has more space that gmail, and accepts files sended by email, but you have do 'dig' what is the virtual email address of your destination folder, and it only does accept emails with JPGs, you have to rename the archives extension :P But I could do that automatically, by putting a preference about the chosen storage service.

Yes, Gmail could be hacked someday, but also every other email or storage services around. If you don't want that then you can use the batch to only copy the backups to a chosen location (disk drive, flashdrive), but then again if someone stoles that media, or if some catastrophe happens to your hardware/house (I hope not :)) then you lose everything. There are always risks, there isn't the perfect solution. Anyway you can always put passwords in your archives to prevent the look of "greedy eyes".

Kind regards,

Pedro
foxidrive
2011-06-12 16:01:38 UTC
Permalink
Post by Arpeggio
The users will drop there the several paths they want to be
compressed, with a bonus: you can add several specific files/folders
to the main path, e.g.. C:\library\ , now suposing that "library" is
a huge folder with lots of subfolders and filetypes and you don't
want to backup everything in there, just the .cpp, .txt and a
subfolder named samples3, then you would write in one of the path
vars MY_PATH3=C:\library\?*.cpp *.txt samples3\* , because rar, 7zip
and others will understand that as inclusions. You can even add
specific arguments for that path like -r -ms -x<exclusion folder>
etc, that they will be understood by the compressor as switches. You
can't be much more specific than that :) And the '?' will be used
only by the routine that will guess the proper backup filename based
on the actual path, to distinguish it from arguments, inclusions and
switches, and will be removed at execution.
So wildcards using ? won't work??

Using the switches for the archiver means having to know them: will your
target audience know the archiver's switch set?
Post by Arpeggio
Post by foxidrive
In many cases there would need to be extensive editing of files
and folders - and then testing of the created archives - to make
sure everything is accounted for and no typos have crept in.
I guess you could do that in the first times
Yep, that's what I was getting at. People using the code need to
understand that.
Post by Arpeggio
As for the things I want to compress, well, everything, but nothing
too overkill like my DVD collection :)
You must have a small amount of data or a fast upstream connection to be
able to send all your data! Someone with a photography hobby could
have quite a collection of photos...
Post by Arpeggio
You can also use skydrive,
Yes, Gmail could be hacked someday, but also every other email or
storage services around.
But not a backup kept offsite at a friend's or families house.
Post by Arpeggio
Anyway you can always put passwords in your archives to
prevent the look of "greedy eyes".
That's not failsafe either.


I don't want to suggest that your solution has no merits, but I'm quite
convinced that backups shouldn't be a 'set and forget' thing. People
should take responsibility for their backups and know what is being
backed up, and when to change the backup when the source structure changes.

My friend would set it going and never check it again - I think that is
foolish trusting something so important to an automated task.

Mien you, one time when you *can* afford to do that is when you are
creating regular image backups of the entire drive, and keeping several
generations.
--
Regards,
Mic
Arpeggio
2011-06-12 14:51:58 UTC
Permalink
Those are good ideas, I already use a results screen and a .LOG file with some albeit limited details, in case anything goes wrong. As for the email notification, maybe I'll do that too, thanks :)
Arpeggio
2011-06-12 15:14:56 UTC
Permalink
Todd, not trying to abuse here, but is there a way of taking the focus out of the decision box from your code? Because I want it to be less obtrusive for a simple scheduled backup, but still visible if the user starts the batch manually. As it is now, even when running a fullscreen app the user sees it, as well as the whole windows taskbar.
I checked the syntax of the WshShell.Popup to see if it has something to do with those numbers, but they are only the button and icon config.

Many thanks,

Pedro
Todd Vargo
2011-06-13 20:28:32 UTC
Permalink
Post by Arpeggio
Todd, not trying to abuse here, but is there a way of taking the focus out
of the decision box from your code? Because I want it to be less obtrusive
for a simple scheduled backup, but still visible if the user starts the
batch manually. As it is now, even when running a fullscreen app the user
sees it, as well as the whole windows taskbar.
I checked the syntax of the WshShell.Popup to see if it has something to
do with those numbers, but they are only the button and icon config.
Many thanks,
Pedro, when responding to posts in a newsgroup, it is appropriate to quote a
relative portion of the message which you are responding to so others
reading know what it refers to.

As I mentioned in my first post, "I would use a parameter when automated to
bypass the user input section." The following modification does that. You
simply add the parameter, "scheduled", to the command line in the scheduler.

@echo off
if /i %1. equ scheduled goto :begin
set msg="Do you want it to continue?"
set title="Backup will begin in 5 seconds."
echo> tmp.vbs Set WshShell = WScript.CreateObject("WScript.Shell")
echo>>tmp.vbs BtnCode = WshShell.Popup(%msg%, 5, %title%, 4 + 32)
echo>>tmp.vbs Wscript.Quit BtnCode
wscript tmp.vbs
if errorlevel 7 del tmp.vbs & goto :eof
del tmp.vbs
echo Continuing with backup...
:begin
echo backup code goes here.
--
Todd Vargo

(Post questions to group only. Remove "z" to email personal messages)
Arpeggio
2011-06-12 18:25:01 UTC
Permalink
Post by foxidrive
So wildcards using ? won't work??
Actually they will, only the 1st '?' (the separator) will be deleted, but if it brings confusion I could substitute it with a '/'
Post by foxidrive
Using the switches for the archiver means having to know them: will your
target audience know the archiver's switch set?
The switches are optional, just for refinement; if some users don't know how to use them, then they will put there just the main folder, or use 'my_path<1> through <n> for the subfolders, instead of putting it all in a command line.
The point is, it isnt' harder than writing the same normal compress operation in the command line using switches, so the ones who can understand it will have no trouble in this. Call it "a bonus for power users".
Post by foxidrive
Post by Arpeggio
I guess you could do that in the first times
Yep, that's what I was getting at. People using the code need to
understand that.
Well the same could be said of any other backup utility, so people should known that already (wishful thinking, I know); but I understand that I can't have the same trust than a renowed software house, though.
Post by foxidrive
You must have a small amount of data or a fast upstream connection to be
able to send all your data! Someone with a photography hobby could
have quite a collection of photos...
As I said, not too overkill, no mp3 collections and all that, just work docs, browser settings, address books, todo lists, notes, (bookmarks, passwords) and all those things that change a lot day by day and you don't remember to backup up all the time, those things that are scattered through all your hard-drive, that sometimes you forget a few...
Post by foxidrive
Post by Arpeggio
Yes, Gmail could be hacked someday, but also every other email or
storage services around.
But not a backup kept offsite at a friend's or families house.
Is your friend's house that safe? As I said before, what about catastrophes? fires, floods, robbery... a meteor :P , or the 'small things' like strong magnetic fields near the magnetic drives, data decaying of the optical drives...
Besides, you really think a house is safer that cloud servers with redundant data and recovery systems? maybe, maybe not, so I made the option of storing both in a physical media and in the cloud.
Post by foxidrive
Post by Arpeggio
Anyway you can always put passwords in your archives to
prevent the look of "greedy eyes".
That's not failsafe either.
Not for data integrity, but for data privacy it's a huge help (you can set the passes with switches in the path variable, by the way). Besides is better than no protection.
Post by foxidrive
I don't want to suggest that your solution has no merits, but I'm quite
convinced that backups shouldn't be a 'set and forget' thing. People
should take responsibility for their backups and know what is being
backed up, and when to change the backup when the source structure changes.
My friend would set it going and never check it again - I think that is
foolish trusting something so important to an automated task.
Yes, but previously my 'conscious backups' were a lot sparse then I hoped for, and many times I thought I had them and I didn't (or did but were bery old). My automated method (although a lot less sofisticated than this one) saved my on numerous ocasions.
At least is a lot better than the manual conscious backups that one should have done but never did. I don't say people to trust my batch only, they can easily use it in conjunction with other backup programs.
But I understand you to a point: those very important things, unique that costed you a lot to get and whatever, should be backed up immediatly, and not waiting for the "next scheduled backup".
My batch is more for those "numerous little things that I wish I backed up".
Besides I don't need to backup *all* my data, no one does, there are always data that is redundant, that you can easily get with other means, or simply isn't that important.


Best regards,
Pedro
foxidrive
2011-06-12 20:47:45 UTC
Permalink
Post by Arpeggio
Post by foxidrive
So wildcards using ? won't work??
Actually they will, only the 1st '?' (the separator) will be deleted,
but if it brings confusion I could substitute it with a '/'
Pedro, if you use a pipe | for example it can't appear as a switch or
part of a command. I use it to delimit directory lists becuase it can't
appear in them naturally.
Post by Arpeggio
The switches are optional, Call it "a bonus for power users".
:)
Post by Arpeggio
Post by foxidrive
Post by Arpeggio
I guess you could do that in the first times
Yep, that's what I was getting at. People using the code need to
understand that.
Well the same could be said of any other backup utility, so people
should known that already (wishful thinking, I know); but I
understand that I can't have the same trust than a renowed software
house, though.
In this case it is not trust per se, but because the paths are typed
manually, and not selected from a dialog box, then error can easily
creep in as a simple typo or from not paying attention. This is why
the initial backups need to be thoroughly checked - and the users made
aware of the fact.
Post by Arpeggio
As I said, not too overkill, no mp3 collections and all that, just
work docs, browser settings, address books, todo lists, notes,
(bookmarks, passwords) and all those things that change a lot day by
day and you don't remember to backup up all the time, those things
that are scattered through all your hard-drive, that sometimes you
forget a few...
Indeed. I do full backups monthly and backups of changeable items in
certain folders when I run my update.bat on a whim.
Post by Arpeggio
Post by foxidrive
Post by Arpeggio
Yes, Gmail could be hacked someday, but also every other email
or storage services around.
But not a backup kept offsite at a friend's or families house.
Is your friend's house that safe?
It can't be hacked by an online thief.
But sure, it can also be burgled.
Post by Arpeggio
Besides, you really think a house
is safer that cloud servers with redundant data and recovery systems?
Yes, when the house is for an offsite backup.

Who is to know if the cloud provider does indeed have these things?
Have you not heard about the backups in the cloud failing, because the
provider didn't keep regular backups? Recently there was news about
cloud backup providers closing shop and there was no way to retreive
your data, and they had no means to transfer it to another provider.
Post by Arpeggio
maybe, maybe not, so I made the option of storing both in a physical
media and in the cloud.
Gmail will be a target for hackers - I don't trust them with my email
let alone any personal data. I trust to multiple physical backups.
Post by Arpeggio
Post by foxidrive
Post by Arpeggio
Anyway you can always put passwords in your archives to prevent
the look of "greedy eyes".
Besides is better than no protection.
It may as well be no protection, to a dedicated hacker with lots of time. :)
Post by Arpeggio
Yes, but previously my 'conscious backups' were a lot sparse then I
hoped for, and many times I thought I had them and I didn't (or did
but were bery old). My automated method (although a lot less
sofisticated than this one) saved my on numerous ocasions.
It's easy to enter a reminder (like using ReminderFox addin for Firefox
and Thunderbird) for the 1st of the month, or your favourite day.
Post by Arpeggio
At least
is a lot better than the manual conscious backups that one should
have done but never did. I don't say people to trust my batch only,
they can easily use it in conjunction with other backup programs. But
I understand you to a point: those very important things, unique that
costed you a lot to get and whatever, should be backed up immediatly,
and not waiting for the "next scheduled backup". My batch is more for
those "numerous little things that I wish I backed up"..
I've lapsed too and left it undone, so I know what you are saying.


So now you are left with a timeout problem....

How about writing a temp batch file to get input?

This writes a temp batch file to get data - and allows 15 seconds to get
input, and repeats that 4 times. If there is a flag file with the data
in it then you can parse that to get the input.

It launches the temp bat file minimised - is that what you want to do?



@echo off

for /L %%a in (1,1,4) do (
Post by Arpeggio
Post by foxidrive
temp.bat echo set /p "var=Enter a value (15 seconds - try %%a of 4): "
temp.bat echo echo "%%var%%"^>flag.tmp
start "Inputz" /min temp.bat
ping -n 15 localhost >nul
taskkill /F /FI "WINDOWTITLE eq Inputz*" >nul
del temp.bat
)

if exist flag.tmp (
echo got parameter from flag.tmp
type flag.tmp
) else (
echo no data
)
del flag.tmp 2>nul
pause
--
Regards,
Mic
Arpeggio
2011-06-13 00:08:38 UTC
Permalink
Post by foxidrive
Pedro, if you use a pipe | for example it can't appear as a switch or
part of a command. I use it to delimit directory lists becuase it can't
appear in them naturally.
I know, but pipe is reserved in batch to pass parameters between programs, to bypass that I would have to put quotes in the beggining and end of every path variable, messing with my code that already deals with quotes, quotes inside subpaths, paths with spaces, etc. The '/' is not used by the filesystem, switches nor batch language, so it's the ideal char.
Post by foxidrive
In this case it is not trust per se, but because the paths are typed
manually, and not selected from a dialog box, then error can easily
creep in as a simple typo or from not paying attention. This is why
the initial backups need to be thoroughly checked - and the users made
aware of the fact.
Your're right, good point :)
Post by foxidrive
Who is to know if the cloud provider does indeed have these things?
Have you not heard about the backups in the cloud failing, because the
provider didn't keep regular backups? Recently there was news about
cloud backup providers closing shop and there was no way to retreive
your data, and they had no means to transfer it to another provider.
How "professional" of them... That's why I trust my backups to big names like Google or Microsoft. I mean, it will take a lot more for those guys to fail than the others. (And yet I read some days ago that Amazon cloud storage was attacked or something...:P)
Actually I also use not-so-big names like Adrive, it can be less safe because of that but, darn, 50Gigs, 2G máx per file, for free? :D I use it as redundant backup, and to share DVDs I make.
Post by foxidrive
Gmail will be a target for hackers - I don't trust them with my email
let alone any personal data. I trust to multiple physical backups.
Well, any big company is a target, as well as Microsoft, Yahoo and others, and Google isn't less safe than the other two. But you can choose any other company.
Post by foxidrive
Post by Arpeggio
Post by Arpeggio
Anyway you can always put passwords in your archives to prevent
the look of "greedy eyes".
Besides is better than no protection.
It may as well be no protection, to a dedicated hacker with lots of time. :)
Well, then I guess cloud storage just isn't your thing :)



About your code, it's a very good idea, and to answer your question it's almost what I want (not pretending to be too pesky) but the ideal would be not minimized but just normal and without focus, but I guess that isn't possible with batch (or Todd's basic script), so I will have to decide which one too choose: normal with focus or minimized (one is too 'down you throat' and the other too invisible). By playing with your code I already know that it's the /MIN switch that minimizes the window. Maybe I choose minimized and put in the main window a warning saying there's another window minimized asking a question about <whatever> in case someone wants to answer :D

Tank you for your comments,

Pedro
Dr J R Stockton
2011-06-14 18:58:35 UTC
Permalink
In alt.msdos.batch.nt message <11d6c272-fa79-4c8d-a04f-***@gleg
roupsg2000goo.googlegroups.com>, Sun, 12 Jun 2011 17:08:38, Arpeggio
Post by Arpeggio
Post by foxidrive
Pedro, if you use a pipe | for example it can't appear as a switch or
part of a command. I use it to delimit directory lists becuase it can't
appear in them naturally.
I know, but pipe is reserved in batch to pass parameters between programs, to bypass that I would have to put quotes in the beggining and end
of every path variable, messing with my code that already deals with quotes, quotes inside subpaths, paths with spaces, etc. The '/' is not
used by the filesystem, switches nor batch language, so it's the ideal char.
You should by now have become aware that Usenet convention is to limit
line-length of test to 72 characters. Go beyond 80, and, although your
characters will be delivered, they may not be seen.
--
(c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
Web <http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
Arpeggio
2011-06-16 16:59:25 UTC
Permalink
Post by Todd Vargo
Pedro, when responding to posts in a newsgroup, it is appropriate to quote a
relative portion of the message which you are responding to so others
reading know what it refers to.
I know, but at that time my message was one of the few directly threaded from yours, so I didn't think it was necessary (and before my long conversation with Foxidrive).

Thanks for your code. One or two days more, and I finnish it :)

Pedro

Loading...