Use clipboard from VBScript

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

    No security warnings and no carriage return at the end of line

    ' value to put in Clipboard
    mavaleur = "YEAH"
    
    ' current Dir
    path = WScript.ScriptFullName
    GetPath = Left(path, InStrRev(path, "\"))
    
    ' Put the value in a file
    Set objFSO=CreateObject("Scripting.FileSystemObject")
    outFile=GetPath & "fichier.valeur"
    Set objFile = objFSO.CreateTextFile(outFile,True)
    objFile.Write mavaleur
    objFile.Close
    
    ' Put the file in the Clipboard
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run "cmd.exe /c clip < " & outFile, 0, TRUE
    
    ' Erase the file
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.DeleteFile outFile
    

提交回复
热议问题