Autoit proxy IE object - browser

I'd like to use a proxy to mask my ip surfing the net an autoit browser!
This is my code:
#NoTrayIcon
#include <GUIConstants.au3>
#Include <IE.au3>
#include <GUIConstantsEx.au3>
GUICreate("Web Browser By EMPĀ£!!",800,600)
GUISetBkColor(0x808080)
GUISetState(#SW_SHOW)
$Edit=GUICtrlCreateInput("http://www.whatismyip.com/",20,20,500,20)
$Vai=GUICtrlCreateButton("SURF!!!",600,10,150,50)
$oIE = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($oIE, 10, 90,780, 500)
$ret = HttpSetProxy(2,"61.163.78.51:3128")
If $ret == 0 Then
MsgBox(0, "Proxy", "Proxy Error")
Exit
EndIf
While 1
$msg=GUIGetMsg()
Switch $msg
Case $Vai
$Link=GUICtrlRead($Edit)
_IENavigate($oIE,($Link))
GUICtrlSetData($Edit,$Link)
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
I navigate on http://www.whatismyip.com/ and i can see my real ip address! I'd like to hide a proxy!

The HttpSetProxy function is only for use with InetGet, it makes no difference to the internet explorer settings. In order to make a proxy for internet explorer windows you need to change the internet explorer settings.
The way I would do it is something like:
#include <GUIConstants.au3>
#include <IE.au3>
#include <GUIConstantsEx.au3>
Global Const $sInetSettingsKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
GUICreate("Web Browser By EMPĀ£!!", 800, 600)
GUISetBkColor(0x808080)
GUISetState(#SW_SHOW)
$Edit = GUICtrlCreateInput("http://www.whatismyip.com/", 20, 20, 500, 20)
$Vai = GUICtrlCreateButton("SURF!!!", 600, 10, 150, 50)
$oIE = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($oIE, 10, 90, 780, 500)
MySetProxy("61.163.78.51:3128")
While 1
$msg = GUIGetMsg()
Switch $msg
Case $Vai
$Link = GUICtrlRead($Edit)
_IENavigate($oIE, ($Link))
GUICtrlSetData($Edit, $Link)
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
MySetProxy()
Func MySetProxy($sProxy = "", $fEnable = True)
Local Static $sPrev = ""
Local Static $fWasEnabled = False
If $sProxy = "" Then
If $sPrev <> "" Then __setProxyInfo($fWasEnabled, $sPrev)
Else
If $sPrev = "" Then
$sPrev = RegRead($sInetSettingsKey, "ProxyServer")
$fWasEnabled = RegRead($sInetSettingsKey, "ProxyEnable")
EndIf
__setProxyInfo($fEnable, $sProxy)
EndIf
EndFunc
Func __setProxyInfo($fEnabled, $sProxy)
RegWrite($sInetSettingsKey, "ProxyEnable", "REG_DWORD", 1)
RegWrite($sInetSettingsKey, "ProxyServer", "REG_SZ", $sProxy)
EndFunc
whatismyip.com didn't like it much though. But the IP address definitely changed.

Related

How to resize display resolution on windows with nim

I'd like to use nim to resize the default display resolution on a machine (windows 10 only), I want to basically do it via a command line call like setDisplay 1280 1024
I've seen and used the python example Resize display resolution using python with cross platform support which I can follow, but just can't translate. I just don't get how to fill in EnumDisplaySettings
import winim/lean
import strformat
var
cxScreen = GetSystemMetrics(SM_CXSCREEN)
cyScreen = GetSystemMetrics(SM_CYSCREEN)
msg = fmt"The screen is {cxScreen} pixels wide by {cyScreen} pixels high."
EnumDisplaySettings(Null,0, 0) #total type mismatch
MessageBox(0, msg, "Winim Example Screen Size", 0)
Tried checking stuff like https://cpp.hotexamples.com/fr/examples/-/-/EnumDisplaySettings/cpp-enumdisplaysettings-function-examples.html but wasn't much help, same for https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-changedisplaysettingsa
I wrote about 2% of this answer myself, and the rest came from pointystick on discord - thanks to them!
The solution is a bit lazy, but it's so fast that for most that won't matter.
With no cmd line args it will just set the display to the default recommendation, else with 2 cmd line args it can reset your display if it finds a match
import winim/lean
import os
import strutils
var modeToFind = (width: 1920, height: 1080, bitsPerPixel: 32,
refreshRate: 60)
var reset = 0
type ModeNotFoundError = object of CatchableError
proc getDisplayMode(): DEVMODEW =
## Finds the wanted screen resolution or raises a ModeNotFoundError.
var
nextMode: DWORD = 0
mode: DEVMODEW
while EnumDisplaySettings(nil, nextMode, mode) != 0:
echo $mode.dmPelsWidth & " x " & $mode.dmPelsHeight &
" x " & $mode.dmBitsPerPel &
" - " & $mode.dmDisplayFrequency
inc nextMode
if (mode.dmPelsWidth == modeToFind.width) and
(mode.dmPelsHeight == modeToFind.height):
echo "Found it!"
return mode
if(reset==1):
return mode
raise newException(ModeNotFoundError, "Cannot find wanted screen mode")
proc changeResolution(): bool =
## Actually changes the resolution. The return value indicates if it worked.
result = false
try:
let wantedMode = getDisplayMode()
result = ChangeDisplaySettings(wantedMode.unsafeAddr, 0.DWORD) == DISP_CHANGE_SUCCESSFUL
except ModeNotFoundError: discard
when isMainModule:
var
cxScreen:int32 = 0 #= GetSystemMetrics(SM_CXSCREEN)
cyScreen:int32 = 0 # = GetSystemMetrics(SM_CYSCREEN)
try:
cxScreen = (int32) parseInt(paramStr(1))
cyScreen = (int32) parseInt(paramStr(2))
modeToFind.width = cxScreen
modeToFind.height = cyScreen
except:
reset = 1
if not changeResolution():
echo "Change Resolution Failed"

Script to read from Excel and interact with website and write down the result again to Excel

I am trying to automate some repetitive work for getting results from a website,
this link Drugs.com, checks for interaction between two medicines.
I must take the text of the two medicines from the Excel sheet and enter them on the website to check the interaction between them.
Here is a sample of my Excel sheet:
column(A) Column(B)
(A1)candesartan benazepril
(A2)eprosartan captopril
(A3)irbesartan enalapril
When I press 'Check For Interaction' the result of the next page must be extracted and return one of tree interactions:
-major
-moderate
-minor
This must then write the result to column(c)
I am a beginner at autoit but I can do some scripting albeit with a lot of bugs.
I will appreciate it if someone can correct/assist me with the bugs in my code. I will also appreciate it if someone can help me with the correct keywords so that I can Google for examples and solutions.
Thanks all.
#include <Excel.au3>
#include <IE.au3>
#include <File.au3>
Local $sWorkbook = "C:\Users\Aligaaly\Desktop\autoit\test\drugs.xlsx"
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)
$oWorkbook = _Excel_BookAttach($sWorkbook)
GLOBAL $oIE = _IECreate("https://www.drugs.com/drug_interactions.php")
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
$text_form1 = _IEGetObjById($oIE, "livesearch-interaction")
If StringLower($oInput.classname) == "input-button search-button" and _IEFormElementGetValue($oInput) Then ; it is an input
Global $oInput_btn = $oInput
EndIf
Next
WinActivate("[CLASS:XLMAIN]", "")
For $i = 1 To 5
Global $sResulta = _Excel_RangeRead($oWorkbook, Default, 'A' & $i & ':A' & $i,1 )
For $y = 1 To 5
Global $sResultb = _Excel_RangeRead($oWorkbook, Default, 'B' & $y & ':B' & $y,1 )
WinActivate("[CLASS:IEFrame]", "")
_IEFormElementSetValue($text_form1, $sResulta )
_IEAction ($oInput_btn, "click")
sleep(5000)
_IEFormElementSetValue($text_form1, $sResultb )
_IEAction ($oInput_btn, "click")
sleep(5000)
For $oInput In $oInputs
If StringLower($oInput.value) == "check for interactions" Then
Global $check_btn = $oInput
EndIf
Next
_IEAction ($check_btn, "click")
sleep(5000)
$oButtonsa = _IETagnameGetCollection($oIE, "span")
For $oButtonn in $oButtonsa
If $oButtonn.classname == "status-category status-category-major" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "major","C" & $y)
ElseIf $oButtonn.classname == "status-category status-category-moderate" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "moderate","C" & $y)
ElseIf $oButtonn.classname == "status-category status-category-minor" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "minor","C" & $y)
EndIf
ExitLoop
Next
Next
Next
i have updated the code with my final touches
i think this code is now complete the steps i have write down above
but i have an error when the script finish the first iteration
The problem is in _IEFormElementSetValue function.
Probably,
$text_form1 = _IEGetObjById($oIE, "livesearch-interaction")
can't find any object.
For debug it you can insert this code before _IEFormElementSetValue:
ConsoleWrite("isObject:" & isObj($text_form1) & #CRLF)
Update: I found 3 problems.
1) You didn't return to search page after end of iteration and the input object can't be found;
2) You must get Input and Button object on the start of each iteration;
3) Exitloop must be on each If ... esleif section.
Try this code:
#include <Excel.au3>
#include <IE.au3>
#include <File.au3>
Local $sWorkbook = "C:\Users\Aligaaly\Desktop\autoit\test\drugs.xlsx"
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)
$oWorkbook = _Excel_BookAttach($sWorkbook)
GLOBAL $oIE = _IECreate("https://www.drugs.com/drug_interactions.php")
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
$text_form1 = _IEGetObjById($oIE, "livesearch-interaction")
If StringLower($oInput.classname) == "input-button search-button" and _IEFormElementGetValue($oInput) Then ; it is an input
Global $oInput_btn = $oInput
EndIf
Next
WinActivate("[CLASS:XLMAIN]", "")
For $i = 1 To 5
Global $sResulta = _Excel_RangeRead($oWorkbook, Default, 'A' & $i & ':A' & $i,1 )
For $y = 1 To 5
Global $sResultb = _Excel_RangeRead($oWorkbook, Default, 'B' & $y & ':B' & $y,1 )
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
$text_form1 = _IEGetObjById($oIE, "livesearch-interaction")
If StringLower($oInput.classname) == "input-button search-button" and _IEFormElementGetValue($oInput) Then ; it is an input
$oInput_btn = $oInput
EndIf
Next
WinActivate("[CLASS:IEFrame]", "")
_IEFormElementSetValue($text_form1, $sResulta )
_IEAction ($oInput_btn, "click")
sleep(5000)
_IEFormElementSetValue($text_form1, $sResultb )
_IEAction ($oInput_btn, "click")
sleep(5000)
For $oInput In $oInputs
If StringLower($oInput.value) == "check for interactions" Then
Global $check_btn = $oInput
EndIf
Next
_IEAction ($check_btn, "click")
sleep(5000)
$oButtonsa = _IETagnameGetCollection($oIE, "span")
For $oButtonn in $oButtonsa
If $oButtonn.classname == "status-category status-category-major" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "major","C" & $y)
ExitLoop
ElseIf $oButtonn.classname == "status-category status-category-moderate" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "moderate","C" & $y)
ExitLoop
ElseIf $oButtonn.classname == "status-category status-category-minor" Then
WinActivate("[CLASS:XLMAIN]", "")
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "minor","C" & $y)
ExitLoop
EndIf
Next
_IENavigate($oIE, "https://www.drugs.com/drug_interactions.php?action=new_list")
Next
Next

