Using WSH (VBS) with iMacros - how do they do it? - firefox

(iMacros For Firefox 6.6.5.0; Firefox 3.6.3; Windows XP Pro SP3 w/all updates)
I made an iMacro to select "load next 25" (comments) on a web page (CNN.COM). Unfortunately, iMacros doesn't appear to do looping (do the above until that string doesn't appear on the page anymore - i.e. all the comments are loaded). I tried putting {!iloop} in the TAG command, and it didn't work - then I read it wouldn't.
So I tried the example at http://wiki.imacros.net/Loop_after_Query_or_Login
I can't find any information on how to actually run the script in the above example. I searched Google and found VBS scripting is handled with .wsh files with Windows XP Pro. (The examples and other references there say Windows does VBS natively, so I looked up how with Google.)
So I made the following .wsh file (modified the above example):
Option Explicit
Dim iim1, iret
'initialize iMacros instance
set iim1 = CreateObject ("imacros")
iret = iim1.iimInit()
do while not iret < 0
iret = iim1.iimPlay("Load All CNN Comments")
loop
' tell user we're done
msgbox "End."
' exit iMacros instance and quit script
iret = iim1.iimExit()
Wscript.Quit()
Here's the iMacro: (Load All CNN Comments.iim)
VERSION BUILD=6650406 RECORDER=FX
TAG POS=1 TYPE=A ATTR=TXT:Load<SP>next<SP>25
WAIT SECONDS=#DOWNLOADCOMPLETE#
The iMacro works by itself - I press Play (left iMacro panel) and the next 25 comments load on the CNN.com page in the current tab.
I put the .wsh file in the ...\iMacros\Macros directory - with the iMacro "Load All CNN Comments.iim"
When I run the .wsh file (by just double clicking on it's icon - I created it with Notepad, and Windows gave it an icon for that file type - it's executable) I get the message from "Windows Script Host" - "There is no script file specified." I wasn't actually expecting it to work, as I don't see how Windows would know to call iMacros to run the iim macro.
It would be nice if there was a simple, COMPLETE, example of how to use a VBS script with iMacros, that isn't bogged down with unnecessary complication like filling in a form, loading multiple pages, etc. I can't find ANY example.
So what do I need to do to get this to work? I just installed iMacros yesterday, because I am constantly having the problem that there are hundred of comments after a CNN.com article, and loading 25 more at a time until they are all on the page makes it impractical to read any replies to my comments.
It would also be nice if I could run the Macro from Firefox, rather than by double clicking on some file somewhere.
Thanks for any help.

Try changing the extension of your script from .WSH to .VBS.

Related

What can I do in order to fix my VBScript error?

So I decided to start learning VBScript coding language, but I had some issues with running it. Here is what I have done:
I made a code, specifically this code:
Picture of the source code in/of HTML and VBScript
I installed IE (internet explorer) since I saw that VBScript is only supported by IE.
The code I did wrote, I wrote it on notepad, saved the file, and gave the file extension: .vbs (file name was "test").
I right-clicked test.vbs, clicked Properties, changed "Open With" to Microsoft (R) Windows Based Script Host.
I ran the file.
This Error occurred: Picture of the Error window
So may I ask, what wrong did I do? or what is wrong? like did I personally do a mistake, or is it something like if Windows 10 does not support VBScript, or if VBScript is not supported anymore? I as well saw a thread of Microsoft saying that VBScript support will be stopped for Windows 7, 8; though I dont know the exact mistake I have done.
Thanks for the answers.
P.S. I as well tried the file in the extension .htm, but It did not work though I ran it on both firefox and IE.
I guess you misunderstood the "runs only in IE" part of VBScript. Yes, IE is the only browser that runs inline-VBScript in HTML files. But no, you don't need IE (or HTML, for that matter) to execute a simple VBScript (*.vbs) file.
You received that error, because the Windows Scripting Host doesn't "understand" HTML. Hence, it complains at line 1, column 1 about something it can't identify as VBScript.
Here's Microsoft's VBScript Primer.
For you classic Hello World! VBScript, simply paste this one line into a file...
MsgBox "...from the Scripting host with love!",, "Hello World..."
... and make sure (as you already did) that the file's extension is *.vbs. Then simply double-click to execute it.
VBScript in HTML is only supported by the Trident (MSHTML) browser engine used by Internet Explorer 10 and below and Microsoft HTML Applications (MSHTAs or HTAs). Your script failed to run as .VBS because it's not a VBScript file. It failed to run in IE because IE 11 and above only supports JavaScript.
In order to run your script, change the extension to .HTA. It will then work in Windows 7, 8, 10 and 11, and additionally allow for full access to the local computer's resources (files, registry keys, etc.).
If you really want to create a web page (to run from the Internet), use JavaScript instead of VBScript and save it as .HTM.

Can an already running program's window be hidden?

