A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Windows scripting

  1. #1
    Allan Jardine
    Join Date
    Dec 2000
    Location
    Turtle hunting
    Posts
    192

    Windows scripting

    Hello all,

    Could anyone point me in the direction of how one can write a script for Windows (XP) which would launch a web-browser, take a screenshot and then save the screenshot in a file? Is it even possible, I presume so?

    Thanks
    Allan

  2. #2
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    I don't think that this is possible unless you want to make your own program.
    Jason L. Wright
    I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.

  3. #3
    OK, here's what I've got.

    First download IrfanView if you don't have it already (i suggest the zipped version instead of the installer).

    Then create a new text document and paste the following inside.

    Code:
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set Argv = WScript.Arguments
    
    ' path to irfanview
    IView = "i_view32"
    
    ' path to browser
    Browser = "iexplore.exe -e"
    ' Browser = "firefox.exe -new-window"
    
    ' 0: Hides the window and activates another window.
    ' 1: Activates and displays a window. If the window is minimized 
    '    or maximized, the system restores it to its original size and 
    '    position. An application should specify this flag when displaying 
    '    the window for the first time.
    ' 2: Activates the window and displays it as a minimized window.
    ' 3: Activates the window and displays it as a maximized window.
    ' 4: Displays a window in its most recent size and position. 
    '    The active window remains active.
    ' 5: Activates the window and displays it in its current size and position.
    ' 6: Minimizes the specified window and activates the next 
    '    top-level window in the Z order.
    ' 7: Displays the window as a minimized window. The active window remains active.
    ' 8: Displays the window in its current state. The active window remains active.
    ' 9: Activates and displays the window. If the window is minimized or 
    '    maximized, the system restores it to its original size and 
    '    position. An application should specify this flag when restoring a minimized window.
    ' 10:Sets the show-state based on the state of the program that 
    '    started the application.
    
    Return = WshShell.Run(browser & " " & Argv(0), 3)
    
    ' wait for the page to load
    WScript.Sleep 3000
    
    WshShell.AppActivate "Internet Explorer"
    
    ' take a screenshot
    ' JPEG quality
    Quality = "100"
    
    ' filename to save cpature as
    Filename = "capture $U(%d-%m-%Y %H-%M-%D).jpg"
    Command = IView & " /capture=0 /jpgq=" & Quality & " /convert=""" & Filename & """"
    Return = WshShell.Run(Command, 7, true)
    
    
    ' close the browser
    WshShell.SendKeys "%{f4}"
    
    Set WshShell = Nothing
    WScript.Quit(0)
    Save the file as capture.vbs

    Change the browser, sleep time, irfanview path, jpeg quality and save file variables as necessary. Then open up a command prompt and go to the directory that you saved the script to. Run the script with the web page as the command line argument.

    Code:
    capture.vbs http://www.flashkit.com
    It will open the browser, load the page, save a screen shot and close the active window (hopefully the browser). It all takes about 4 seconds to complete.

  4. #4
    Allan Jardine
    Join Date
    Dec 2000
    Location
    Turtle hunting
    Posts
    192
    Thanks yasunobu13!

    That script is fantastic - exactly the kind of thing I was looking for. One little thing I stumbled across was quote makes for the path to the web browser. I has to use triple quotes, so that the command which was passed on the to cli from Run was quoted... Can you tell it my first shot at windows shell stuff

    A

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center