Results 1 to 2 of 2

Thread: Attempting to copy output to clipboard with VBS

  1. #1
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Attempting to copy output to clipboard with VBS

    My script thus far:

    Code:
    Name=Inputbox("Enter the PC or Laptop you wish to run UPTIME against:")
    Set objShell = CreateObject("WScript.Shell")
    objShell.Run "%COMSPEC%  /k C:\UPTIME.EXE " & Name & " > c:\uptime.txt"
    WScript.Quit
    This works. I get a text file with the uptime info in it.


    What I would like to do is copy the output in the text file to the clipboard and make it easy to paste into tickets at our help desk.

    When I create a variable to hold this in the line:

    Code:
    uptime = (objShell.Run ("%COMSPEC% /k C:\UPTIME.EXE " & Name))
    and then try to output either by MSGBOX or by WSCRIPT.ECHO all I get is a box with a 0 in it.

    I was figuring if I could get the output into a variable then I could copy that to the Clipboard and thereby allow it to be pasted in other applications.

    I am having no luck so far. Can anyone help me?

    Thanks!

  2. #2
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    I got the output in a variable now, just need to know how to get it to copy to the clipboard.

    Here's the script:

    Code:
    'Get Laptop or PC Name or IP Address
    Name=Inputbox("Enter the PC or Laptop you wish to run UPTIME against:")
    
    'Run the Command
    Set objShell = CreateObject("WScript.Shell")
    objShell.Run "%COMSPEC% /c C:\UPTIME.EXE " & Name & " > c:\uptime.txt"
    Set objShell = Nothing
    
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    sFile = "C:\uptime.txt"
    If oFSO.FileExists(sFile) Then
    Set oFile = oFSO.OpenTextFile(sFile, 1)
     Do While Not oFile.AtEndOfStream
      sText = oFile.ReadLine
       If Trim(sText) <> "" Then
        WScript.Echo sText
       End If
     Loop
    oFile.Close
    Else
    WScript.Echo "The file was not there."
    End If
    So all I need is to get sText into the Clipboard.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •