Page 1 of 1

mshta command for copy into clipboard

Posted: 02 Mar 2020 06:45
by einstein1969
Hi,

I have this command that show a group of button for launch varius script

Code: Select all

mshta.exe "about:<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES"><title>Avvio Bots</title><HTA:APPLICATION ID="" CONTEXTMENU="no" BORDER="none" BORDERSTYLE="complex" SHOWINTASKBAR="no" SCROLL="no"/><body style="padding:20px;background:rgb(5,15,40)" onload="window.resizeTo(400,250)"><input type="Button" value="But1" name="prova1" id="p1"><br><input type="Button" value="But2" name="prova2" id="p2"><br><br><button onclick="window.close()">Chiudi</button></body>"
I need to copy into clipboard the number or name of button clicked

I have probed with "ClipBoardData.setData" but not working.

Code: Select all

mshta.exe "about:<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES"><title>Avvio Bots</title><HTA:APPLICATION ID="" CONTEXTMENU="no" BORDER="none" BORDERSTYLE="complex" SHOWINTASKBAR="no" SCROLL="no"/><body style="padding:20px;background:rgb(5,15,40)" onload="window.resizeTo(400,250)"><input type="Button" value="But1" name="prova1" id="p1" onclick="ClipBoardData.setData("text","1")"><br><input type="Button" value="But2" name="prova2" id="p2"><br><br><button onclick="window.close()">Chiudi</button></body>"

Re: mshta command for copy into clipboard

Posted: 02 Mar 2020 07:39
by jfl
I was not aware it was possible to do one-line HTML applications like this. Nice!

If you don't find a native HTA way, maybe it'd be possible to return the user choice number as the HTML Application exit code, then send that to the clipboard using an outside tool?
There's an example on how to return an exit code there: https://stackoverflow.com/questions/208 ... batch-file
You'd need a 2-line batch like this:

Code: Select all

start /wait mshta.exe "about:...
echo %ERRORLEVEL% | 2clip
There are several 2clip.exe versions available on the Internet, including mine in SysTools.zip, which I obviously recommend ;-)

Re: mshta command for copy into clipboard

Posted: 02 Mar 2020 07:53
by siberia-man
For long time (I don't know exactly since when) Windows is already shipped with the "clip" tool:

Code: Select all

C:\>clip /?

CLIP

Description:
    Redirects output of command line tools to the Windows clipboard.
    This text output can then be pasted into other programs.

Parameter List:
    /?                  Displays this help message.

Examples:
    DIR | CLIP          Places a copy of the current directory
                        listing into the Windows clipboard.

    CLIP < README.TXT   Places a copy of the text from readme.txt
                        on to the Windows clipboard.

Re: mshta command for copy into clipboard

Posted: 02 Mar 2020 12:40
by hacxx
einstein1969 wrote:
02 Mar 2020 06:45
Hi,

I have this command that show a group of button for launch various scripts

Code: Select all

mshta.exe "about:<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES"><title>Avvio Bots</title><HTA:APPLICATION ID="" CONTEXTMENU="no" BORDER="none" BORDERSTYLE="complex" SHOWINTASKBAR="no" SCROLL="no"/><body style="padding:20px;background:rgb(5,15,40)" onload="window.resizeTo(400,250)"><input type="Button" value="But1" name="prova1" id="p1"><br><input type="Button" value="But2" name="prova2" id="p2"><br><br><button onclick="window.close()">Chiudi</button></body>"
The reason why it doesn't work is because the code is too long.

Re: mshta command for copy into clipboard

Posted: 04 Mar 2020 15:02
by einstein1969
@jfl & @siberia_man
I use this code in a tool that execute one line command and i don't want execute a cmd windows if possible because i need execute hidden and i don't want use file.
Is too complicate for me assembly the code. Can you help me?

@hacxx
this is an example and is very long and work

Code: Select all

mshta.exe "about:<!DOCTYPE HTML><META HTTP-EQUIV=MSThemeCompatible CONTENT=YES><title>This is an too long example</title><HTA:APPLICATION CONTEXTMENU=no BORDER=dialog SHOWINTASKBAR=no SCROLL=no MINIMIZEBUTTON=no MAXIMIZEBUTTON=no /><Script type='text/vbscript'>Sub Window_OnLoad : I=now : End Sub : Sub uno : I=now : end sub : Sub due : I=5 : end sub</SCRIPT><Script type='javascript'>i=4</script><body bgcolor=#600000 style='padding:5px;' onload='window.resizeTo 225,225'><select name=s size=4 style=background:blue;color:yellow;border:8px><option value=1>too long example 1</option><option value=2 selected>too long example 2</option><option value=3>too long example 3</option><option value=4>too long example 4</option></select><br><input type=checkbox name=Checkbox1>to long example</input><hr><button language=Javascript style=border:8px;width:115px; onclick=window.close()>to long button</button><span id=T></span><p><font color=green><b><PRE ID=myClock></PRE></b></font></p></body>"

Re: mshta command for copy into clipboard

Posted: 04 Mar 2020 17:52
by aGerman
Try to write the onclick property like that:

Code: Select all

onclick="clipboardData.setData('text','1')"
Note that JScript is case-sensitive. Thus, something like ClipBoardData doesn't exist. However, that's still only a guess and certainly doesn't meet the standard way where you should have used an event handler instead.

Steffen

Re: mshta command for copy into clipboard

Posted: 05 Mar 2020 02:38
by siberia-man
Functionality of clipboardData and its method setData is strongly restricted by MSIE. Indeed, try using clip.

Re: mshta command for copy into clipboard

Posted: 05 Mar 2020 04:12
by einstein1969
@aGerman
thank, this work!!!!!!!! The problem is the case sensitive and the manage of doube quote and single quote. I don't understand how I should use this.

You said I didn't use event management well, what do you mean? Can you give me an example?

@Siberia_man
Thanks . I will use the "clip" command if I am forced to.

Code: Select all

mshta … | clip
but this not work on the software that I use. Can you help me?

Re: mshta command for copy into clipboard

Posted: 05 Mar 2020 07:30
by siberia-man
I am not sure that anyone can help you with no knowing about your SW environment.

Re: mshta command for copy into clipboard

Posted: 05 Mar 2020 11:17
by aGerman
You said I didn't use event management well, what do you mean? Can you give me an example?
Have a look at this:
https://stackoverflow.com/questions/362 ... copy-event
But I can't tell what you have to do to make it work in a command line. Probably too much of code anyway. So, if it works without the event handler then stick with the simple solution.
Functionality of clipboardData and its method setData is strongly restricted by MSIE.
I agree. But we are talking about MSHTA which shares the rendering engine with IE, and also the scripting engine. So that's not much of a problem. Although I wonder how long IE and HTA will be still supported in future. The IE is a living dead, superseded by Edge already.

Steffen

Re: mshta command for copy into clipboard

Posted: 08 Mar 2020 09:26
by Sponge Belly
Hello All!

Slightly OT, perhaps, but here goes…

Placing content on the clipboard is severely restricted for security reasons. But there are workarounds. This SO Answer by Srikanth P provides a JScript solution that makes expert use of the Internet Explorer object.

HTH! :)

- SB

PS: Just spotted a typo on line 6 of the code in the SO Answer. The end of the line should read:

Code: Select all

WScript.Sleep(20);
And I meant to say the solution only works with text. Not for use with binary!