How to Find the Windows default browser using autoit - autoit

i had tried following code and but iam getting null
$myDefaultBrowser = RegRead("HKEY_CURRENT_USER\Software\Clients\StartMenuInternet", "(Default)")

Here is another one:
#include <APIRegConstants.au3>
#include <WinAPIReg.au3>
ConsoleWrite(_getDefaultBrowser() & #crlf)
Func _getDefaultBrowser()
Return _WinAPI_AssocQueryString(".html", $ASSOCSTR_EXECUTABLE)
EndFunc ;==>_getDefaultBrowser

you can find the default browser by replacing "(Default)" with ""
$myDefaultBrowser = RegRead("HKEY_CURRENT_USER\Software\Clients\StartMenuInternet", "")

Related

Conditional include of file

I'd like to include certain script only if it's present. Unfortunately #include is processed before the execution, so I can't make it conditional like this:
If FileExists(#ScriptDir & "\common.au3") Then
#include "common.au3"
EndIf
I tried to use Execute to evaluate the read file in place via Execute(ReadFile(...)). But that seems to only process single statements - I couldn't declare multiple functions for example.
Is there a different way to conditionally include another file?
Probably not a good design choice but if you really need to do somethin like this, try #OnAutoItStartRegister:
#OnAutoItStartRegister "_OnAutoItStart_CreateIncludes"
#include "include_collection.au3"
If IsDeclared("iExample_Common") Then
MsgBox(64, "", "Common.au3 exists")
Else
MsgBox(16, "", "Common.au3 wasnt included")
EndIf
MsgBox(0, "", "Your Script here")
Func _OnAutoItStart_CreateIncludes()
If StringInStr($CmdLineRaw, '-_OnAutoItStart_CreateIncludes', 1) Then Return
If FileExists(#ScriptDir & "\common.au3") And Not StringInStr(FileRead("include_collection.au3"), '#include "common.au3"') Then
FileWrite("include_collection.au3", '#include "common.au3"')
EndIf
$iPID = Run('"' & #AutoItExe & '" ' & $CmdLineRaw & ' -_OnAutoItStart_CreateIncludes', #WorkingDir, Default, 2)
While ProcessExists($iPID)
ConsoleWrite(StdoutRead($iPID))
Sleep(10)
WEnd
Exit
EndFunc ;==>_OnAutoItStart_CreateIncludes
Create an additional empty file "include_collection.au3" as well.
In this example, I created "commons.au3" containing a statement "$iExample_commons = 1234'.
Note: Once the file is included this way, it should not be deleted otherwise your script will fail again. This could probably be overcome too but at some point it will become very messy.
Maybe it's a better Idea to wrap a launcher around your application which will add/remove include lines before startup as needed.

Autoit - searching for a URL in a web page and click on it

I'm trying to figure out how can I click a URL that matches a specific pattern.
For example:
#include <IE.au3>
#include <MsgBoxConstants.au3>
local $pattern = "/123/"
Local $oIE = _IECreate("www.example.com",0,1,1,1)
Local $oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
If StringInStr($oLink, $pattern) Then
_IEAction($oLink, "click")
sleep(700)
_IEQuit($oIE)
ExitLoop
EndIf
Next
Basically what I need to achieve is,
if a $oLink in $oLinks contains $pattern - click on it.
The above program, for some reason, does not work.
Any suggestions?
Thank you
I'm not sure if you can use StringInStr on the object.
Try using:
StringInStr($oLink.href, $pattern)
instead.
Do you get your links with this piece of code?
#include <Array.au3>
#include <Inet.au3>
local $pattern = "/123/"
$source = _INetGetSource('https://www.nytimes.com/')
$links = StringRegExp($source, 'href="(http.*?)"', 3)
_ArrayDisplay($links)
Then you just need to adapt your For Next loop and use StringInStr on every links[$i]

autoit IE click on a button in a website

I am trying to open a link by clicking on button inside a website.
This is the element :-
<div class="btn3">Like</div>
I tried this
$oBtn.classname = _IEGetObjById($oIE, "Like")
_IEAction($oBtn, "click")
not working. any help. Please.
You are doing it all wrong.
Try reading the help file.
This will work
Local $oInputs = _IETagNameGetCollection($oIE, "div")
For $oInput In $oInputs
If $oInput.classname == "btn3" Then _IEAction($oInput, "click")
Next
You can use $oBtn.classname only if you create an internet application object or an xml object with autoit. OR if you use _IETagNameGetCollection()
Here is an example:
#include <IE.au3>
Local $oIE = _IE_Example("form")
Local $oInputs = _IETagNameGetCollection($oIE, "input")
Local $oBtn
For $oInput In $oInputs
if $oInput.class = "btn3" Then
$oInput.Click
ExitLoop
Next
_IEQuit($oIE)
Of course you will need a little modification to the code since we know nothing about the website you are trying to automate

AutoIt: Illegal text at end of statement

I'm unable to figure out what it wrong with this
Func Hypotenuse($a, $b)
Return sqrt($a * $a + $b * $b)
EndFunc
Error is
Func Hypotenuse($a, $b)
Func Hypotenuse($a, $b)^ERROR
Error: Illegal text at end of statement (one statement per line).
EDIT: It appears to have been a hidden character
Well, nothings wrong there :O
This:
Func Hypotenuse($a, $b)
Return sqrt($a * $a + $b * $b)
EndFunc
ConsoleWrite(Hypotenuse(2,2))
Works perfect for me? And for you? Whats the rest of the Code?
You copied code from AutoIt forum or some other Invision Power Board driven forum.
If that is correct, you copy the end-of-line HTML-character if you don't pop out the code box. Easiest fix for many lines is to CTRL + A, copy & paste into Notepad, then copy that and paste back into SciTE.
This sort of thing can happen when you call your function from the incorrect If..Then statement. For example, the code
If Hypotenuse(1,1) > 0 Then ConsoleWrite("test" & #CRLF) EndIf
gives you an "Illegal text at end of statement" error, whereas the code
If Hypotenuse(1,1) > 0 Then ConsoleWrite("test" & #CRLF)
or
If Hypotenuse(1,1) > 0 Then
ConsoleWrite("test" & #CRLF)
EndIf
works just fine.
I had the same issue when I had an extra ) at the end of the call.
Real code issue:
LogProgram("(SM) Selected Image SM: " & $imageList[$smPicName]))
Correct:
LogProgram("(SM) Selected Image SM: " & $imageList[$smPicName])

ASP conditional error

i am trying to use an ASP conditional here:
if (Request.Cookies("username")) and
(Request.Cookies("password")) <> ""
Then
And i keep getting this error:
Type mismatch: '[string: ""]'
Any ideas what I am getting that?
try
if (Request.Cookies("username") <> "") and (Request.Cookies("password") <> "") Then
Actually, I would do the following..
if (!string.IsNullOrEmpty(Request.Cookies("username")) &&
!string.IsNullOrEmpty(Request.Cookies("password")))
{
// Do your stuff, here :)
}
Get into the habit of using string.IsNullOrEmpty for testing variables and string.Empty for setting values, if u don't want a string to be null.

Resources