Search code examples
vbscriptpastebin

Get a variable output to clipboard


The idea is that of constructing a URL through a user input, and then getting this output to the pastebin.

So the script runs, asks for a user input which then goes to complete the URL, which in turn gets in the pastebin. At least, that's the idea.

This is the code I've came up with so far:

Set WshShell = WScript.CreateObject("WScript.Shell")

dim strLink, defInc, remedy
defInc = "INC"
strLink=InputBox("Enter Incident ID",,defInc)

remedy = "https://1st_part_web_url"& strLink &"%22"

WshShell.Run "cmd.exe /c echo " & remedy & " | clip", 0, TRUE

This way I get no output whatsoever to the pastebin. Why not?


Solution

  • Option Explicit
    
    Dim URL
    
        URL = "https://somewhere/somePage?var1=something&var2=somethingMore&id=123456789"
    
        With WScript.CreateObject("WScript.Shell") 
            .Environment("Process").Item("URL")=URL
            .Run "cmd /c ""(cmd /v:on /c echo(!URL!)|clip"" ", 0, true
        End With
    

    To avoid escaping the possible problematic characters in urls, this code uses a environment variable to pass the information to cmd that will pipe the information into clip.exe