programatically save image in clipboard to a jpg file.

This VBScript code takes screenshot and keeps in clipboard

    Set oWordBasic = CreateObject("Word.Basic")
    oWordBasic.SendKeys "{prtsc}"
    oWordBasic.AppClose "Microsoft Word"
    Set oWordBasic = Nothing

I'm looking for a way to save this clipboard image into a jpeg file programmatically. Please help

Thanks
Amit
Amit SinghAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerCommented:
The most compatible way would be this:

set WSH_OBJ = CreateObject("WScript.Shell")
Set OBJ_WB = CreateObject("Word.Basic")

 OBJ_WB.SendKeys "{prtsc}"
 OBJ_WB.AppClose "Microsoft Word"
 Set OBJ_WB = Nothing
 
WSH_OBJ.Run "mspaint",3
WScript.Sleep 500

WSH_OBJ.AppActivate "untitled - Paint"
 WScript.Sleep 500

WSH_OBJ.SendKeys "^v"
WScript.Sleep 200

WSH_OBJ.SendKeys "^s"
WScript.Sleep 200
WSH_OBJ.SendKeys "c:\temp1\test" & replace(replace(replace(now(),"/","-")," ",""),":","") & ".jpg"
WScript.Sleep 200
WSH_OBJ.SendKeys "{ENTER}"
WScript.Sleep 200
WSH_OBJ.SendKeys "%f"
WScript.Sleep 200
WSH_OBJ.SendKeys "x"
Set WSH_OBJ=Nothing
WScript.Quit

Open in new window


It's a fixed path, but variable file name (based on date and time), so that the overwrite window NEVER occurs.
Amit SinghAuthor Commented:
Thank you Kimputer for helping me to solve my problem, however I'm looking for something little different. I want the process to run in the background and does not require user input or action. It should take screenshot and save as a jpeg file and everything should happen in the background.

It is not necessary to have it in VBScript it can be in any language I'm just looking for a solution

Thanks
Amit
Bill PrewIT / Software Engineering ConsultantCommented:
When would this script run, and what should be the location and filename for the jpg.

~bp
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Bill PrewIT / Software Engineering ConsultantCommented:
Can I ask what problem you are actually trying to solve.  There are great tools like WinSnap that can capture the screen and save to a file all with a single keystroke.

~bp
Amit SinghAuthor Commented:
Hello Bill,

The script would run all the time in the background and would take screenshot every 10 min automatically. It would save screenshot on computers hard disk locally.

The purpose of this is: I work as a freelancer and would like to provide snapshot of my screen to the client so that they know how their paid time is being utilized. something very similar to Elance tracker.

Thanks for your help!
KimputerCommented:
This VB code is enough (and you can compile it with the FREE Visual Studio products from MS: https://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx).

Imports System.IO

Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Hide()
        Dim snappit As String = 0
        Try
            Dim screenshot As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
            Dim screengrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
            Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screengrab)
            g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenshot)

            screengrab.Save(Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "snap" & Now.ToString("yyMMdd-hhmmss") & ".jpg"))
        Catch ex As Exception

        End Try
        Environment.Exit(0)

    End Sub
End Class

Open in new window


It is one program that only saves one time (currently in My Documents, with the year/month/day - hour/minute/seconds format, the reason being for easy sorting of course. What you do next, is to just schedule a task for every 10 minutes. Forget about it and your My Documents will be filled with screenshots every 10 minutes throughout the day (or however you set up the scheduled task)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewIT / Software Engineering ConsultantCommented:
If it were me (and it's not) I'd probably find an existing utility that can do this.  I use WinSnap for screen captures myself, and while it can save to disk automatically it doesn't have an interval timer option to make captures automatically as you need.  So I did a little googling and there seem to be some existing utilities that can do this, some free, some for modest cost (which I figured you might be okay with because you want to use it for business reasons).  In case you are interested, here are a few I found:

https://www.techsmith.com/snagit.html
http://www.timesnapper.com/
http://www.theuds.com/autoscreenshot.php?lang=EN
http://sourceforge.net/projects/autoscreencap/
http://www.wisdom-soft.com/products/screenhunter_pro.htm
http://www.sobolsoft.com/autoscreenshot/
http://www.irfanview.com/

And I also found a powershell approach although I haven't tried it.

https://github.com/mattifestation/PowerSploit/blob/master/Exfiltration/Get-TimedScreenshot.ps1

bp
Amit SinghAuthor Commented:
Thanks a lot this works very well!

One last thing, I want to save it to a particular folder because the snapshot gets mixed up with my other files can you please add that feature to the code?

Thank you very much for your help!
Amit SinghAuthor Commented:
Very helpful Experts!
KimputerCommented:
Imports System.IO

Class Form1
    Dim targetfolder = "C:\snaps\snappppppp"


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Hide()
        Try
            If Not (Directory.Exists(targetfolder)) Then
                Directory.CreateDirectory(targetfolder)
            End If
        Catch ex As Exception

        End Try
        
        Dim snappit As String = 0
        Try
            Dim screenshot As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
            Dim screengrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
            Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screengrab)
            g.CopyFromScreen(New Point(0, 0), New Point(0, 0), screenshot)

            screengrab.Save(Path.Combine(targetfolder, "snap" & Now.ToString("yyMMdd-hhmmss") & ".jpg"))
        Catch ex As Exception

        End Try
        Environment.Exit(0)

    End Sub
End Class

Open in new window

Amit SinghAuthor Commented:
Thanks a lot Kimputer!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.