Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to prompt at runtime from a batch file in a GUI way?

90 views
Skip to first unread message

Kenny McCormack

unread,
Apr 18, 2015, 3:39:20 PM4/18/15
to
So, I have written a batch file, and it works fine from the CMD.EXE prompt.

However, one of the users doesn't like the prompt and wants to run it by
double-clicking. But the batch file needs a parameter (%1).

Is there any way to make the script put up a GUI window and prompt for that
parameter (if it detects that %1 is empty) ?

I seem to remember once, long ago, on some OS, perhaps it was Windows,
perhaps it wasn't, where this was possible - that you defined something in
the icon (or, back in those days, in the "PIF" file) that caused it to
prompt at runtime for the parameter...

BTW, if there is no obvious/built-in way, I can always do this in WinBatch,
but I was curious if there was an obvious/built-in way. In particular, I'm
not interested in VBS/cscript/whatever methods.

--
A liberal, a moderate, and a conservative walk into a bar...

Bartender says, "Hi, Mitt!"

foxidrive

unread,
Apr 19, 2015, 3:50:28 AM4/19/15
to
On 19/04/2015 05:39, Kenny McCormack wrote:
> So, I have written a batch file, and it works fine from the CMD.EXE prompt.
>
> However, one of the users doesn't like the prompt and wants to run it by
> double-clicking. But the batch file needs a parameter (%1).
>
> Is there any way to make the script put up a GUI window and prompt for that
> parameter (if it detects that %1 is empty) ?
>
> I seem to remember once, long ago, on some OS, perhaps it was Windows,
> perhaps it wasn't, where this was possible - that you defined something in
> the icon (or, back in those days, in the "PIF" file) that caused it to
> prompt at runtime for the parameter...

This technique no longer works in modern windows.

You can use something like this and then use %input% in place of %1

@echo off
set "input=%~1"
if "%~1"=="" set /p "input= How many beers can you drink? : "
echo You wuss. Only %input%?
pause



Kenny McCormack

unread,
Apr 19, 2015, 4:39:20 AM4/19/15
to
In article <55335e42$0$41722$c3e8da3$5d8f...@news.astraweb.com>,
Right, but that obviously doesn't meet the requirements (which is that a
GUI window comes up).

Obviously, I already knew about "set /p", but it isn't the point.

--
"I heard somebody say, 'Where's Nelson Mandela?' Well,
Mandela's dead. Because Saddam killed all the Mandelas."

George W. Bush, on the former South African president who
is still very much alive, Sept. 20, 2007

foxidrive

unread,
Apr 19, 2015, 5:20:48 AM4/19/15
to
On 19/04/2015 18:39, Kenny McCormack wrote:
> Right, but that obviously doesn't meet the requirements (which is that a
> GUI window comes up).


> Obviously, I already knew about "set /p", but it isn't the point.

It wasn't obvious at all - you said nothing about what you knew and were
talking about techniques from Win9x.


Todd Vargo

unread,
Apr 20, 2015, 3:39:35 AM4/20/15
to
On 4/18/2015 3:39 PM, Kenny McCormack wrote:
> So, I have written a batch file, and it works fine from the CMD.EXE prompt.
>
> However, one of the users doesn't like the prompt and wants to run it by
> double-clicking. But the batch file needs a parameter (%1).
>
> Is there any way to make the script put up a GUI window and prompt for that
> parameter (if it detects that %1 is empty) ?
>
> I seem to remember once, long ago, on some OS, perhaps it was Windows,
> perhaps it wasn't, where this was possible - that you defined something in
> the icon (or, back in those days, in the "PIF" file) that caused it to
> prompt at runtime for the parameter...
>
> BTW, if there is no obvious/built-in way, I can always do this in WinBatch,
> but I was curious if there was an obvious/built-in way. In particular, I'm
> not interested in VBS/cscript/whatever methods.
>

If there was an "obvious" way, people would not be asking and WinBatch
would not exist.

Since you have excluded VBS, and your other post excludes SET/P, you
might as well just use WinBatch since you obviously have it accessible
and know how to use it.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Kenny McCormack

