Use clipboard from VBScript

后端 未结 15 1462
青春惊慌失措
青春惊慌失措 2020-11-29 06:36

I am looking for a method to place some text onto the clipboard with VBScript. The VBScript in question will be deployed as part of our login script. I would like to avoid

15条回答
  •  心在旅途
    2020-11-29 07:20

    Using Microsoft's clip.exe is the closest to having a clean Windows XP system solution. However you don't have to call CMD.EXE to host it in order to use it. You can call it directly and write to its input stream in your script code. Once you close the input stream clip.exe will write the contents straight to the clipboard.

    Set WshShell = CreateObject("WScript.Shell")
    Set oExec = WshShell.Exec("clip")
    Set oIn = oExec.stdIn
    oIn.WriteLine "Something One"
    oIn.WriteLine "Something Two"
    oIn.WriteLine "Something Three"
    oIn.Close
    

    If you need to wait for clip to be finished before your script can continue processing then add

    ' loop until we're finished working.
    Do While oExec.Status = 0
        WScript.Sleep 100
    Loop
    

    And don't forget to release your objects

    Set oIn = Nothing
    Set oExec = Nothing
    

提交回复
热议问题