Log in

View Full Version : Attempting to copy output to clipboard with VBS



JRF2k
09-15-2008, 04:18 PM
My script thus far:


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:


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!

JRF2k
09-15-2008, 05:09 PM
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:


'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.