unread,
Apr 21, 2015, 12:39:17 AM4/21/15
to
In article <mh2afl$v97$1...@news.albasani.net>,
Todd Vargo <tlv...@sbcglobal.netz> wrote:
...
>> BTW, if there is no obvious/built-in way, I can always do this in WinBatch,
>> but I was curious if there was an obvious/built-in way. In particular, I'm
>> not interested in VBS/cscript/whatever methods.
>>
>
>If there was an "obvious" way, people would not be asking and WinBatch
>would not exist.
>
>Since you have excluded VBS, and your other post excludes SET/P, you
>might as well just use WinBatch since you obviously have it accessible
>and know how to use it.

Yup. So it would seem.
(As you say, I have access to it, and am quite happy using it)

Like I said, I did have a vague memory of this being possible (using
only existing - i.e., non-third-party - tools) at one point in the distant
past (either in Win 3.x, or 9x, or maybe even OS/2, days). But, yeah, it
doesn't seem to be "in the mix" in current versions of Windows...

Besides, isn't the whole point of this particular newsgroup to
seek/demonstrate/publicize ways of doing things that use only the
existing/built-in/non-third-party tools - no matter how
grotesque/kludgey/ugly those methods end up looking & being?

So, it was in that spirit that I was asking if there was a built-in way to
do it.

--
"The God of the Old Testament is arguably the most unpleasant character
in all fiction: jealous and proud of it; a petty, unjust, unforgiving
control-freak; a vindictive, bloodthirsty ethnic cleanser; a misogynistic,
homophobic, racist, infanticidal, genocidal, filicidal, pestilential,
megalomaniacal, sadomasochistic, capriciously malevolent bully."

- Richard Dawkins, The God Delusion -

foxidrive

unread,
Apr 21, 2015, 1:48:33 AM4/21/15
to
On 21/04/2015 14:39, Kenny McCormack wrote:
> Besides, isn't the whole point of this particular newsgroup to
> seek/demonstrate/publicize ways of doing things that use only the
> existing/built-in/non-third-party tools - no matter how
> grotesque/kludgey/ugly those methods end up looking & being?
>
> So, it was in that spirit that I was asking if there was a built-in way to
> do it.

Once upon a time everything was so limited that hyper-universe-spanning
batch files were always used to do even the most simplest things.

It was all much fun then - but fast forward to modern times and people ask
for solutions and too often omit even the slightest accurate details - and
then after they get a solution they tell you it doesn't work (because they
omitted actual data) or they suddenly tell you that they can't use the
technique you chose - and that it needs to be made from rocks and straw.

I tend to chose the most robust solutions, or the easiest to implement -
...and people still have trouble with the T word.


Kenny McCormack

unread,
Apr 21, 2015, 8:31:13 AM4/21/15
to
In article <5535e4b1$0$44779$c3e8da3$dd96...@news.astraweb.com>,
foxidrive <foxi...@server.invalid> wrote:
>On 21/04/2015 14:39, Kenny McCormack wrote:
>> Besides, isn't the whole point of this particular newsgroup to
>> seek/demonstrate/publicize ways of doing things that use only the
>> existing/built-in/non-third-party tools - no matter how
>> grotesque/kludgey/ugly those methods end up looking & being?
>>
>> So, it was in that spirit that I was asking if there was a built-in way to
>> do it.
>
>Once upon a time everything was so limited that hyper-universe-spanning
>batch files were always used to do even the most simplest things.

Interesting turn-of-phrase there...

>It was all much fun then - but fast forward to modern times and people ask
>for solutions and too often omit even the slightest accurate details - and
>then after they get a solution they tell you it doesn't work (because they
>omitted actual data) or they suddenly tell you that they can't use the
>technique you chose - and that it needs to be made from rocks and straw.

But isn't that still pretty much the rule here - that we have to use only
what MS provides? Which, nowadays does include both VBS and (shudder)
Powershell...

Note that I've never used either of these, since, like all MS products,
they both seem like too little, too late. WinBatch does everything I need,
and is a very nice, well-supported product.

>I tend to chose the most robust solutions, or the easiest to implement -
>...and people still have trouble with the T word.

I suppose I should know, but which "T word" ?

--

There are many self-professed Christians who seem to think that because
they believe in Jesus' sacrifice they can reject Jesus' teachings about
how we should treat others. In this country, they show that they reject
Jesus' teachings by voting for Republicans.

Kenny McCormack