I have been using wsh to run vbscripts in conjunction with iMacros at my work for going on 3 years now. I know that the iMacros browser itself has an option to run hidden but the web-based db interface I have to work with does not function in the iMacros browser. For this reason I have had to use Internet Explorer. I have no problems with the script itself or how it runs. The thing I would like to improve is how the Internet Explorer window itself is handled.
Currently, when iMacros is initiated it creates the IE window in a non-maximized state cascaded from where the previous window was created. Because of iMacros's behavior, I then resize the window using an iMacros script so that enough of the page is rendered for the script to see everything it needs.
Set iim1 = CreateObject ("imacros")
iret = iim1.iimOpen ("-ie -iePrivate", TRUE, 300)
iret = iim1.iimPlayCode("SIZE X=" & scrWidth & " Y=" & scrHeight)
This all works fine and dandy. The scripts are scheduled to run at specific times, gather information out of the db and then imports that data into Excel spreadsheets and prints them out.
What I would like to do is make the IE window hidden while these scripts run. Because I do not create the IE window first (Set objIE = CreateObject("internetexplorer.Application")) I do not have access to the IE window object. I let iMacros create the window with the -iePrivate flag so that it will not disturb my own IE window if I should be logged in and working in the db while the script executes. However, it does try to take focus and become the active application while the script executes. Which can be very annoying at time. My goal is to be able to share these scripts with my co-workers but I don't want the IE windows popping up on them while they may be working on something else.
Is there a way to get to the IE object created by iMacros so that the window can be hidden?
This does Internet Explorer and Explorer windows (they used to be the same program).
Set objShell = CreateObject("Shell.Application")
Set AllWindows = objShell.Windows
For Each window in AllWindows
msgbox window.locationname
Next

Invoke 'Open' Dialog from Windows Desktop

Is there some way I can programmatically (in VBS) OR by using CMD/RUN open the 'Open' dialog that contains the places bar and a browser but without opening say notepad or MSpaint?
http://i.technet.microsoft.com/dynimg/IC354177.jpg
I'd like to use this on the desktop itself, it would be really cool if there was a DLL I can just use instead of having a VBS file but if not i'm sure its possible in VBS.
I'm busy searching where the actual open dialog box comes from, it should come from some DLL file somewhere.
I might even consider stopping the windows shell from opening all together and just using this open window as the shell on some computers.
Regards, Rocklore
What version of Windows are you on?
"UserAccounts.CommonDialog" was the way to do this in XP. But it no longer exists in Windows 7. You may be able to use some of the flags available for the BrowseForFolder() method to make it look like a file open dialog. See this page for an example.
XP Edit:
Here's an XP example using UserAccounts.CommonDialog.
With CreateObject("UserAccounts.CommonDialog")
.InitialDir = CreateObject("WScript.Shell").SpecialFolders("Desktop")
.Filter = "All Files|*.*"
' Show the dialog. If [Open] is clicked, save the name of the selected file...
If .ShowOpen Then strFile = .FileName
End With

Operate a Desktop program with sofware

I would like to operate a (Windows) Desktop program. Because i use this on a daily basis to do some simple operaition. (Open a file PDF file, render it and save it in another folder).
I would like to do this by using somekind of service or script. I have been looking into VBscript to do this but i'm getting stuck at some operations that are normally done by users.
For example if i would like to open a file a user would go to File > Open and select the desired file. Off course the script could go to file and open but how do you select a certain file (the newest file in a certain folder).
Is it possible to have a piece of code to do these operations within a Desktop program or am i trying to do something impossible or maybe i'm using the wrong tools. Below a piece off testcode for what i'm trying to accomplish.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files (x86)\programname.exe"""
wsh.sleep 1000 ' wait 1 second
WshShell.AppActivate """Program name"""
WshShell.SendKeys "^o" ' Open file
Any help is greatly appreaciated.
You are trying to control an application through its GUI, but it is not designed for that.
Having said that, I estimate this will be a nightmare if you do not use tools (or an app :-) ) explicitely created for that purpose, a la test robots like HP QTP or automation tools like Autoit http://www.autoitscript.com/site/autoit.
For example, if your application occasionally flushes the keyboard buffer, you might need to wait for some GUI event before sending the keystroke. This kind of synchronization is not accomplishable using vbscript only.

Switching Internet Explorer Windows with VBA

I have been working on an Excel macro to automate an Internet Explorer process at work. I'm incredibly close to figuring everything out, but at the end, the macro clicks on a "Download Report" button, which launches a new window. I need to initiate a few things on this new window but I cannot figure out how to change the focus of the macro to the new window. I have found a few things online, but they have been unsuccessful. I know there are ways to toggle between browser windows by telling Excel to look for the name of the browser window, and to activate it, but parts of the name of the new window are constantly changing (it's a unique URL for that particular window).
I was wondering if there might be a way to have the Macro look for just the first Nine letters of the window and switch to that window? Similar to the LEFT function in excel? The reason being is that the first 9 characters of the URL never change. The name of the original window (the one I'm trying to switch from) never changes, so maybe I could tell Excel to look for the the Browser Window that is NOT named the original one? Or any other ideas?
Thanks in advance for any help
Is the VBA AppActivate command what you are looking for?
You will need to add the references to the Internet Controls and shell. You just need to loop through the IE windows and look at the left hand side of the url. See below
Function GetInternetWindow(urlToLookFor as String) As InternetExplorer
Dim winShell As Shell
Dim ie As InternetExplorer
Set winShell = New Shell
'loop through the windows and look at the urls
For Each ie In winShell.Windows
If Left(ie.LocationURL, 9) = urlToLookFor Then
GetInternetWindow = ie
Exit For
End If
Next
End Function

Resources