last day (19 days later) » 

11:50 AM
0
A: GUI for running batch files

npocmakaTry like this: <!-- :: Batch section @echo off setlocal echo Select an option: for /F "delims=" %%a in ('mshta.exe "%~F0"') do set "HTAreply=%%a" echo End of HTA window, reply: "%HTAreply%" goto :EOF --> <HTML> <HEAD> <HTA:APPLICATION SCROLL="no" SYSMENU="no" > <body bgcolor="cyan"> <TITLE>HT...

 
Tak
Thank you very much. This solved the first problem. Any advice regarding having an input textbox to pass parameters to a batch file? and also is there a way to anchor the GUI to the cmd so that it can be dragged and floating around?
 
@Tak - for arguments - check my edit.As for the your second question - I'm not sure what you are asking exactly. You want system menu for ye hta window?
 
Tak
Thank you. And how I can pass the argument to the called batch file. I did this <button onclick='callShellApplication("C:\\test.bat args")'>Bat1</button> and in test.bat I did this I wrote this in the beginning SET "arg1=%1" and used arg1. But then when I run the batch file, enter the argument and click the button1 to run test.bat, the batch file close and nothing happens. Any advice what I'm doing wrong?
 
@Tak - is your set inside brackets? What have you wrote in the input textfield? I've tested this with a single line batch file : @echo ##%1## and it worked fine.
 
Tak
It was inside brackets then I removed it now but still not working. In the textfield I wrote a string something like user1 . Am I correctly passing args here correctly <button onclick='callShellApplication("C:\\test.bat args")'>Bat1</button> ?
 
11:50 AM
@Tak - try the bat directly with your arguments to see what happens.It could be an issue with the bat itself.
 
Tak
The batch file was already working
The only change I did in the test.bat was changing SET "username=user1" to SET username=%1
 
12:27 PM
if execution take a longer time you can consider adding a wait:
see the jscript example
 
Tak
@npocmaka so when status=0 this means the exec is running?
 
it could be also the exit code.Unfortunately it is not well documented by microsoft
you'll have to test it by yourself :)
aa
yes
when status is 0 the command is still running
it is
 
Tak
I've tested and I found out that when I remove the below 2 lines it works properly:
new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(res.StdOut.ReadLine());
window.close();
but it doesn't exit the opened GUI and cmd
@npocmaka I've modified the function to look like this but there is something wrong pasteall.org/916336
 
just a moment...
 
Tak
@npocmaka take your time
 
12:46 PM
WScript.Shell has no sleep function.
YOu should write one by yourself
eg.
function callShellApplication(command){
var args=document.getElementById('args').value;
var r = new ActiveXObject("WScript.Shell");
var res=r.Exec(command +" "+args);
var out="";
while (res.Status == 0)
{
sleepFor(100);
}
while (!res.StdOut.AtEndOfStream){
out=out+"\r\n"+res.StdOut.ReadLine();
}

var StS=new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1);
StS.Write(out);
//new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(res.StdOut.ReadLine());
window.close();
and the sleep
function sleepFor( sleepDuration ){
var now = new Date().getTime();
while(new Date().getTime() < now + sleepDuration){ /* do nothing */ }
}
I'll update the answer
check the update
 
Tak
@npocmaka thank you very much
last thing which is not very important. Is there a possibility that the gui is kind of anchored to the cmd?
like now when you run the batch file the gui will open along with the cmd, if you move the cmd the gui will not move along with it
@npocmaka not sure if this is possible or not?
 
1:03 PM
There's no easy way to do this
it is possible ...but could take me a month or more to do it
 
Tak
haha, okay, not worth it then
thank you again
 

  last day (19 days later) »