User input in .bat Datei

September 27, 2009 at 08:08:12
Specs: Windows XP
Hi,

ich kenne mich mit DOS leider ueberhaupt nicht aus, ich bin damals mit Apple Macintosh aufgewachsen, dann war Windows da.

Ich habe mir eine winzige bat Datei gebastelt, um mithilfe eines user inputs ein Programm starten zu lassen oder nicht.
Es handelt sich um meinen persoenlichen Kalender auf USB stick, den ich wegen meiner Termine und Reminder fuer mich sehr wohl autostarten lassen moechte, aber wenn ich mit wem anderen mit dem Stick arbeite, moechte ich gern diesen Autostart unterbinden. Logisch, geht ja niemanden was an und braucht nur Ladezeit.

Hier mein Programm soweit:

@echo off
set /p userinput= Start EPIM? [y/n]:
if "%userinput%"=="y" START /min \PortableApps\EssentialPIM\EssentialPIM.exe
if "%userinput%"=="n" exit else EXIT
: ==>if userinput ist ENTER ohne sonstwas -> Exit :
cls
rem exit

Mein Problem ist (da es ja, wenn ich das richtig verstanden habe, den CHOICE Befehl unter XP nicht mehr gibt), dass man nicht einfach mit y oder n antworten kann, sondern danach Enter druecken muss. Ich habe auch nichts gefunden, ob man mit Esc rauskommt. Die Idee ist, dass ich/man mit einem Tastendruck das Programm starten oder den Autostart abbrechen kann. Enter allein funktioniert (s.o.), aber weiter komme ich nicht. Ich habe was gefunden mit INKEY aber nicht verstanden, wie das gehen soll.

Eventuell gibts auch einen Weg, dass das Programm nach einer gewissen Wartezeit (z.b. 4 Sekunden) automatisch startet, ich aber innerhalb dieser Zeit mit irgendeiner Eingabe (e.g. Enter oder Esc oder n) den Autostart abbrechen kann?

Danke schonmal,
niki


See More: User input in .bat Datei

Report •


#1
September 27, 2009 at 08:16:56
he says :

"Hi,

I know myself with DOS, unfortunately not available at all, then I grew up with Apple Macintosh, then Windows was there.

I have a tiny bat file handicrafts to make using a user inputs start a program or not.
It is my personal calendar on a USB stick, which I for my appointments and reminder for me to auto start would like very much, but when I work with others with whom the stick, I'd like to disable this startup. Logically, yes, what is nobody's, and only needs charging.

Here is my program so far:

"the code"

My problem is (as it so, if I understood correctly, the CHOICE command in XP no longer exists) that one can not simply respond with y or n, but must then press ENTER. I have not found anything, whether it comes out with Esc. The idea is that I can run / one touch of a button, the program or cancel the startup. Enter key work on its own ,but again I don`t know how it works.

Maybe there is also a way to have the program automatically after a certain waiting period (eg 4 seconds) will start, but I do within this time any input eg (Enter or Esc or n) can cancel the auto-start?

thanks,
niki

our patience is big


Report •

#2
September 27, 2009 at 08:21:37
I'm very sorry, I copied my problem from a German forum and forgot to translate it! I hope someone will be able to help me.

I am rather clueless at DOS having grown up with Apple Macintosh and then Windows, nevertheless I have tried to write up a tiny .bat file in order to depend a programme autostarting or not. The programme is a personal scheduler on my usb stick and with its reminders it makes sense to autostart for me, but using the stick with someone else my appointments are obviously nobody's business and only annoying when loading.

here's my little .bat file:

@echo off
set /p userinput= Start EPIM? [y/n]:
if "%userinput%"=="y" START /min \PortableApps\EssentialPIM\EssentialPIM.exe
if "%userinput%"=="n" exit else EXIT
: ==>if userinput ist ENTER ohne sonstwas -> Exit :
cls
rem exit

As far as I have understood, the CHOICE command is not supported under XP. Here's my problem: I would like to make the choice between autostart my scheduler or not with a single key stroke. Enter works for one of the two choices, assuming that no character + Enter was a choice. Y or N need pressing Enter. Escape doesn't work to close the DOS window. I have stumbled upon a command INKEY, but not understood, how it works.
I have also tried out ideas where the autostart happens after e.g. 4 seconds and where I could cancel with my input (e.g. Enter, Escape, n) within this time - no idea though how to accomplish this.

Any ideas?

Many thanks in advance
niki


Report •

#3
September 27, 2009 at 08:23:10
I was too slow, thanks for the translation!!

Report •

Related Solutions

#4
September 27, 2009 at 08:24:32
you`re welcome...

our patience is big


Report •

#5
September 27, 2009 at 08:32:43
It sounds like you want to use a VBScript:
With CreateObject("WScript.Shell")
  If .Popup("Start EPIM?", 4, "", 4) = 6 Then _
    .Run "\PortableApps\EssentialPIM\EssentialPIM.exe", 6
End With


Report •

#6
September 27, 2009 at 08:40:57
Wow!! No idea about scripting, I guessed I had to save your suggestion as a .vbs file, and it works like a charm, thanks a million for the superspeedy help!!

Is there an option like /min in the DOS thing to start it minimized?


Report •

#7
September 27, 2009 at 08:48:09
That 6 at the end of the .Run line should minimize it and not activate the window. If that's not working, try 7 or 2.

Report •

#8
September 27, 2009 at 08:57:14
Cool stuff, "2" doesn't, but with "7" it works!

I'm not a programmer, I never considered getting familiar with scripting, but I guess I will now, there seems to be a whole new world of possibilities, thanks a lot!

lg
niki


Report •


Ask Question