AutoHotkey Community
Let's help each other out
Skip to content
Post by guesto » 10 Apr 2016, 14:32
sinkfaze wrote:COM Object: ImageMagickObject COM+ ObjectPurpose: ImageMagick® is a software suite to create, edit, and compose bitmap images.System Requirements: ImageMagickObject COM+ ObjectDocumentation Link:Other Links: http://www.imagemagick.org/script/binary-releases.php#windowsBasic Code Example:
Code: [Select all]GeSHi © Codebox Plus
oI := ComObjCreate("ImageMagickObject.MagickImage.1")
Post by Joe Glines » 18 Jul 2015, 11:09
Joetazz wrote:Any idea what the maximum size that can be stored in this? I read through some of the documentation however I was playing around and was storing a lot more characters than what I saw in the documentation.
Post by Joe Glines » 17 Jul 2015, 19:08
sinkfaze wrote:COM Object: WScript.ShellPurpose: Exchange variables between scriptsSystem Requirements: GeneralDocumentation Link: WshEnvironment ObjectOther Links: Environment Variables
Post by joedf » 11 Jan 2015, 13:15
Post by lexikos » 11 Jan 2015, 03:20
Msxml2.XMLHTTP
Code: [Select all] [Expand]GeSHi © Codebox Plus
req := ComObjCreate("Msxml2.XMLHTTP"); Open a request with async enabled.req.open("GET", "https://autohotkey.com/download/1.1/version.txt", true); Set our callback function (v1.1.17+).req.onreadystatechange := Func("Ready"); Send the request.req.send()/*; If you're going to wait, there's no need for onreadystatechange.; Setting async=true and waiting like this allows the script to remain; responsive while the download is taking place, whereas async=false; will make the script unresponsive.while req.readyState != 4 sleep 100*/#PersistentReady() { global req if (req.readyState != 4) ; Not done yet. return if (req.status == 200 || req.status == 304) ; OK. MsgBox % "Latest AutoHotkey version: " req.responseText else MsgBox 16,, % "Status " req.status ExitApp}
WinHttpRequest.WaitForResponse()
Post by GeekDude » 07 Nov 2014, 08:32
Post by kon » 06 Nov 2014, 18:42
; ConstantsmsoTrue := -1pbPictureResolutionCommercialPrint_300dpi := 3pbTextOrientationHorizontal := 1VT_R4 := 4 ; 32-bit floating-point numberpbApp := ComObjCreate("Publisher.Application") ; Create a Publisher application object and store a reference to it in the pbApp variablepbApp.ActiveWindow.Visible := true ; Make the window visible; Application.NewDocument Method (Publisher); http://msdn.microsoft.com/en-us/library/office/ff940013%28v=office.15%29.aspxpbDoc := pbApp.NewDocument() ; Create a new document and store a reference to the object in the pbDoc variable; Shapes Methods (Publisher); http://msdn.microsoft.com/en-us/library/office/dn338310%28v=office.15%29.aspxpbDoc.Pages(1).Shapes.AddLine(100, 150, 500, 550) ; Draw a line from the point (100, 150) to point (500, 550); Shapes.AddCurve Method (Publisher); http://msdn.microsoft.com/en-us/library/office/ff939838%28v=office.15%29.aspxarrPoints := ComObjArray(VT_R4, 4, 2)arrPoints[0, 0] := 100arrPoints[0, 1] := 150arrPoints[1, 0] := 240arrPoints[1, 1] := 600arrPoints[2, 0] := 370arrPoints[2, 1] := 100arrPoints[3, 0] := 500arrPoints[3, 1] := 550pbDoc.Pages(1).Shapes.AddCurve(arrPoints) ; Draw a curve using the points specified by the array; Shapes.AddTextbox Method (Publisher); http://msdn.microsoft.com/en-us/library/office/ff939294%28v=office.15%29.aspxpbTextbox := pbDoc.Pages(1).Shapes.AddTextbox(pbTextOrientationHorizontal, 40, 60, 520, 65) ; Create a textbox; Story.TextRange Property (Publisher); http://msdn.microsoft.com/en-us/library/office/ff940334%28v=office.15%29.aspxpbTextRange := pbTextbox.TextFrame.Story.TextRange ; Store a reference to the range of text inside the textboxpbTextRange.Text := "AutoHotkey is awesome!"pbTextRange.Font.Bold := msoTruepbTextRange.Font.Size := 40pbTextRange.Font.Name := "Arial"; Page.SaveAsPicture Method (Publisher); http://msdn.microsoft.com/en-us/library/office/ff939984%28v=office.15%29.aspxSavePath := A_ScriptDir "\MyTestFile.jpg" ; Save the picture to the same directory as this scriptpbDoc.Pages(1).SaveAsPicture(SavePath, pbPictureResolutionCommercialPrint_300dpi); Document.SaveAs Method (Publisher); http://msdn.microsoft.com/en-us/library/office/ff940221%28v=office.15%29.aspxSavePath := A_ScriptDir "\MyTestDocument.pub" ; Save the document to the same directory as this scriptpbDoc.SaveAs(SavePath)return
Post by kon » 15 Jul 2014, 14:50
Post by Menixator » 03 Oct 2013, 04:13
Post by joedf » 03 Oct 2013, 04:09
Post by Hamlet » 03 Oct 2013, 03:38
sinkfaze wrote:COM Object: VBSript.RegExpPurpose: VBS Regular ExpressionsSystem Requirements: GeneralDocumentation Link: Regular Expression Object Properties and Methods
CNT =(123 abc 456 def789 efgh 012 ijkl)REX := ComObjCreate( "VBScript.RegExp" )REX.Global := True REX.IgnoreCase := FalseREX.Pattern := "(\d+)\s*(\w+)"COL := REX.Execute( CNT)Loop % COL.Count LT1 .= COL.Item( A_Index - 1 ).Value "`n" ; Zero Based OffsetLoop % COL.Count LT2 .= COL.Item( A_Index - 1 ).Submatches(0)For EMT in COL LT3 .= EMT.Value "`n"For EMT in COL LT4 .= EMT.Submatches(1)Msgbox % LT1 "`n`n" LT2 "`n`n" LT3 "`n`n" LT4Return
Post by sinkfaze » 02 Oct 2013, 20:53
haystack := "<A id='MyLink'>one<SPAN id='MyText'>two</SPAN>three</A>"regex := ComObjCreate("VBScript.RegExp")regex.Global := trueregex.IgnoreCase := trueregex.Pattern := "<.*?(id='\w+')?>"match := regex.Execute(haystack)t := "Haystack: " haystack "`nNeedle:`t " regex.Pattern "`n`n"t .= "`tPos (-1)`tLen`tVal`n`t------------------------------------------`n"for item in match { _ := "[" A_Index-1 "]`t" t .= _ item.FirstIndex "`t" item.Length "`t" item.value "`n" s .= _ item.SubMatches(0) "`n"};// first character in the string is identified as 0MsgBox,, % match.count " Matches", %t%MsgBox,, SubPatterns, %s%MsgBox,, Tags Replaced, % regex.Replace(haystack, "|")
Post by sinkfaze » 02 Oct 2013, 20:50
#NoEnv;[========];[ Load ];[========];-- Note: XML data from fincs. The data has been edited to remove all formatting.xmldata=(ltrim join <compactdiscs> <compactdisc> <artist type="individual">Frank Sinatra</artist> <title numberoftracks="4">In The Wee Small Hours</title> <tracks> <track>In The Wee Small Hours</track> <track>Mood Indigo</track> <track>Glad To Be Unhappy</track> <track>I Get Along Without You Very Well</track> </tracks> <price>$12.99</price> </compactdisc> <compactdisc> <artist type="band">The Offspring</artist> <title numberoftracks="5">Americana</title> <tracks> <track>Welcome</track> <track>Have You Ever</track> <track>Staring At The Sun</track> <track>Pretty Fly (For A White Guy)</track> </tracks> <price>$12.99</price> </compactdisc> </compactdiscs>)MsgBox Before:`n%xmldata%;-- Create DOM objectxmlDoc:=ComObjCreate("msxml2.DOMDocument.6.0")xmlDoc.async:=False;-- Load XML data to DOM objectxmlDoc.loadXML(xmldata)if xmlDoc.parseError.errorCode { MsgBox ,16 ,XML Load Error ,% "Unable to load XML data." . "`nError: " . xmlDoc.parseError.errorCode . "`nReason: " . xmlDoc.parseError.reason return };[==========];[ Format ];[==========];-- Create SAXXMLReader and MXXMLWriter objectsxmlReader:=ComObjCreate("msxml2.SAXXMLReader.6.0")xmlWriter:=ComObjCreate("msxml2.MXXMLWriter.6.0");-- Set properties on the XML writer.; Note: Some of the property assignments have been commented out so that the; default values will be used. Uncomment and set to another value if desired.xmlWriter.byteOrderMark:=True ;-- Determines whether to write the Byte Order Mark (BOM). The ; byteOrderMark property has no effect for BSTR or DOM output.xmlWriter.disableOutputEscaping:=False ;-- Matches the disable-output-escaping attribute of the <xsl:text> and ; <xsl:value-of> elements. When set to True, special symbols such as ; "&" are passed through literally.;;;;;xmlWriter.encoding:="UTF-8";;;;; ;-- Sets and gets encoding for the output. Observation: For some;;;;; ; reason, encoding is not displayed in the processing instructions;;;;; ; node if this property is set to "UTF-8".xmlWriter.omitXMLDeclaration:=False ;-- Forces the IMXWriter to skip the XML declaration. Useful for ; creating document fragments. Observation: For some reason (bug?), ; this property is assumed to be TRUE if the "output" property is a ; DOM object.xmlWriter.indent:=True ;-- Sets whether to indent output. There is no real need for the ; xmlWriter without this feature;;;;;xmlWriter.standAlone:=True;;;;; ;-- Sets the value of the standalone attribute in the XML declaration to;;;;; ; "yes" or "no".;;;;;xmlWriter.version:="1.0";;;;; ;-- Specifies the version to include in XML declarations. ;;;;;xmlWriter.output:="";;;;; ;-- Sets the destination and the type of output for IMXWriter.;;;;; ; Observation: If set, this property should (must?) be set last. ;-- Set the XML writer to the SAX content handlerxmlReader.contentHandler :=xmlWriterxmlReader.dtdHandler :=xmlWriterxmlReader.errorHandler :=xmlWriterxmlReader.putProperty("http://xml.org/sax/properties/lexical-handler",xmlWriter)xmlReader.putProperty("http://xml.org/sax/properties/declaration-handler",xmlWriter);-- Trigger the xmlWriter format engine. Show results.xmlReader.parse(xmlDoc)MsgBox % "After:`n" . xmlWriter.output ;;;;;;[========];;;;;;[ Save ];;;;;;[========];;;;;;-- Create output DOM object;;;;;xmlOutputDoc:=ComObjCreate("Msxml2.DOMDocument.6.0");;;;;xmlOutputDoc.async:=False;;;;;;;;;;;-- Load and save;;;;;xmlOutputDoc.loadXML(xmlWriter.output);;;;;xmlOutputDoc.save("FormattedXMLFile.xml");;;;;if xmlOutputDoc.parseError.errorCode;;;;; {;;;;; MsgBox;;;;; ,16;;;;; ,XML Save Error;;;;; ,% "Unable to save XML data.";;;;; . "`nError: " . xmlOutputDoc.parseError.errorCode;;;;; . "`nReason: " . xmlOutputDoc.parseError.reason;;;;;;;;;; return;;;;; };;;;;;;;;;MsgBox Formatted XML saved to "FormattedXMLFile.xml". %A_Space%
Post by sinkfaze » 02 Oct 2013, 20:46
#NoEnv#SingleInstance forceSetBatchLines -1ListLines OffSendMode InputSetWorkingDir %A_ScriptDir%; Autoexecuteglobal DataDir := A_MyDocuments "\Reports\"global FileList := ""gosub MakeSplashGUICopyFiles()SendEmail()ExitAppreturnCopyFiles(){ if not FileExist("A:\*.*") { MsgBox 4144, No Files Found , There are no files found on drive A:\`n`nOperation aborted! ExitApp } GuiControl Splash:, SplashText, Moving Files Gui Splash:Show ; Move files from drive A:\ to backup Loop A:\*.* { FileMove % A_LoopFileFullPath, % DataDir, 1 FileList .= (FileList = "") ? "" : "`n" FileList .= A_LoopFileName } Gui Splash:Cancel}SendEmail(){ if (FileList = "") return ; Create email message GuiControl Splash:, SplashText, Creating Email Gui Splash:Show omsg := ComObjCreate("Outlook.Application") NewMail := omsg.CreateItem(0) ; 0 = olMailItem NewMail.Subject := "Reports" NewMail.Body := "" Recipient := NewMail.Recipients.Add("Somebody's Name") Recipient.Type := 1 ; To: CC: = 2 BCC: = 3 ; Add attachments Loop Parse, FileList, `n, `r { NewMail.Body .= A_LoopField "`n" NewMail.Attachments.Add(DataDir . A_LoopField) } ; Send the email GuiControl Splash:, SplashText, Sending Email NewMail.Send() GuiControl Splash:, SplashText, Email Sent Sleep 2000 Gui Splash:Cancel}MakeSplashGUI:Gui Splash:+AlwaysOnTop -Caption +BorderGui Splash:Font, boldGui Splash:Add, Text , r2 w250 vSplashText ,return
Post by sinkfaze » 02 Oct 2013, 20:41
sDatabaseName := "e:\TestDatabase.MDB"adOpenStatic := 3, adLockOptimistic := 3, adUseClient := 3sConnectionString := "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" . sDatabaseNamesCommandText := "SELECT ID,Name FROM MyTable"; Create a database using ADOXoCatalog := ComObjCreate("ADOX.Catalog")oCatalog.Create(sConnectionString)oTable := ComObjCreate("ADOX.Table")oTable.Name := "MyTable"oTable.Columns.Append("ID", 3) ; adInteger 3 Indicates a four-byte signed integer (DBTYPE_I4). oTable.Columns.Append("Name", 202, 50) ; adVarWChar 202 Indicates a null-terminated Unicode character string. oCatalog.Tables.Append(oTable)oTable := ""oCatalog := ""; Connect to the database and query some data from itoConnection := ComObjCreate("ADODB.Connection")oConnection.Open(sConnectionString)oRecordset := ComObjCreate("ADODB.Recordset")oRecordset.CursorLocation := adUseClientoRecordset.Open(sCommandText, oConnection, adOpenStatic, adLockOptimistic); Add new recordoRecordset.AddNew()oRecordset.Fields["ID"].Value := 1oRecordset.Fields["Name"].Value := "AutoHotkey"oRecordset.Update(); Reading and display current recordIf !oRecordset.EOF{ MsgBox, % "ID: " oRecordset.Fields["ID"].Value "`n" . "Name: " oRecordset.Fields["Name"].Value}; Disconnect the connectionoRecordset.Close(), oConnection.Close()
Post by sinkfaze » 02 Oct 2013, 20:36
; Access the Session NameSpaceSession := ComObjActive("Outlook.Application").Session; Access the Folders CollectionFolders := Session.Folders("Outlook Data File").Folders; Loop through the MAPIFoldersLoop, % Folders.Count t .= Folders.item(A_Index).Name "`n"MsgBox, %t%; Loop through all the MailItems in the Drafts FolderDraftItems := Folders.item("Drafts").ItemsLoop, % DraftItems.Count { Item := DraftItems.item(A_Index) MsgBox, % "To:`t" Item.To . "`nSubject:`t" Item.Subject . "`nBody:`t" Item.Body}
Post by sinkfaze » 02 Oct 2013, 20:31
ZipFolder := A_Desktop "\folder.zip"NewDir := A_Desktop "\New Folder"FileCreateDir, %NewDir%shell := ComObjCreate("Shell.Application")Folder := shell.NameSpace(ZipFolder)NewFolder := shell.NameSpace(NewDir);// extract allNewFolder.CopyHere(Folder.items, 4|16)return;// extract 1-by-1for item in Folder.items NewFolder.CopyHere(item)
Post by sinkfaze » 02 Oct 2013, 20:28
;// Excel ConstantsxlMaximized := -4137xlAsc := xlYes := 1;// Create WorkBookXLBook := ComObjCreate("Excel.Sheet")XLSht := XLBook.ActiveSheet;// Maximize the WorkBook ControlXLBook.Windows(1).WindowState := xlMaximizedXLBook.Application.Visible := true;// Fill in Data & Sortfor cell in XLSht.Range("A1:C10") if (cell.row = 1) cell.value := "Header " A_Index else { Random, num, 0, 1 cell.value := num };// Sort DataMsgBox, Sorting by Column 1, then 2, then 3...XLSht.Cells.Sort( XLSht.Columns(1), xlAsc , XLSht.Columns(2), ComObjMissing(), xlAsc , XLSht.Columns(3), xlAsc , xlYes );// Save WorkBookMsgBox, 4, , The Workbook will close once the object is released - would you like to save it to the scirpt directory?IfMsgBox, Yes XLBook.SaveAs(A_ScriptDir "\Excel.Sheet Example.xls")
Post by sinkfaze » 02 Oct 2013, 20:25
/************************************************************* CAPIEncrypt.ahk This is a sample script to illustrate how to use the CAPICOMs EncryptedData to encrypt/decrypt text file. Note: For simplicity, this script does not handle exception.*************************************************************/ForReading := 1ForWriting := 2; CAPICOM's constants. CAPICOM_ENCRYPTION_ALGORITHM_RC2 := 0CAPICOM_ENCRYPTION_ALGORITHM_RC4 := 1CAPICOM_ENCRYPTION_ALGORITHM_DES := 2CAPICOM_ENCRYPTION_ALGORITHM_3DES := 3CAPICOM_ENCRYPTION_ALGORITHM_AES := 4 CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM := 0CAPICOM_ENCRYPTION_KEY_LENGTH_40_BITS := 1CAPICOM_ENCRYPTION_KEY_LENGTH_56_BITS := 2CAPICOM_ENCRYPTION_KEY_LENGTH_128_BITS := 3CAPICOM_ENCRYPTION_KEY_LENGTH_192_BITS := 4CAPICOM_ENCRYPTION_KEY_LENGTH_256_BITS := 5strSF := "C:\test.txt"strOF := "C:\Encrypted.txt"Algorithm := CAPICOM_ENCRYPTION_ALGORITHM_AESKeyLength := CAPICOM_ENCRYPTION_KEY_LENGTH_56_BITSPassword := "123456"EncryptCommand(strSF, strOF, Algorithm, KeyLength, Password);~ DecryptCommand(strSF, strOF, Password)return; End Main; EncryptCommand() - Encrypt content of text file ObjectFile.EncryptCommand(SourceFile, ObjectFile, Algorithm, KeyLength, Password){ Content := "" Message := "" EncryptedData := "" ; Create the EncryptedData object. EncryptedData := ComObjCreate("CAPICOM.EncryptedData") ; algorithm, key size, and encryption password. EncryptedData.Algorithm.Name := Algorithm EncryptedData.Algorithm.KeyLength := KeyLength EncryptedData.SetSecret(Password) ; Display main title. MsgBox, % "Encrypting text file " . SourceFile . "." ; Load content of text file to be encrypted. LoadFile(SourceFile, Content) ; Now encrypt it. EncryptedData.Content := Content Message := EncryptedData.Encrypt ; Finally, save encrypted message to strSF. SaveFile(ObjectFile, Message) MsgBox, % "Successful - Encrypted message saved to " . ObjectFile . "." ; Free resources. EncryptedData := "" }; DecryptCommand() - Decrypt an encrypted file.DecryptCommand(SourceFile, ObjectFile, Password){ Message := "" EncryptedData := "" ; Create the EncryptedData object. EncryptedData := ComObjCreate("CAPICOM.EncryptedData") ; decryption password. EncryptedData.SetSecret(Password) ; Display main title. MsgBox, % "Decrypting encrypted text file " . SourceFile . "." ; Load the encrypted message. LoadFile(SourceFile, Message) ; Now decrypt it. EncryptedData.Decrypt(Message) ; Finally, save decrypted content to strSF. SaveFile(ObjectFile, EncryptedData.Content) MsgBox, % "Successful - Decrypted content saved to " . ObjectFile . "." ; Free resources. EncryptedData := ""}; LoadFile() - Read content of a text file.LoadFile(FileName, ByRef Buffer) { global ForReading objFSO := "", objTS := "" objFSO := ComObjCreate("Scripting.FileSystemObject") If Not objFSO.FileExists(FileName) { MsgBox, % "Error: File " . FileName . " not found." ExitApp } objTS := objFSO.OpenTextFile(FileName, ForReading) Buffer := objTS.ReadAll}; SaveFile() - Save string to file.SaveFile(FileName, ByRef Buffer){ global ForWriting objFSO := "", objTS := "" objFSO := ComObjCreate("Scripting.FileSystemObject") objTS := objFSO.OpenTextFile(FileName, ForWriting, True) objTS.Write(Buffer)}
Post by sinkfaze » 02 Oct 2013, 20:20
/*olAppointmentItem 1 olContactItem 2 olDistributionListItem 7 olJournalItem 4 olMailItem 0 olNoteItem 5 olPostItem 6 olTaskItem 3 */; will create a new mail itemComObjActive("Outlook.Application").CreateItem[0].GetInspector.Display(); will create a new note itemComObjActive("Outlook.Application").CreateItem[5].GetInspector.Display()
Gui, Add, Text, xm ym w325 Section, Select the Outlook item you wish to create:Gui, Add, ListBox, r6 xs wp AltSubmit gItemSelection vitem, Mail||Appointment|Contact|Task|Journal|Note|Post|Distribution ListGui, Add, Button, xs+295 gCreateItem, OKGui, Show, AutoSize Center, Create New Outlook ItemreturnItemSelection:CreateItem:if (A_ThisLabel="ItemSelection" && A_GuiEvent<>"DoubleClick") returnGui, SubmitComObjActive("Outlook.Application").CreateItem[item-1].GetInspector.Display()Gui, DestroyreturnGuiCancel:GuiClose:Gui, Destroyreturn
Top