unread,
Apr 21, 2015, 8:35:20 AM4/21/15
to
In article <5533736f$0$26128$b1db1813$7946...@news.astraweb.com>,
foxidrive <foxi...@server.invalid> wrote:
>On 19/04/2015 18:39, Kenny McCormack wrote:
>> Right, but that obviously doesn't meet the requirements (which is that a
>> GUI window comes up).
>
>
>> Obviously, I already knew about "set /p", but it isn't the point.
>
>It wasn't obvious at all - you said nothing about what you knew

The clue was the word "GUI" in the OP (set/p is obviously TUI).

>and were talking about techniques from Win9x.

Only by "external reference" - I.e., by saying that we used to do those
things "way back when"...

--
In the corner of the room on the ceiling is a large vampire bat who
is obviously deranged and holding his nose.

npocmaka

unread,
Apr 21, 2015, 11:26:44 AM4/21/15
to
::====================================================
@echo off

rem --
setlocal
if /I "%~1" equ "-HELP" (
call :help
goto :eof
)


if "%~2" equ "" (
goto :UI
)

rem -- deleting all content in result folder to prevent
rem data collisions
rem --
del "%~2\*" /Q /F >nul 2>&1
set result_dir="%~2"
rem -- getting the short name of source file to deal with eventual
rem spaces in its name
rem --
set sourse=%~1

goto :skip_UI

:UI
set "file_selector="about:^<Title^>- ### SELECT FILE ### -^</Title^>^<body^>^<script^>window.resizeTo(500,200);function p(){var f=document.getElementById('f').value;var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(f)); }^</script^>^<input type='file' name='f' size='20'^>^</input^>^<button onclick='p()'^>Submit^</button^>^<body^>""

if not defined sourse echo select the file& for /f "tokens=* delims=" %%a in ('
mshta %file_selector%
') do (
set "sourse=%%~a"
)

set "destination_ch="about:^<Title^>- ### DESTINATION FOLDER ### -^</Title^>^<body^>^<script^>window.resizeTo(500,200);function p(){var f=document.getElementById('f').value;var fso= new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(f)); }^</script^>^<input type='text' name='f' size='20'^>^</input^>^<button onclick='p()'^>Choose^</button^>^<body^>""

:resubmit
if not defined result_dir echo choose name for destination folder & for /f "tokens=* delims=" %%a in ('
mshta %destination_ch%
') do (
set "result_dir=%%~a"
)

if not defined result_dir (
echo YOU MUST CHOOSE DIRECTORY NAME FOR RESULT FILES!!
goto :resubmit
)

echo %result_dir% | find ":" >nul 2>&1 || (
set "result_dir=%~dp0%result_dir%"
)
echo FILES WILL BE STORED IN "%result_dir%"
del "%result_dir%\*" /Q /F >nul 2>&1



:skip_UI

echo %result_dir%

::====================================================

Something that I've written some time ago.Check if this technique aplies your needs.

Herbert Kleebauer

unread,
Apr 21, 2015, 4:57:38 PM4/21/15
to
On 19.04.2015 10:39, Kenny McCormack wrote:

>> @echo off
>> set "input=%~1"
>> if "%~1"=="" set /p "input= How many beers can you drink? : "
>
> Right, but that obviously doesn't meet the requirements (which is that a
> GUI window comes up).
>
> Obviously, I already knew about "set /p", but it isn't the point.

Obviously there are only GUI windows since Win7. Seems you just want
a second window for input:


@echo off
if [%1]==[?] goto popup
set file_name=%1
if not [%1]==[] goto :ok
start /w cmd /c %0 ?
call _.bat
del _.bat

:ok
echo %file_name%
goto :eof


:popup
cls
mode con cols=67 lines=9
color ca
echo.
echo ******************************************************************
echo ** **
echo ** Missing parameter **
echo ** **
echo ** **
echo ******************************************************************

set /p file_name=Enter file name:
echo set file_name=%file_name%>_.bat


Todd Vargo

