VBScript to detect Facebook IE window, press Like and close the window - facebook

I tryed to make a script to detect the IE window that is opened on Facebook and hit the Like button.
Let's say I have 10 IE opened. Only one of them is on a page on Facebook.
I want my script to detect that IE window, click this button:
IE.Document.getElementById("pagesHeaderLikeButton")
(The above button is the Like button)
and close that IE window.
I tryed to get that IE window by:
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
Set IE = wnd
Exit For
End If
Next
But this will only set my VBscript to the first opened IE and it will not find the Facebook window.
I tryed this:
Dim objInstances, item
Set objInstances = CreateObject("Shell.Application").windows
For Each item In objInstances
If Item.Name Like "*Internet*" And Item.document.URL Like "*facebook.com*" Then
IE.Document.getElementById("pagesHeaderLikeButton").Click
End If
Next
But I get "Sub or function not defined"

Next code snippet could help:
Set shApp = CreateObject( "shell.application")
With shApp
For Each wnd In .Windows
If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
If InStr(1, wnd.document.URL, "facebook.com", vbTextCompare) > 0 Then
Wscript.Echo "THIS:"
End If
Wscript.Echo Left( wnd.document.URL, 70)
End If
Next
End With
Output example (with more facebook.com matches):
==>cscript D:\VB_scripts\SO\30717779a.vbs
http://www.msn.com/?ocid=iehp
THIS:
https://www.facebook.com/login.php?api_key=127760087237610&skip_api_lo
THIS:
https://www.facebook.com/literarnifestival1
THIS:
https://cs-cz.facebook.com/mgvsetin
http://www.bing.com/search?q=Xmaster+Official&qs=n&form=QBRE&pq=xmaste
http://www.bing.com/search?q=%22Xmaster+Official%22&qs=n&form=QBRE&pq=
==>

The following code will search for open IE windows that have "facebook.com" in its URL and save them in a collection:
Dim getIE As New Collection
For Each Item In CreateObject("Shell.Application").Windows
If Item.Name Like "*Internet*" And Item.document.URL Like "*facebook.com*" Then
getIE.Add Item
End If
Next
Then you can loop through the collection and do what you want with the IE items:
For Each itemIE In getIE
itemIE.Document.getElementById("pagesHeaderLikeButton").Click ' For example
Next itemIE
Hope this does what you wanted! ;)

For Each wnd In CreateObject("Shell.Application").Windows
If InStr(wnd.Name,"Internet") Then
if InStr(wnd.Document.URL,"facebook.com") Then
Set IE2 = wnd
Exit For
End If
End If
Next
So to press the button will be like this:
Set Butlike = IE2.Document.getElementsByTagName("button")
For Each btn In Butlike
If btn.type = "submit" Then btn.Click()
Next

Related

How can I disable ":w" from doing anything with the popup's buffer?

Here is a piece of code that creates the popup:
:function! PopupDemo()
let message = 'Hello World'
for i in range(10)
let message = message . ' ' . message
endfor
let s:win_buf = bufadd('popup-demo')
call bufload(s:win_buf)
call setbufline(s:win_buf, 1, message)
echo 'buf id: ' . s:win_buf
let width = 40
let height = 10
" Set the new window as the current window.
let enter = v:false
" Calculate the centering coordinates.
let win_x = &columns / 2 - width / 2
let win_y = &lines / 2 - height / 2
let s:win_id = nvim_open_win(s:win_buf, enter, {
\'relative': 'editor',
\'row': win_y,
\'col': win_x,
\'width': width,
\'height': height,
\'focusable': v:false,
\'style': 'minimal',
\'border': ['╔', '═','╗', '║', '╝', '═', '╚', '║'],
\'noautocmd': v:false,
\'bufpos': [0, 0]
\})
call nvim_win_set_option(s:win_id, 'wrap', v:true)
:endfunction
:function! PopupClose(timer)
if s:win_id != 0
call nvim_win_close(s:win_id, v:false)
endif
if s:win_buf != 0
call nvim_buf_delete(s:win_buf, {'force': v:true})
endif
:endfunction
After I create a buffer and a pop-up window through the PopupDemo() function, I do not call the PopupClose() function to close the window, but directly use the :wq command to save the file and exit neovim, the following error message will appear:
E37: No write since last change
E162: No write since last change for buffer "popup-demo"
I want file save instructions like ":w", ":wq" and ".wqall" to ignore the popup's buffer, how can I do this?
neovim version: v0.7.2
Normally buffers are related to files. Set 'buftype' option equal to nofile if not.
As it is Neovim-only code, you can replace bufadd('') with nvim_create_buf(v:false, v:true), so it sets the option while creating the buffer.

