Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/16/2018 in all areas

  1. 1. Description. oAuth 2.0 is security system implemented by Google a few years ago. You are able to connect into your Google accounts and manage documents. In this UDF i show you how to pass first authorization process., this allow you to automate most of functions using API interface. 2. Requirements. Google account. oAuth.au3 Download 3. Possibilities ;============================================================================================================ ; Date: 2018-02-10, 14:21 ; ; Description: UDF for authorize your app with oAuth 2.0 Google. ; ; Function(s): ; oAuth2GetAuthorizationCode() -> Get Code for "grant". ; oAuth2GetAccessToken() -> Get "access_token" and "refresh_token" first time. ; oAuth2RefreshAccessToken() -> Get current "access_token" using "refresh_token". ; ; Author(s): Ascer ;============================================================================================================ 4. Enable your Google API. 4.1. Video Tutorial not mine! YouTube 4.2 Screenshots from authorization process (Polish language) Go to https://console.developers.google.com/apis/dashboard and accept current rules. Next create an new project Enter name of you new project and click Create Google will working now, please wait until finish. Next go to enable your API interface, we make if for Google Take "Gmail" in search input and after click in found result. Click Enable interface, Google will working now. Create your login credentials Select Windows Interface (combobox), User credentials (radio) and click button what is need bla bla Type name of a new client id for oAuth 2.0 and click Create a new Client ID. Next configure screen aplication, type some name and click Next. Google will working now. Last step on this website is download source with your credentials in *Json format. Now you received a file named client_id.json, it's how it look in Sublime Text: 5. Coding. Now we need to call a some function to get access code. #include <oAuth.au3> Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" Local $sRedirectUri = "http://localhost" oAuth2GetAuthorizationCode($sClientId, $sRedirectUri) Function will execute default browser for ask you to permission. Next Google ask you to permission for access to your personal details by application Autoit Now you can thing is something wrong but all is ok, you need to copy all after code= . It your access code. Let's now ask Google about our Access Token and Refresh Token #include <oAuth.au3> Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" Local $sClientSecret = "cWalvFr3WxiE6cjUkdmKEPo8" Local $sAuthorizationCode = "4/AAAPXJOZ-Tz0s6mrx7JbV6nthXSfcxaszFh_aH0azVqHkSHkfiwE8uamcabn4eMbEWg1eAuUw7AU0PQ0XeWUFRo#" Local $sRedirectUri = "http://localhost" Local $aRet = oAuth2GetAccessToken($sClientId, $sClientSecret, $sAuthorizationCode, $sRedirectUri) If Ubound($aRet) <> 4 then ConsoleWrite("+++ Something wrong with reading ResponseText." & @CRLF) Exit EndIf ConsoleWrite("Successfully received data from Google." & @CRLF) ConsoleWrite("access_token: " & $aRet[0] & @CRLF) ConsoleWrite("expires_in: " & $aRet[1] & @CRLF) ConsoleWrite("refresh_token: " & $aRet[2] & @CRLF) ConsoleWrite("token_type: " & $aRet[3] & @CRLF) Important! When you received error 400 and output says: Invalid grant it means that your previous generated access_code lost validity and you need to generate new calling previus code. When everything is fine you should received a 4 informations about your: access_token, expires_in, refresh_token and token_type. Access_Token time is a little short so you need to know fuction possible to refresh it (tell Google that he should generate a new Token for you) #include <oAuth.au3> Local $sRefreshToken = "1/ba8JpW7TjQH3-UI1BvPaXhSf-oTQ4BmZAbBfhcKgKfY" Local $sClientId = "167204758184-vpeues0uk6b0g4jrnv0ipq5fapoig2v8.apps.googleusercontent.com" Local $sClientSecret = "cWalvFr3WxiE6cjUkdmKEPo8" Local $sRedirectUri = "http://localhost" Local $aRet = oAuth2RefreshAccessToken($sRefreshToken, $sClientId, $sClientSecret) If Ubound($aRet) <> 3 then ConsoleWrite("+++ Something wrong with reading ResponseText." & @CRLF) Exit EndIf ConsoleWrite("Successfully received data from Google." & @CRLF) ConsoleWrite("access_token: " & $aRet[0] & @CRLF) ConsoleWrite("expires_in: " & $aRet[1] & @CRLF) ConsoleWrite("token_type: " & $aRet[2] & @CRLF) 6. Finish words If you followed all this above steps im sure that you received all informations required for coding your Google API (Gmail, Dropbox, YouTube, Calender etc. See next thread: [UDF] Gmail API - Email automation with AutoIt!
    2 points
  2. An array can have more than 65K rows.
    2 points
  3. Mbee I Didn't mean to seem unkind but I gave you exactly what you asked for in the first post you gave me some line about it not being what you wanted without actually looking at it. The Thing is that you asked me to comment code directly from the HELPFILE which you could have easily looked up rather than wanting me to do even more work for you. Only reason I did the second script was for closure A Note about Comments As far comments go generally the programmers rule is that if it is obvious what it does then don't comment.. Instead you should strive to write code that tells a story and then you only comment the deceptive things that don't work like they seem. There are a few reasons for this.. First is that too many comments makes it hard to follow code when you know what you are looking at Second is that people generally don't change the comments when they change the code so its even worse than no comment its now an INCORRECT comment This isn't so important in our little autoit scripts but it will become more so as you move up to larger codebases In the future don't throw a fit about not understanding the code, figure out what you can... Add YOUR comments as to what you think each thing does and then repost that asking for clarification. Instead of acting like you did in your first reply. Edit- In the future i'll try to be a little gentler on the un-initiated
    2 points
  4. 1. Description. Automate communication with Gmail API using oAuth 2.0 security. 2. Requirements. Google Gmail account. Finished Authorization process. Look here 3. Possibilities. ;======================================================================================================================== ; Date: 2018-02-12, 11:46 ; ; Bug Fixs: 2018-02-17, 7:31 -> Fixed problems with adding items to array and minor bugs. ; ; Description: UDF for using Gmail API interface. This UDF requires oAuth.au3 and Gmail account. ; ; Function(s): ; gmailUsersGetProfile() -> Information about your account. ; gmailUsersLabelsList() -> Get all available labels ids. ex. "INBOX", "UNREAD" ; gmailUsersLabelsGet() -> Get information about specific label id. ; gmailUsersMessagesBatchDelete() -> Delete many messages emails by id. ; gmailUsersMessagesBatchModify() -> Set status for many messages ex. "INBOX", "UNREAD" ; gmailUsersMessagesDelete() -> Totaly delete email from ur account. ; gmailUsersMessagesGet() -> Get all information about specific email. ; gmailUsersMessagesList() -> Get list of last ~100 emails. ; gmailUsersMessagesModify() -> Modify single message. ; gmailUsersMessagesTrash() -> Put email in trash. ; gmailUsersMessagesUntrash() -> Restore email from trash. ; gmailUsersMessagesSend() -> Send email to single or group recipients. ; gmailUsersMessagesAttachmentsGet() -> Download attachment by id. ; ; Author(s): Ascer ;======================================================================================================================== 4. Downloads. oAuth.au3 Gmail API.au3 5. Examples. Sending emails
    1 point
  5. Made this from a question in Help and Support #include <Array.au3> $aPreProcesses = ProcessList() $iNotepad = ShellExecute("notepad.exe") MsgBox(0, "Run or Exit Some Applications", "") _ArrayDisplay(_Processlist_Diff($aPreProcesses, ProcessList())) ;With Process Name & List Containing PID _ArrayDisplay(_Processlist_Diff($aPreProcesses, ProcessList(), True)) ;Returns Array of [PID] ;If bExtended = true ;Returns Array [Processname, PID, List# Containing PID] Func _Processlist_Diff(Const ByRef $aProcList0, Const ByRef $aProcList1, $bExtended = False) ; Check arrays Local $iRowsP1 = UBound($aProcList0, $UBOUND_ROWS) - 1 If $iRowsP1 <= 0 Then Return SetError(1, 0, 0) If UBound($aProcList0, $UBOUND_DIMENSIONS) <> 2 Then Return SetError(2, 0, 0) $iRowsP2 = UBound($aProcList1, $UBOUND_ROWS) - 1 If $iRowsP2 <= 0 Then Return SetError(3, 0, 0) If UBound($aProcList1, $UBOUND_DIMENSIONS) <> 2 Then Return SetError(4, 0, 0) ; Create error handler ObjEvent("AutoIt.Error", "__Processlist_Diff_AutoErrFunc") ; Create dictionary Local $oDictionary = ObjCreate("Scripting.Dictionary") ; Set case sensitivity $oDictionary.CompareMode = 0 ;Binary Compare ; Add elements to dictionary Local $vKey, $vElem, $bCOMError = False For $i = 0 To $iRowsP1 + $iRowsP2 - 1 If $iRowsP1 > 0 Then $vElem = "#PL0#" & $aProcList0[$iRowsP1][0] $vKey = $aProcList0[$iRowsP1][1] $iRowsP1 -= 1 Else $vElem = "#PL1#" & $aProcList1[$iRowsP2][0] $vKey = $aProcList1[$iRowsP2][1] $iRowsP2 -= 1 EndIf If $oDictionary.Exists($vKey) Then ;ConsoleWrite("DUPE PID " & $vElem & @CRLF) $oDictionary.Remove($vKey) Else ; Add Key $ Element $oDictionary.Item($vKey) = $vElem EndIf If @error Then $bCOMError = True ; Failed with an Int64, Ptr or Binary datatype ExitLoop EndIf Next ; Create return array Local $aValues, $j = 0 If $bCOMError Then ; Mismatch Int32/64 Return SetError(5, 0, 0) ElseIf $bExtended Then Local $aValues[$oDictionary.Count][3] For $vKey In $oDictionary.Keys() $vElem = $oDictionary.Item($vKey) $aValues[$j][0] = StringTrimLeft($vElem, 5) $aValues[$j][1] = $vKey ; Check which list contains PID If StringLeft($vElem, 5) = "#PL0#" Then $aValues[$j][2] = 0 Else $aValues[$j][2] = 1 EndIf $j += 1 Next Else ;Only PID ; Only need to list Keys $aValues = $oDictionary.Keys() EndIf $oDictionary.RemoveAll ;would be cleaned up anyway.. ; Return array Return $aValues EndFunc ;==>_Processlist_Diff Func __Processlist_Diff_AutoErrFunc() ; Do nothing special, just check @error after suspect functions. EndFunc ;==>__Processlist_Diff_AutoErrFunc The bExtended = True Returns Array [Processname. PID, List# Containing PID] for each PID that isn't in both lists If bExtended = False (Default) Return is just an array of [PID]
    1 point
  6. rcmaehl

    WMIC uninstall

    You can also use FileInstall to package the uninstall script with the script that runs it. (When Compiled)
    1 point
  7. DigDeep, You need to have just the one idle loop: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant. ; Make tray items global in scope as they are created inside a function Global $iDisplay, $iPrinter, $idAbout, $idExit $Form1 = GUICreate("Form1", 240, 254, 438, 144) $Label1 = GUICtrlCreateLabel("Test Lable 1", 56, 40, 127, 33, $SS_CENTER) $Label2 = GUICtrlCreateLabel("Test Lable 2", 56, 120, 127, 41, $SS_CENTER) $close = GUICtrlCreateButton("Close", 88, 208, 75, 25) GUISetState(@SW_SHOW) Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. SystemTrayMenu() ; System Tray Menu While 1 ; Check GUI events Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $close Exit EndSwitch ; Check tray events Switch TrayGetMsg() Case $idAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable. MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)) ; Find the folder of a full path. Case $iDisplay, $iPrinter MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.") Case $idExit ; Exit Exit EndSwitch WEnd Func SystemTrayMenu() ; System Tray Menu Local $iSettings = TrayCreateMenu("Settings") ; Create a tray menu sub menu with two sub items. $iDisplay = TrayCreateItem("Display", $iSettings) $iPrinter = TrayCreateItem("Printer", $iSettings) TrayCreateItem("") ; Create a separator line. $idAbout = TrayCreateItem("About") TrayCreateItem("") ; Create a separator line. $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. ; No loop here! EndFunc ;==>SystemTrayMenu M23
    1 point
  8. JLogan3o13

    WMIC uninstall

    Just to clarify, you want to be able to run it and pass credentials rather than seeing the UAC prompt, is that correct? If that is the case, I would compile the uninstall script, and then from a second script run the compiled one with the RunAs (look in the help file) function - passing the username and password.
    1 point
  9. As written, the ExitLoop forces the loop to stop after a single iteration, so the While loop would be unneeded as well.
    1 point
  10. Change this if WinExists(["CLASS:DirectUIHWND1"]) then to if WinExists("[CLASS:DirectUIHWND1]") then
    1 point
  11. This question makes no sense, please elaborate while we wait for the inevitable "Try this" reply
    1 point
  12. Why so complicated? How about this -- Local $oIE = _IECreate("https://www.lazada.com.my/products/sokano-mini-kitchen-fun-playset-with-full-utensils-set-pink-i100636698-s100895345.html") $oMeta = _IEGetObjByName($oIE, 'og:url') ConsoleWrite($oMeta.GetAttribute('content') & @CRLF)
    1 point
  13. If I understand the question correctly you may consider a different approach that uses filereadtoarray. Then you can search the array for your term with arrayfindall. Then you can use the results to modify the original array or create a new one as shown in the below example. That way you don't need to loop every line. #include<Array.au3> $testFile=@DesktopDir&"\lines.txt" ; your file here $fileArray=FileReadToArray($testFile) if @error <> 0 Then MsgBox(0,'',"Error. This is the error code: "&@error) EndIf _ArrayDisplay($fileArray); show the array of lines from the opened file $searchString="3" ; change this to what you are searching for $results=_ArrayFindAll($fileArray,$searchString,0,0,0,1) _ArrayDisplay($results); show the array containing all the indices for the searched term for $a=0 to UBound($results)-1 $addString="ABC" ; this is what I am adding to certain lines that contain the search term $fileArray[$results[$a]]&=$addString Next _ArrayDisplay($fileArray); show the modified array with the added text
    1 point
  14. Hello Abdulla, I'd like to suggest *NOT* to use ... $mydata = fileread(FileOpen("testdata2.csv")) fileopen() will give you a handle that has to be used once you should need to close the file in your script. The way you did it, the handle is lost, as direktly used for fileread(), instead of saving it to some variable. To process one line by another use FileReadLine() instead of FileRead() $CSV="testdata2.csv" $fCSV=FileOpen($CSV,0) while 1 $NextLine=FileReadLine($fCSV) if @error Then FileClose($fCSV) ExitLoop ; leave the WHILE loop, we are done Else ; process the next line EndIf WEnd Regards, Rudi.
    1 point
  15. ripdad

    Compiling Func Issue

    Quick glance... Move Next at line 383 to line 295 ?
    1 point
  16. I just see this post, and I remember I started (some time ago) to build a tool to explorer WMI classes, but I did not finish it completly. If someone is interested, here is the code and icons (i don't have enough time to finish it). The original idea was to add a Tab "Data" to show the values of each propertiy of the selected class (but there is scriptomatic for that). Hope it will be useful. Here is the archive with the code and icons : WMIExplorer.zip
    1 point
  17. Melba23

    FileSelectFolder

    trashy, My ChooseFileFolder UDF (look in my sig for the link) will let you display both files and folders but as you can distinguish between them when selected you should be able to get just a folder name even if the user actually goes for a file. M23
    1 point
×
×
  • Create New...