mshta command for copy into clipboard

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
einstein1969
Expert
Posts: 774
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

mshta command for copy into clipboard

#1 Post by einstein1969 » 02 Mar 2020 06:45

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>"

jfl
Posts: 122
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: mshta command for copy into clipboard

#2 Post by jfl » 02 Mar 2020 07:39

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 ;-)

siberia-man
Posts: 152
Joined: 26 Dec 2013 09:28
Contact:

Re: mshta command for copy into clipboard

#3 Post by siberia-man » 02 Mar 2020 07:53

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.

hacxx
Posts: 28
Joined: 09 Apr 2015 13:18

Re: mshta command for copy into clipboard

#4 Post by hacxx » 02 Mar 2020 12:40

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.

einstein1969
Expert
Posts: 774
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: mshta command for copy into clipboard

#5 Post by einstein1969 » 04 Mar 2020 15:02

@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>"

aGerman
Expert
Posts: 3840
Joined: 22 Jan 2010 18:01
Location: Germany

Re: mshta command for copy into clipboard

#6 Post by aGerman » 04 Mar 2020 17:52

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

siberia-man
Posts: 152
Joined: 26 Dec 2013 09:28
Contact:

Re: mshta command for copy into clipboard

#7 Post by siberia-man » 05 Mar 2020 02:38

Functionality of clipboardData and its method setData is strongly restricted by MSIE. Indeed, try using clip.

einstein1969
Expert
Posts: 774
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: mshta command for copy into clipboard

#8 Post by einstein1969 » 05 Mar 2020 04:12

@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?

siberia-man
Posts: 152
Joined: 26 Dec 2013 09:28
Contact:

Re: mshta command for copy into clipboard

#9 Post by siberia-man » 05 Mar 2020 07:30

I am not sure that anyone can help you with no knowing about your SW environment.

aGerman
Expert
Posts: 3840
Joined: 22 Jan 2010 18:01
Location: Germany

Re: mshta command for copy into clipboard

#10 Post by aGerman » 05 Mar 2020 11:17

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

Sponge Belly
Posts: 197
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: mshta command for copy into clipboard

#11 Post by Sponge Belly » 08 Mar 2020 09:26

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!

Post Reply