COM Object Reference

Post your working scripts, libraries and tools
User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 10:38

Another way to retrieve file/folder properties.

COM Object: Scripting.FileSystemObject
Purpose: Retrieves file & folder properties.
System Requirements: General
Documentation Link: FileSystemObject
DateLastAccessed Property, DateCreated Property, DateLastModified Property
Size Property
Name Property
Shortname Property
Type property
Attributes Property
Path Property
Shortpath Property

Basic Code Example - this example demonstrates how to retrieve the properties of a specified file and folder via FileSystemObject:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 18:51

COM Object: winmgmts
Purpose: Manipulating Services
System Requirements: General
Documentation Link: Win32_Service Class
WMI Scripting Primer: Part 3
Services
Other Links: Scripts to manage Services
Basic Code Example - retrieves service information and demonstrates starting and stopping a service:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 18:56

COM Object: WScript.Shell
Purpose: Various Administration Tasks
System Requirements: General, WSH vertion 5.6 for the Exc() method
Documentation Link WshShell Object
Other Links: WSH Primer
Basic Code Example:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 18:59

COM Object: WScript.Shell
Purpose: Exchange variables between scripts
System Requirements: General
Documentation Link: WshEnvironment Object
Other Links: Environment Variables
Basic Code Example - demonstrates how to set a volatile environment variable and read it from another script:Save this code as Sender.ahk

Code: [Select all] [Download] GeSHi © Codebox Plus

objShell :=	ComObjCreate("WScript.Shell")
objEnv := objShell.Environment("Volatile")
loop {
random, env, 0, 100
;Here the variable is named "Test". Change the name as you need.
;But the other script to read the value needs the corresponding variable name.
;This variable and its value will be lost after logout/restart/shutdown of your computer.
objEnv.Item("Test") := env
sleep 100
}
Return


Save this code as Receiver.ahk

Code: [Select all] [Download] GeSHi © Codebox Plus

objShell :=	ComObjCreate("WScript.Shell")
objEnv := objShell.Environment("Volatile")
loop {
tooltip % objEnv.Item("Test")
sleep 100
}
User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 19:09

COM Object: Excel.Application
Purpose: Work with SafeArray and Range in Excel
System Requirements: General
Basic Code Example
Hotkeys: F1 - set values to Range("A1:B3") via SafeArray, F2 - get values from Range("A1:B3") via SafeArray

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 19:11

COM Object: Shell.Application [Folder Object]
Purpose: Access/Manipulate Folders
System Requirements: General
Documentation Link: Shell Object, Folder Object
Code Example: Rename Folders/Files without using FileCopy(Dir)

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 19:17

COM Object: Shell.Explorer [Embedded Browser]
Purpose: Embed a Trident Browser (IE) in a Gui
System Requirements: General
Documentation Link: Shell.Explorer, iWebBrowser2
Basic Code Example: Embed a browser navigate to a web site and wait for it to loadEvery one asks why ctrl+key comboes and enter do not work in theier implementation of this. Please see how this is solved in this example

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 19:21

COM Object: WMPlayer.OCX
Purpose: Play Media Files; Embed WMP control in GUI
System Requirements: Windows Media Player 9 Series or later
Documentation Link: Player Object
Code Example:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Embed player in a GUI:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 19:34

COM Object: Ahk.ComSurrogate.32/64
Purpose: Create COM objects of a specified bitness
System Requirements: ComDispatch.ahk (with the included ComRemote.ahk library)
Description:This is a simple COM script that proxies the creation of 32-bit only objects on 64-bit scripts and vice versa.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



You need to have it running in the background using the AHK_L build of the appropriate bitness (running both AHK_L builds at the same time is supported), then you can use these functions to create objects:

Code: [Select all] [Download] GeSHi © Codebox Plus

ComCreateObj32(ProgIDorCLSID)
{
static _sur := A_PtrSize = 8 ? ComObjActive("Ahk.ComSurrogate.32") : ""
return A_PtrSize = 8 ? _sur.ObjCreate(ProgIDorCLSID) : ComObjCreate(ProgIDorCLSID)
}

ComCreateObj64(ProgIDorCLSID)
{
static _sur := A_PtrSize = 4 ? ComObjActive("Ahk.ComSurrogate.64") : ""
return A_PtrSize = 4 ? _sur.ObjCreate(ProgIDorCLSID) : ComObjCreate(ProgIDorCLSID)
}


Example: ScriptControl on 64-bit AHK_L:

Code: [Select all] [Download] GeSHi © Codebox Plus

oSC :=	ComCreateObj32("ScriptControl"), oSC.Language :=	"VBScript"
oSC.ExecuteStatement("MsgBox ""Hello World!""")
User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 20:17

COM Object: WIA.CommonDialog/WIA.DeviceManager/WIA.ImageFile/WIA.ImageProcess/WIA.Rational/WIA.Vector
Purpose: acquire images on digital cameras, scanners, or Web cameras, and to rotate, scale, and annotate your image files.
System Requirements: require Windows XP Service Pack 1 (SP1) or later, and Windows Image Acquisition Automation Library v2.0 Tool
Documentation Link: http://msdn.microsoft.com/en-us/library/ms630827
Other Links:
Basic Code Example:

Display Detailed Image Information

The following example shows how to display detailed information about one of the sample pictures from Microsoft Windows XP.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Take a Picture

The following example shows how to signal a camera to take a picture if the device selected is a camera.

Code: [Select all] [Download] GeSHi © Codebox Plus

objCommonDialog :=	ComObjCreate("WIA.CommonDialog")

dev := objCommonDialog.ShowSelectDevice

If (dev.Type = CameraDeviceType)
itm := dev.ExecuteCommand(wiaCommandTakePicture)
return
User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 20:20

COM Object: Outlook.Application
Purpose: Create various new items in Outlook
System Requirements: Windows 2000 or higher
Documentation Link: Outlook 2003 Visual Basic Reference
Other Links: CreateItem Method, GetInspector Property, OlItemType constants
Basic Code Example: The entire process of creating a new Outlook item can be executed in a single line using one of the OlItemType constants shown in the below code (and in the above link) with the CreateItem method. This method is valuable if you have problems opening new items using the command line switches.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



And here's a sample ListBox GUI that will allow you to select and create a new instance of any of the applicable Outlook items:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 20:25

COM Object: CAPICOM Series
Purpose: digitally sign data, sign code, verify digital signatures, envelop data for privacy, hash data, encrypt/decrypt data and more.
System Requirements: 32-bit OS, for more details, please see MSDN
Documentation Link: CAPICOM Reference
Other Links:Platform SDK Redistributable: CAPICOM
Basic Code Example: First require to install capicom.dll from microsoft's site above.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 20:28

COM Object: Excel.Sheet
Purpose: Hold MS Excel Data - represents a MS Excel workbook
System Requirements: MS Excel
Documentation Link: WorkBook Object
Other Links: Excel Constants, Sort Method
Code Example:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Note - the Excel.Sheet object will open in the Active Excel Process (accessed by ComObjActive) - or will create a new Excel Process - and it will close when the pointer is released.
User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 20:31

COM Object: Shell.Application [Folder & FolderItems object]
Purpose: Extract Files From/Unzip a Zip Directory
System Requirements: General
Documentation Link: Shell Object, Folder Object, FolderItems
Other Links: CopyHere Method
Code Example:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 20:36

COM Object: Outlook.Application
Purpose: Personal Information Manager
System Requirements: MS Outlook (MS Office)
Documentation Link: Application Object
Other Links: Session Property, Folders Collection, MAPIFolder Object, MailItem Object
Basic Code Example: This example will access the Outlook Folders, and then each item in the Drafts Folder, assuming Outlook is already open.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 20:41

COM Object: ActiveX Data Objects (ADODB.Connection and others)
Purpose: Work with a variety of databases, such as CSV, Excel xls, Access mdb and so on.
System Requirements: General
Documentation Link: http://msdn.microsoft.com/en-us/library/windows/desktop/ms675532
Basic Code Example:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 20:46

COM Object: Outlook
Purpose: Demonstrate sending an email with attachments using Outlook
System Requirements: Windows 2000 or higher
Documentation Link: Outlook Object Model
Other Links: CreateItem Method, OlItemType constants, Attachments Collection, Recipients Collection
Basic Code Example: The following code copies the files from he A:\ drive to a backup folder, then emails them as attachments to the specified recipient.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 20:50

COM Objects: msxml2.DOMDocument.6.0, msxml2.SAXXMLReader.6.0, msxml2.MXXMLWriter.6.0
Purpose: Format XML output
System Requirements: Windows XP SP3+, Microsoft Core XML Services (MSXML) 6.0
Documentation Link: XML DOM Reference
Other Links: Use MXXMLWriter
Basic Code Example:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Although the flexibility of the XML writer is limited, the output is correctly parsed, formatted, and encoded.
User avatar
sinkfaze
Posts: 413
Joined: 01 Oct 2013, 08:01

Re: COM Object Reference

02 Oct 2013, 20:53

COM Object: VBSript.RegExp
Purpose: VBS Regular Expressions
System Requirements: General
Documentation Link: Regular Expression Object Properties and Methods, Microsoft Beefs Up VBScript with Regular Expressions
Basic Code Example: Global Regex match & replace

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Hamlet
Posts: 32
Joined: 02 Oct 2013, 09:55
Location: Seoul, Korea

Re: COM Object Reference

03 Oct 2013, 03:38

sinkfaze wrote:COM Object: VBSript.RegExp
Purpose: VBS Regular Expressions
System Requirements: General
Documentation Link: Regular Expression Object Properties and Methods

Personally, I'd like to recommend the following link.

Microsoft Beefs Up VBScript with Regular Expressions
http://msdn.microsoft.com/en-us/library/ms974570.aspx

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by Hamlet on 03 Oct 2013, 04:39, edited 2 times in total.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bing [Bot], cocobanana and 19 guests