autoIT copy most recent filepath to clipboard

Hello I am writing a script that will open the windows 10 camera, then display the most recent image when I close the camera then with a GUI, ask the user if the image is okay. If they select yes then the script would copy the filepath to the clibpoard and then be able to past this filepath into a Microsoft Excel cell. I have everyhting working how I want it to until the point where I need the filepath to be copied to the clipboard. Here is my code so far.
#include <MsgBoxConstants.au3>
Camera()
Func Camera()
; Execute Camera and wait for Camera to close
Local $iPID = ShellExecuteWait("explorer.exe", "shell:AppsFolder\Microsoft.WindowsCamera_8wekyb3d8bbwe!App")
Sleep(3000)
WinWaitClose("Camera")
EndFunc
#include-once
#include <Array.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <Process.au3>
$dst = "C:\Users\Cex\Pictures\Camera Roll" ; specify folder
$a_FileList = _FileListToArray2()
_ArraySort($a_FileList, 1, 1, $a_FileList[0][0], 1)
ShellExecute($a_FileList[1][0])
Func _FileListToArray2($s_Mask='*')
$h_Search = FileFindFirstFile($dst & '\' & $s_Mask)
$s_FileName = FileFindNextFile($h_Search)
If Not #error Then
Dim $a_File[100][2]
While Not #error
If StringInStr($s_FileName,'.',0,-1) Then
$s_FullName = $dst & '\' & $s_FileName
$a_File[0][0] += 1
If $a_File[0][0] >= UBound($a_File) Then
ReDim $a_File[$a_File[0][0] * 2][2]
EndIf
$a_File[$a_File[0][0]][0] = FileGetLongName($s_FullName)
$a_File[$a_File[0][0]][1] = FileGetTime($s_FullName,0,1)
EndIf
$s_FileName = FileFindNextFile($h_Search)
WEnd
ReDim $a_File[$a_File[0][0] + 1][2]
Return $a_File
EndIf
Return ''
EndFunc
#include <GUIConstantsEx.au3>
#include <IE.au3>
WinWaitActive("Photos", "")
Local $qGUI = GUICreate("Example", 200, 125, 1000, 200)
GUICtrlCreateLabel("Are you happy with this image?", 30, 30)
Local $bYes = GUICtrlCreateButton("Yes", 6, 60, 85, 25)
GUICtrlSetOnEvent($bYes, "xYes")
Local $bNo = GUICtrlCreateButton("Yes", 107, 60, 85, 25)
GUICtrlSetOnEvent($bNo, "xNo")
Local $bClose = GUICtrlCreateButton("Close", 57, 90, 85, 25)
GUISetState(#SW_SHOW, $qGUI)
While 1
Switch GUIGetMsg()
Case $bYes
bYes()
GUIDelete($qGUI)
Exit
Case $bNo
bNo()
GUIDelete($qGUI)
Exit
Case $bClose, $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Func bYes()
_RunAU3("YesTest.au3")
EndFunc
Func bNo()
_RunAU3("NoTest.au3")
EndFunc
Func _RunAU3($sFilePath, $sWorkingDir = "", $iShowFlag = #SW_SHOW, $iOptFlag = 0)
Return Run('"' & #AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"', $sWorkingDir, $iShowFlag, $iOptFlag)
EndFunc
Like I said I am looking to copy the filepath of the most recent photograph and then copy it to the clipboard which will then be pasted into a cell in excel. I have limited coding knowledge so there are probably many bad points to my code but I have just been learning as I go along so if anyone can help me please do not confuse me however, if you have to, then all help is appreciated!
AutoIT has build in functions for the clipboard, such as ClipPut and ClipGet.
ClipPut($filepath)
which would be in your case
ClipPut($a_FileList[1][0])

Random text view

I'm having a problem because when I touch my button sometimes my text doesn't appear...
function randomText(event)
display.remove(mmDis)
local a = { "Cristiano ronaldo jest najlepszy!",
"messi jest dobry!","lewandowski jest ok", "diego lopez to bramkarz realu"
}
com = (a[math.random(1, #a)])
local mmDis = display.newText(tostring(com),
display.contentWidth*0.57, display.contentHeight*0.7,
display.contentWidth*0.9, display.contentHeight*0.8, "Impact", 30)
mmDis.y=20
mmDis.x=190
mmDis:setFillColor(0, 0, 0, 1)
mmDis.anchorY = 0
end
play:addEventListener ("tap", randomText )

how to play web url audio files corona sdk?

I am trying to play audio file from web link but it seems not working now. These are the codes I tried:
local birdSound = audio.loadSound("www.sound.com/birds.mp3")
audio.play(birdSound)
It gives an error
You can't load in memory a remote audio file with the loadSound API because this function is just intended to load local files.
By default the file is searched for in the project folder (system.ResourceDirectory), but changing the baseDir parameter you can also look inside a different local folder.
So to play your remote audio file you should first dowload it in the system.DocumentsDirectory through the network.download API. When it is done you can load it with the loadSound, specifying the correct baseDir.
For details about the network.download API look here
Use the sniper below to download your remote file and then save it to localFilename at base dir basedir:
local xmnetwork = {
last_error = nil,
downloadHandlerInProgress = nil,
downloadHandlerFinished = nil,
downloadBeginHandler = nil,
network = require("network")
}
function xmnetwork.download(url, errorHandler,beganHandler, inProgressHandler, endedHandler, localFilename, basedir)
if( xmnetwork.network == nil) then
xmnetwork.network = require("network")
end
xmnetwork.downloadHandlerInProgress = inProgressHandler
xmnetwork.downloadHandlerFinished = endedHandler
xmnetwork.downloadBeginHandler = beganHandler
xmnetwork.errorHandler = errorHandler
local function downloadListener( event )
print("download event:" .. tostring(event))
if ( event.isError ) then
print( "Network error!" )
if( xmnetwork.errorHandler) then
xmnetwork.errorHandler(event)
end
elseif ( event.phase == "began" ) then
if ( event.bytesEstimated <= 0 ) then
print( "Download starting, size unknown" )
else
print( "Download starting, estimated size (in MB): " .. ( event.bytesEstimated /1024/1024))
end
if( xmnetwork.downloadBeginHandler) then
xmnetwork.downloadBeginHandler(event)
end
elseif ( event.phase == "progress" ) then
if(xmnetwork.downloadHandlerInProgress ) then
xmnetwork.downloadHandlerInProgress (event)
end
if ( event.bytesEstimated <= 0 ) then
print( "Download progress: " .. event.bytesTransferred )
else
print( "Download progress: " .. (event.bytesTransferred / event.bytesEstimated) * 100 .. "'%'")
-- log("xmnetwork.download", "downloading :" .. (event.bytesTransferred / event.bytesEstimated) * 100 .. "'%'")
end
elseif ( event.phase == "ended" ) then
print( "Download complete, total bytes transferred: " .. event.bytesTransferred )
if(xmnetwork.downloadHandlerFinished) then
xmnetwork.downloadHandlerFinished(event)
end
end
end
local params = {}
-- Tell network.request() that we want the "began" and "progress" events:
params.progress = "download"
-- Tell network.request() that we want the output to go to a file:
params.response = {
filename = localFilename,
baseDirectory = basedir
}
xmnetwork.network.request( url, "GET", downloadListener, params )
end

Resources