Use clipboard from VBScript

后端 未结 15 1466
青春惊慌失措
青春惊慌失措 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:19

    To avoid the security warnings associated with Internet Explorer and clipboard access, I would recommend you use the Word application object and its methods to put your data onto the clipboard. Of course you can only use this on a machine that has MS Word installed, but these days that's most of them. (*In spite of the fact that you asked for stuff on a 'clean' system :) *)

    ' Set what you want to put in the clipboard '
    strMessage = "Imagine that, it works!"
    
    ' Declare an object for the word application '
    Set objWord = CreateObject("Word.Application")
    
    ' Using the object '
    With objWord
       .Visible = False         ' Don't show word '
       .Documents.Add           ' Create a document '
       .Selection.TypeText strMessage   ' Put text into it '
       .Selection.WholeStory        ' Select everything in the doc '
       .Selection.Copy          ' Copy contents to clipboard '
       .Quit False          ' Close Word, don't save ' 
    End With
    

    You can find detail on the MS Word application object and its methods here: http://msdn.microsoft.com/en-us/library/aa221371(office.11).aspx

提交回复
热议问题