unread,
Apr 21, 2015, 9:12:48 PM4/21/15
to
On 4/21/2015 12:39 AM, Kenny McCormack wrote:
> In article <mh2afl$v97$1...@news.albasani.net>,
> Todd Vargo <tlv...@sbcglobal.netz> wrote:
> ....
>>> BTW, if there is no obvious/built-in way, I can always do this in WinBatch,
>>> but I was curious if there was an obvious/built-in way. In particular, I'm
>>> not interested in VBS/cscript/whatever methods.
>>>
>>
>> If there was an "obvious" way, people would not be asking and WinBatch
>> would not exist.
>>
>> Since you have excluded VBS, and your other post excludes SET/P, you
>> might as well just use WinBatch since you obviously have it accessible
>> and know how to use it.
>
> Yup. So it would seem.
> (As you say, I have access to it, and am quite happy using it)

Ok, so just use it and be happy.

>
> Like I said, I did have a vague memory of this being possible (using
> only existing - i.e., non-third-party - tools) at one point in the distant
> past (either in Win 3.x, or 9x, or maybe even OS/2, days). But, yeah, it
> doesn't seem to be "in the mix" in current versions of Windows...

That method would be via VBS but you specifically excluded it.

>
> Besides, isn't the whole point of this particular newsgroup to
> seek/demonstrate/publicize ways of doing things that use only the
> existing/built-in/non-third-party tools - no matter how
> grotesque/kludgey/ugly those methods end up looking & being?

In a nutshell, the purpose of this news group is to "discuss batch". Not
solve everyone's batch related problems with complete spoon-fed batch code.

>
> So, it was in that spirit that I was asking if there was a built-in way to
> do it.
>

You would have to withdraw your VBS restriction. Unfortunately, at this
point, I have lost interest with this thread. Happy WinBatching, Kenny.

foxidrive

unread,
Apr 21, 2015, 10:54:24 PM4/21/15
to
On 21/04/2015 22:31, Kenny McCormack wrote:
> But isn't that still pretty much the rule here - that we have to use only
> what MS provides? Which, nowadays does include both VBS and (shudder)
> Powershell...

Those and many other tools now exist in Windows - up to and including
creating executable files, with native Windows tools that are in many
default installations.

> Note that I've never used either of these,

The irony is that you ask a question in a group where batch enthusiasts can
create a working TARDIS from 12 lines of batch code - and you exclude the
tools that will help you solve your problem.

> since, like all MS products, they both seem like too little, too late.

In reality you merely lack the knowledge to use them.


B00ze/Empire

unread,
Apr 22, 2015, 7:13:15 PM4/22/15
to
On 2015-04-21 11:26, npocmaka <npoc...@gmail.com> wrote:

[snip]

Lol, I think the OP wont like using mshta either, but nice solution, I
didn't know mshta until now...

Cool Gravatar.

Regards,

--
! _\|/_ Sylvain / B00...@hotmail.com
! (o o) Member-+-David-Suzuki-Fdn/EFF/Red+Cross/Planetary-Society-+-
oO-( )-Oo The HELL with the Prime Directive ... FIRE!

Mike Sanders

unread,
Apr 27, 2015, 8:44:14 AM4/27/15
to
Kenny McCormack <gaz...@shell.xmission.com> wrote:

> But isn't that still pretty much the rule here - that we have to use only
> what MS provides? Which, nowadays does include both VBS and (shudder)
> Powershell...

Kenny, hoping to catch your ear here a moment...

Stop & reconsider your strategy... your thinking is correct with respect
to VBS. But you ought to do yourself a favor & study jscript (a dialect
of javascript 100% native to Windows). You *can* (I do all the time)
merge/interface/combine command-line apps & scripts to great effect.
Which is a big help when deploying more technical apps to less technically
inclined folks...

Jscript has the c-like syntax I know you're familiar with...

function addthem(x, y) {

return x + y;

}

var z += addthem(2, 2); // comment here

Plus, you can leverage DOM (Document Object Model)...

document.onclick=addthem(2, 2);

Now imagine (say) an awk script wrapped in such a GUI...

Study these sources if so compelled (unzip before use):

http://freebsd.hypermart.net/code/topic-win.zip

--
Mike Sanders
www: http://freebsd.hypermart.net
gpg: 0xD94D4C13

lacla...@gmail.com

unread,
Feb 3, 2017, 8:37:01 AM2/3/17
to
> Bartender says, "Hi, Mitt!"mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

JJ

unread,
Feb 4, 2017, 8:58:12 AM2/4/17
to
CMD is strictly text based.
Use Take Command Console if you want GUI prompt.
0 new messages