VBscript fails to pin items to taskbar on Windows Insider build

I have a script that will pin an item to the taskbar in all OS's except the Windows Insider builds. I converted it to a Powershell script and it also works on all OS's except the Windows Insider build. When I run it, I don't get any error messages, nothing in the Event Viewer. MS has been locking down the ability to programmatically pin items to both the Start Menu and the Taskbar. It looks like they're going further in upcoming releases. Has anyone else run into this? Here is the code I'm using.
Function PinItem(strFolder, strFile)
Dim ShortcutPath
Dim sKey1
Dim sKey2
Dim KeyValue
'----------------------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
ShortcutPath = strFolder & "\" & strFile
sKey1 = "HKCU\Software\Classes\*\shell\{:}\\"
sKey2 = Replace(sKey1, "\\", "\ExplorerCommandHandler")
'----------------------------------------------------------------------
With WScript.CreateObject("WScript.Shell")
KeyValue = .RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" & _
"\CommandStore\shell\Windows.taskbarpin\ExplorerCommandHandler")
.RegWrite sKey2, KeyValue, "REG_SZ"
With WScript.CreateObject("Shell.Application")
With .Namespace(objFSO.GetParentFolderName(ShortcutPath))
With .ParseName(objFSO.GetFileName(ShortcutPath))
.InvokeVerb("{:}")
End With
End With
End With
.Run("Reg.exe delete """ & Replace(sKey1, "\\", "") & """ /F"), 0, True
End With
End Function

Panel doesn't execute )PNTS Section

I'm coding a ISPF Panel with "Point and shoot" elements. The elements say "yes" and "no" and the default cursor have to point to "yes".
1st Case:
Declaration of the fields: + TYPE(INPUT) PAS(ON)
When I use this declaration, the panel closes by pressing [enter] and generating rc = 0. However, the )PNTS section doesn't run.
2nd CASE:
Declaration of the fields: + TYPE (PS)
The )PNTS section runs by pressing [enter]. However, I cannot set the .cursor to the field "yes".
I tryed different ways with different field names (e.g. ZPS00001). I tryed to simulate Point and Shoot with Rexx, but nothing worked really fine.
Pressing enter will cause the point and shoot fields to be processed. However the cursor must be on one of the fields for the )PNTS section to set the value associated with a field. It would sound like panel may have not been coded correctly. PAS should be used for input or output fields and PS should be used for text fields. For instance if you have the following panel:
)ATTR
$ TYPE(PS)
! TYPE(OUTPUT) PAS(ON)
)BODY
+ --------------------- +
+ ===>_ZCMD +
+
$Field1 : _FLD +
$Field2 : _ABC +
$Field3 : !IN1 +
$Field4 : !IN2 +
)INIT
&INV1 = 111
&INV2 = 222
&INV3 = 333
)REINIT
REFRESH(*)
)PROC
)PNTS
FIELD(IN1) VAR(INV1) VAL(ON)
FIELD(IN2) VAR(INV2) VAL(OFF)
FIELD(ZPS00001) VAR(INV3) VAL(1)
FIELD(ZPS00002) VAR(INV3) VAL(2)
FIELD(ZPS00003) VAR(INV3) VAL(3)
FIELD(ZPS00004) VAR(INV3) VAL(4)
)END
With the following REXX exec:
/* REXX */
RCC = 0
INV1 = 0
INV2 = 1
DO WHILE RCC = 0
ADDRESS ISPEXEC 'DISPLAY PANEL(PAS)'
RCC = RC
SAY INV1 '-' INV2 '-' INV3
END
You can test the values of inv1, inv2 and inv3 based on where you put the cursor when you hit enter. You will get 1, 2, 3 or 4 if the cursor in on field1, field2, field3 or field4. If it is on IN1 or IN2 then you get ON or OFF. It all depends on where the cursor is positioned when ENTER is hit. Based on the example you can see point and shoot is not limited to Menus. Hope the example helps.
Marv Knight

Dynamic expanding visual basic forms

I have what is most likely a simple question. I have a visual basic form but when I expand it none of the fields or text expands with the window. I was wondering how to make it so the form dynamically expands when someone maximizes or expands the window on the desktop Could someone please advise thank you!
Each control has the properties VerticleAnchor and HorizontalAnchor.
These can be left right or both (top or bottom for verticle) and if it is left and top (default) they stay those distances from the top and left sides. Changing them to right and bottom keep their distances from the right and bottom. Both resizes the control to have the same spacing from both as the form resizes.
Also double chack that the CanGrow and CanShrink are true to allow for them to resize with the form.
Hope that helps!
Edit:
Here is some code from my predecessor that does it using the event:
Private Sub Form_Resize()
On Error GoTo Err_Form_Resize
If CurrentProject.AllForms("frmFMEA_PartA").IsLoaded Then
Dim DatasheetW As Double
Dim DatasheetH As Double
Dim FormW As Double
Dim FormH As Double
DatasheetW = Me.frmFMEA_PartB_Subform.width
FormW = Me.WindowWidth
DatasheetH = Me.frmFMEA_PartB_Subform.Height
FormH = Me.WindowHeight
'MsgBox FormH
'MsgBox DatasheetH
Me.frmFMEA_PartB_Subform.width = IIf(FormW - 360 > 0, FormW - 360, 1) '390
Me.frmFMEA_PartB_Subform.Height = IIf(FormH - 3405 > 0, FormH - 3405, 1) '3195
Me.text.Left = IIf(FormW - 2340 > 0, FormW - 2340, 1)
Me.text_Logo.Left = IIf(FormW - 2340 > 0, FormW - 2340, 1)
End If
Exit_Form_Resize:
Exit Sub
Err_Form_Resize:
MsgBox Err.Description
Resume Exit_Form_Resize
End Sub
as you can see its a lot of math, trial, and error so I try to do it using the form level properties but maybe this will spart some ideas.

why is this vbscript not fetching any value?

i am trying to write a vbscript that extracts the value from src attribute of an <img> tag that has a class attribute as this cs-poster-big
here is the code i have tried so far,
'Initializing object with Internet Explorer Application
set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
'setting properties of Internet Explorer to the newly create object
with IE
.Visible = 0
.navigate "http://www.roku.com/channels/#!details/12" 'INSERT WEBPAGE HERE
end with
'waiting for IE to load the page
'tried using IE.busy or IE.readyState <> 4 also
while IE.busy
wScript.sleep 500
wend
wScript.sleep 500
'getting all image tags from the webpage
Set imgTags = IE.document.getElementsByTagName("IMG")
'iterating through the image tags to find the one with the class name specified
For Each imgTag In imgTags
'tried imgTag.className also
If imgTag.getAttribute("class") = "cs-poster-big" Then MsgBox "src is " & imgTag.src
next
IE.quit
set IE= Nothing
MsgBox "End of script"
and it is not displaying any value but you can view the source of the page here and you can see it has an <img> tag with class cs-poster-big
i don't understand why it is not displaying in my script
Do While IE.Busy Or IE.ReadyState <> 4
WScript.Sleep 500
Loop
Wait until page is completely loaded.
EDIT - While this works in IE10, IE8 fails to locate the image. Not tested in other versions.
In this case, try to change your url to
http://www.roku.com/channels?_escaped_fragment_=details/12/netflix#!details/12/netflix
to avoid problems with the dynamic generate content.
Also, in IE8, code needs to be changed to get class name of the image. It should be
Do While IE.Busy Or IE.ReadyState <> 4
WScript.Sleep 100
Loop
Set imgTags = IE.document.getElementsByTagName("IMG")
For Each imgTag In imgTags
imgClass = imgtag.getAttribute("class")
If IsNull( imgClass ) Then
imgClass = imgTag.className
End If
If imgclass = "cs-poster-big" Then
MsgBox "src is " & imgTag.src
End If
Next
But not a solution, just a workaround.