Jump to content
Sign in to follow this  
ptrex

Powershell - COM

Recommended Posts

ptrex

Powershell - COM

Many Windows Business Application are now only supporting Powershell, as a scripting environment.

Like MS Exchange / SharePoint / Active Directory / MS SQL / etc.

This makes Au3 a handicapped scripting environment for administrators to work with.

But hold on !

Since 2008 Sapien Technologies has released a Powershell COM component named ActiveXPoSH, that makes the bridge between all

Download here http://www.sapien.com/blog/2008/06/25/activexposh-is-now-a-free-download/

First register an account before getting the download access http://www.sapien.com/auth

Why would you need Au3 to join PS1 ?

Well it is a hell lot easier to create GUI's in AU3 than it is in PS1, so let's marry the 2.

Here's an example script translated from there help file to AU3

;**************************************************************************
; Copyright (c) SAPIEN Technologies, Inc. All rights reserved
; This file is part of the PrimalScript 2007 Code Samples.
;
; File: ActiveXposh.vbs
;
; Comments:
;
; Disclaimer: This source code is intended only as a supplement to
;   SAPIEN Development Tools and/or on-line documentation.
;   See these other materials for detailed information
;   regarding SAPIEN code samples.
;
; THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
; KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
; PARTICULAR PURPOSE.
;**************************************************************************

#AutoIt3Wrapper_UseX64=N

Dim $ActiveXPosh

Const $OUTPUT_CONSOLE = 0
Const $OUTPUT_WINDOW = 1
Const $OUTPUT_BUFFER = 2

Func CreateActiveXPosh()
Dim $success

; Create the PowerShell connector object
$ActiveXPosh = ObjCreate("SAPIEN.ActiveXPoSH")
$success = $ActiveXPosh.Init(False) ;Do not load profiles
If $success <> 0 then
Consolewrite( "Init failed" & @CR)
endif
If $ActiveXPosh.IsPowerShellInstalled Then
Consolewrite( "Ready to run PowerShell commands" & @CR)
Else
Consolewrite( "PowerShell not installed" & @CR)
EndIf
; Set the output mode
$ActiveXPosh.OutputMode = $OUTPUT_CONSOLE
EndFunc


Func DownloadFile($URL,$Destination)
Local $Return
Dim $Command
Dim $FSO

;Download a file with PowerShell
$ActiveXPosh.Execute("$Client = new-object System.Net.WebClient")
;Note that variables are preserved between calls
; Construct a $Command
$Command = "$Client.DownloadFile('" & $URL & "','" & $Destination & "')"
ConsoleWrite ("Downloading ..." & @CR)
$ActiveXPosh.Execute($Command)

$FSO = ObjCreate("Scripting.FileSystemObject")
If $FSO.FileExists($Destination) Then
ConsoleWrite ("File transfer complete" & @CR)
Else
ConsoleWrite ("File Transfer failed" & @CR)
EndIf
Return $Return
EndFunc

Func ListServices()
Dim $outtext
; Set the $OUTPUT mode to $BUFFER
$ActiveXPosh.OutputMode = $OUTPUT_BUFFER
$ActiveXPosh.Execute("Get-WmiObject -class Win32_Service | Format-Table -property Name, State")

; Get the $OUTPUT line by line and add it to a variable
For $str In $ActiveXPosh.OUTPUT()
$outtext = $outtext & $str
$outtext = $outtext & @CRLF
Next

; Alternatively you can get the $OUTPUT as a single String
; $outtext = $ActiveXPosh.OutputString

ConsoleWrite ($outtext & @CR)
$ActiveXPosh.ClearOutput() ; Empty the $OUTPUT $BUFFER
EndFunc

; Create the actual Object
CreateActiveXPosh()

$Status = $ActiveXPosh.GetValue("(Get-Service UPS).Status")
if($Status = "Stopped") then
ConsoleWrite ("UPS Service is stopped" & @CR)
else
ConsoleWrite ("UPS Service is " & $Status & @CR)
EndIf


; List all running processes using PowerShell
$ActiveXPosh.Execute("Get-Process")

; Check if WinWord is running using PowerShell
if $ActiveXPosh.Eval("get-process winword") = 1 Then
ConsoleWrite ("Microsoft Word is running" & @CR)
Else
ConsoleWrite ("Microsoft Word is not running" & @CR)
EndIf

DownloadFile ("[url="http://izzy.org/scripts/PowerShell/activexposh.pdf","C:\Temp\activexposh.pdf"]http://izzy.org/scripts/PowerShell/activexposh.pdf","C:\Temp\activexposh.pdf[/url]")

; Use ListServices to show all services in this machine using PowerShell()
ListServices()

ConsoleWrite ("Version " & $ActiveXPosh.GetValue("$PSHOME") & @CR)

$ActiveXPosh = ""

Example how to load a PS1 command file

#AutoIt3Wrapper_UseX64=N

Dim $ActiveXPosh

Const $OUTPUT_CONSOLE = 0
Const $OUTPUT_WINDOW = 1
Const $OUTPUT_BUFFER = 2

Func CreateActiveXPosh()
 Local $success
 ; Create the PowerShell connector object
 $ActiveXPosh = ObjCreate("SAPIEN.ActiveXPoSH")
 $success = $ActiveXPosh.Init(False) ;Do not load profiles
 If $success <> 0 then
  Consolewrite( "Init failed" & @CR)
 endif
 If $ActiveXPosh.IsPowerShellInstalled Then
  Consolewrite( "Ready to run PowerShell commands" & @CR & @CR)
 Else
  Consolewrite( "PowerShell not installed" & @CR & @CR)
 EndIf
 ; Set the output mode
 $ActiveXPosh.OutputMode = $OUTPUT_CONSOLE
 $ActiveXPosh.OutputWidth = 250
EndFunc

; Create the actual Object
CreateActiveXPosh()

$PS1 = FileOpenDialog("Open PS1 Script", @ScriptDir & "\", "PS Scripts (*.ps1)")
PowerShell_Script($PS1)

Func PowerShell_Script($hPSFile)
$file = FileOpen($hPSFile, 0) ; Open read only
 If $file = -1 Then
  MsgBox(0, "Error", "Unable to open file.")
  Exit
 EndIf

Local $sCmd

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
 $sCmd &= $line & @CRLF
Wend
 ; ConsoleWrite("Line read: " & @CRLF & $sCmd & @CRLF)

FileClose($file)
 ExecuteCMD($sCmd)
EndFunc


Func ExecuteCMD($sPSCmd)
 Dim $outtext
 ; Set the $OUTPUT mode to $BUFFER
 $ActiveXPosh.OutputMode = $OUTPUT_BUFFER
 $ActiveXPosh.Execute($sPSCmd)

 ; Get the $OUTPUT line by line and add it to a variable
 For $str In $ActiveXPosh.OUTPUT()
   $outtext =  $outtext & $str
  $outtext =  $outtext & @CRLF
 Next

 ; Alternatively you can get the $OUTPUT as a single String
; $outtext = $ActiveXPosh.OutputString
 ConsoleWrite ($outtext & @CR)

 $ActiveXPosh.ClearOutput() ; Empty the $OUTPUT $BUFFER
EndFunc

I am running this from component from my Windows 7 x64 bit Powershell 3.0 version, and it still is working fine.

Enjoy !

ptrex

Edited by ptrex
  • Like 1

Share this post


Link to post
Share on other sites
supersonic

Thank you for this - it is def. useful! :-)

Share this post


Link to post
Share on other sites
UEZ

Is ActiveXPoSH integreted in PrimalScript 2012? I cannot see a seperate download link for it!

Sound very interesting to have a bridge to PS! :)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
supersonic

@ UEZ

Yes, it is integrated in PS 2012.

Share this post


Link to post
Share on other sites
ptrex

@All

It is many years back that I downloaded this. But I think nowadays you first need to register an account, to get access to the download section.

If you click on download you get there http://www.sapien.com/auth

It is available as free standalone download.

rgds

ptrex

Edited by ptrex

Share this post


Link to post
Share on other sites
supersonic

@ ptrex

Is it possible to load a PowerShell Console File like using the Parameter "-PSConsoleFile"?

Share this post


Link to post
Share on other sites
ptrex
water

Powershell - COM

Many Windows Business Application are now only supporting Powershell, as a scripting environment.

Like MS Exchange / SharePoint / Active Directory / MS SQL / etc.

Do you have a Microsoft link describing when/why Active Directory is only supported by PS?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
ptrex

Hi Water,

Oeps did I enter on your domain ;)

Let me refine what I meant.

Powershell uses uses .NET objects that are just not completely available using COM ADSI.

Therefore Powershell can and will simplify your life as administrator.

Writing a 1 liner to do the job, instead of 15 lines makes a difference.

Out of curiosity how to do you list all deleted AD object using your UDF ?

PS:

Your UDF is still very usefull don't misunderstand me !

rgds

ptrex

Share this post


Link to post
Share on other sites
water

Hi ptrex

sorry if my post was misleading! You didn't enter on my domain.

I just like to know what goes on so I can support users of my UDF as good as possible.

I have never tried to list deleted items. Are they moved to another OU before actually being deleted?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
ptrex

Share this post


Link to post
Share on other sites
DaleHohm

Thanks for posting this ptrex.

I actually looked for this for a long time after powershell was released. I expected it would be created by Microsoft, but when it wasn't, I figured it would show up from ActiveState if at all. When it didn't appear there, I gave up hope for it.

Too bad I didn't know about it earlier, but it will be very handy.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
ptrex
water

Haven't tried the PS COM utility yet. I'm on vacation right now.

If a new problem arises that can't be solved with the current UDF I will do some testing with the PS COM utility.

The rewrite of the Word and Excel UDF will need my full attention during the next weeks.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
ValeryVal

This makes Au3 a handicapped scripting environment for administrators to work with

And also for crafty indirect GUIs:

$ActiveXPosh = ObjCreate("SAPIEN.ActiveXPoSH")
$success = $ActiveXPosh.Init(False) ;Do not load profiles
; Try GUI
$Line = ''
$Line &= '[reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")' & @CrLf
$Line &= '$form= New-Object Windows.Forms.Form' & @CrLf
$Line &= '$button = New-Object Windows.Forms.Button' & @CrLf
$Line &= '$button.text = "AutoIt is here!"' & @CrLf
$Line &= '$form.text = "PowerShell WinForms GUI from AutoIt"' & @CrLf
$Line &= '$form.Size = New-Object Drawing.Point 450,200' & @CrLf

; Create the label control and set text, size and location
$Line &= '$label = New-Object Windows.Forms.Label' & @CrLf
$Line &= '$label.Location = New-Object Drawing.Point 50,30' & @CrLf
$Line &= '$label.Size = New-Object Drawing.Point 300,15' & @CrLf
$Line &= '$label.text = "Enter your name and click the button:"' & @CrLf
; Create TextBox and set text, size and location
$Line &= '$textfield = New-Object Windows.Forms.TextBox' & @CrLf
$Line &= '$textfield.Location = New-Object Drawing.Point 50,60' & @CrLf
$Line &= '$textfield.Size = New-Object Drawing.Point 350,30' & @CrLf
; Create Button and set text and location
$Line &= '$button = New-Object Windows.Forms.Button' & @CrLf
$Line &= '$button.text = "Welcome to AutoIt"' & @CrLf
$Line &= '$button.Location = New-Object Drawing.Point 200,90' & @CrLf
; Set up event handler to extarct text from TextBox and display it on the Label.
$Line &= '$button.add_click({$label.Text = "Hi, " + $textfield.text})' & @CrLf
; Add the controls to the Form
$Line &= '$form.controls.add($button)' & @CrLf
$Line &= '$form.controls.add($label)' & @CrLf
$Line &= '$form.controls.add($textfield)' & @CrLf
; Display the dialog
$Line &= '$form.ShowDialog()' & @CrLf
$ActiveXPosh.Execute($Line)

Thank for your message about the Sapien Technologies News.


The point of world view

Share this post


Link to post
Share on other sites
ptrex
ValeryVal

Yes I know, this opens up a gate to all the .Net objects.

Good news is also that PowerShell Analyze (http://www.powershellanalyzer.com/)

IS NOW 100% FREE like ActiveXPoSH.

Posted Image

Early (2007) I've automated it through it's control class name, ie WindowsForms10.window.8.app.0.378734a1 and so on.

Sincerely,

Val...


The point of world view

Share this post


Link to post
Share on other sites
ptrex
SpinningCone

This is exactly what I need and have been looking for for ages! but it doesn't work :-(

Is there a way to get this to create a 64bit com object? what happens is I am able to run the example and it will run commands however the command I really need to run is "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin" so I can do exchange stuff. on my 64 bit system this cannot be done from a 32 bit instance of powershell. it just returns that the snap in is not installed.

is there a way to get this to work properly in 64bit ?

EDIT: just to check based on some other stuff I did try to add the .dll directly to windows/system32 and ran regasm 64bit to register the thing but no dice. still won't see the object if i have usex64=y

Edited by SpinningCone

Share this post


Link to post
Share on other sites
ptrex

@SpinningCone

I have not see a x64 version around I am afraid :-(

My only source is Google

rgds

ptrex

PS : You will need to put money on the table to buy the later version of Primal Scripts x32 and x64 compatible

http://www.sapien.com/blog/2011/06/13/back-from-teched-2011-does-it-support-sharepoint-and-exchange/

Edited by ptrex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • Bilgus
      By Bilgus
      ; NetFirewallPolicy2 COM UDF Library for AutoIt3
      ; AutoIt Version : 3.3.14.5
      ; Description ...: Windows Firewall Policy2 Interface, Provides access to the firewall policy for Windows Vista+
      Including Test Script 
      _NetFw_Get_CurrentProfileTypes                           Retrieves the currently active firewall profile(s) _NetFw_Get_FirewallEnabled                               Indicates whether a firewall is enabled locally _NetFw_Put_FirewallEnabled                               Specifies whether a firewall is enabled locally _NetFw_Get_ExcludedInterfaces                            Indicates a list of interfaces on which firewall settings are excluded _NetFw_Put_ExcludedInterfaces                            Specifies a list of interfaces on which firewall settings are excluded _NetFw_Get_BlockAllInboundTraffic                        Indicates whether the firewall should not allow inbound traffic _NetFw_Put_BlockAllInboundTraffic                        Specifies whether the firewall should not allow inbound traffic _NetFw_Get_NotificationsDisabled                         Indicates whether interactive firewall notifications are disabled _NetFw_Put_NotificationsDisabled                         Specifies whether interactive firewall notifications are disabled _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled  Indicates whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled  Specifies whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Get_Rules                                         Retrieves the interface to collection of firewall rules _NetFw_Get_ServiceRestriction                            Retrieves the interface used to access the Windows Service Hardening store _NetFw_EnableRuleGroup                                   Enables or disables a specified group of firewall rules _NetFw_IsRuleGroupEnabled                                Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_RestoreLocalFirewallDefaults                      Restores the local firewall configuration to its default state _NetFw_Get_DefaultInboundAction                          Indicates the default action for inbound traffic _NetFw_Put_DefaultInboundAction                          Specifies the default action for inbound traffic _NetFw_Get_DefaultOutboundAction                         Indicates the default action for outbound traffic _NetFw_Put_DefaultOutboundAction                         Specifies the default action for outbound traffic _NetFw_Get_IsRuleGroupCurrentlyEnabled                   Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_Get_LocalPolicyModifyState                        Determines if adding or setting a rule or group of rules will take effect in the current firewall profile  
      UDF:
      Test Script:
       
    • Bilgus
      By Bilgus
      I was Playing around With AutoIt this evening and wondered how hard it would be to get typeinfo like the COM Viewers do only using AutoIt
      Turns out it was pretty easy.
      A Few Notes:
      CAarray info is unfinished I didn't have any objects to test it on so I left it Limited.
      The Object must have IDispatch exposed (ITypeInfo is derivative)
      Its Just a proof of concept Run with it but don't carry scissors
      ITypeInfoCOM.au3
      ITypeInfoTest.au3
       
      Output IWebBrowserApp
       
      Output ObjCreate(MediaPlayer.MediaPlayer.1)
       
    • Bilgus
      By Bilgus
       IGroupPolicyObject interface
      ;;IGroupPolicyObject #RequireAdmin #include-once #include <WinAPIConstants.au3> ; $S_OK #include <WinAPIReg.au3> ;_WinAPI_GetRegKeyNameByHandle Global Enum $GPO_SECTION_ROOT = 0x0, $GPO_SECTION_USER, $GPO_SECTION_MACHINE Global Enum $GPO_OPEN_LOAD_REGISTRY = 0x1, $GPO_OPEN_READ_ONLY Global Enum $GPO_OPTION_DISABLE_USER = 0x1, $GPO_OPTION_DISABLE_MACHINE Global Enum $GPOTypeLocal = 0x0, $GPOTypeRemote, $GPOTypeDS, $GPOTypeLocalUser, $GPOTypeLocalGroup Global Const $sCLSID_GroupPolicyObject = "{EA502722-A23D-11D1-A7D3-0000F87571E3}" Global Const $sIID_IGroupPolicyObject = "{EA502723-A23D-11D1-A7D3-0000F87571E3}" Global Const $dtag_IGroupPolicyObject = _ "New hresult(wstr;wstr;dword);" & _ ; Creates a new GPO in the Active Directory with the specified display name. "OpenDSGPO hresult(wstr;dword);" & _ ; Opens the specified GPO and optionally loads the registry information. "OpenLocalMachineGPO hresult(dword);" & _ ; Opens the default GPO for the computer and optionally loads the registry information. "OpenRemoteMachineGPO hresult(wstr;dword);" & _ ; Opens the default GPO for the specified remote computer and optionally loads the registry information. "Save hResult(bool;bool;ptr;ptr);" & _ ; Saves the specified registry policy settings to disk and updates the revision number of the GPO. "Delete hresult();" & _ ; Deletes the GPO. "GetName hResult(wstr;int);" & _ ; Retrieves the unique name for the GPO. "GetDisplayName hResult(wstr;int);" & _ ; Retrieves the display name for the GPO. "SetDisplayName hresult(wstr);" & _ ; Sets the display name for the GPO. "GetPath hResult(wstr;int);" & _ ; Retrieves the path to the GPO. "GetDSPath hresult(dword;wstr;int);" & _ ; Retrieves the Active Directory path to the root of the specified GPO section. "GetFileSysPath hresult(dword;wstr;int);" & _ ; Retrieves the file system path (UNC format) to the root of the specified GPO section. "GetRegistryKey hresult(dword;handle);" & _ ; Retrieves a handle to the root of the registry key for the specified GPO section. "GetOptions hResult(dword*);" & _ ; Retrieves the options for the GPO. "SetOptions hresult(dword;dword);" & _ ; Sets the options for the GPO. "GetType hResult(dword*);" & _ ; Retrieves type information for the GPO being edited. "GetMachineName hResult(wstr;int);" & _ ; Retrieves the computer name of the remote GPO. "GetPropertySheetPages hresult(ptr;uint*);" ; Retrieves the property sheet pages associated with the GPO. Test() Func Test() Local $iResult Local $oIGroupPolicy Local $aGpoType[5] = ["Local", "Remote", "Active Directory", "LocalUser", "LocalGroup"] $oIGroupPolicy = ObjCreateInterface($sCLSID_GroupPolicyObject, $sIID_IGroupPolicyObject, $dtag_IGroupPolicyObject) While True If Not IsObj($oIGroupPolicy) Then ConsoleWrite("Failed To Retrieve Interface") $iResult = $E_NOINTERFACE ExitLoop Else ConsoleWrite("Success: " & ObjName($oIGroupPolicy, 1) & @CRLF) EndIf Local $sLoc, $sPath, $sName, $iType $tKey = DllStructCreate("handle hKey") $iResult = $oIGroupPolicy.OpenLocalMachineGPO(BitOR($GPO_OPEN_LOAD_REGISTRY, $GPO_OPEN_READ_ONLY)) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetDisplayName($sLoc, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetName($sName, 65535) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sLoc & " : " & $sName & @CRLF) $iResult = $oIGroupPolicy.GetPath($sPath, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sPath & @CRLF) $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite("Type: " & $aGpoType[$iType] & @CRLF) $iResult = $oIGroupPolicy.GetRegistryKey($GPO_SECTION_USER, DllStructGetPtr($tKey)) If $iResult <> $S_OK Then ExitLoop ConsoleWrite(_WinAPI_GetRegKeyNameByHandle(DllStructGetData($tKey, "hKey")) & @CRLF) ExitLoop WEnd Return SetError($iResult, 0, ($iResult = $S_OK)) EndFunc ;==>Test Note: Not well tested..
    • Fenzik
      By Fenzik
       Hello all"
      I have curious problem with com object implementation of Sapi 5.1.
      In some cases }Some Voice engines] the metods for retrieve the voice parameters fails with error :Member not exists:.
      But the Retrieved Voice object can speak the given text, so It exists and work.
      Example of this type of Engine can be this one: http://download.kobavision.be/KobaSpeech3/KobaSpeech 3 With Vocalizer Serena - English (Great Britain).exe (can work as demo)
      So my question is> Is there some way to workaround or solve this issue?
      What i tryed:
      1. Typical use of Sapi.spvoice object:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
       
        $spvoice = ObjCreate("sapi.spvoice")
      for $voice in $spvoice.getvoices()
        msgbox(0, "Voice", $voice.getdescription())
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc

      2. Implement workaround based on Nvda Screen reader sapi5 Library at https://github.com/nvaccess/nvda/blob/master/source/synthDrivers/sapi5.py
      Thys code in Pascal should work, so i tryed to reproduce it in Autoit.
      Pascal code just as example:
                   SOTokens:=SpVoice.GetVoices('','');
                   for i:=0 to SOTokens.Count-1 do
                   try
                        SOToken:=SOTokens.Item(I); s:=SOToken.GetDescription(0);
      end
      In Autoit I tryed it like this:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
        $spvoice = ObjCreate("sapi.spvoice")
      for $i = 0 to $spvoice.getvoices.count-1
      $name = $spvoice.getvoices.item($i).getdescription
      msgbox(0,"Voice", $name)
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc
      Both of this methods returning same Error ("Member not exists.").
      Thanks a lot for help.
      Znefyg
    • gillesg
      By gillesg
      Hello,
       
      Is there a way to get all the properties and method of a COM object thru Autoit.
      I am looking in a way of display the imbricated structure of object and method.
       
      Example of COm objects are "itunes.application", "Shell.application" and so on.
      The idea is to have a code looking like
      $objtobrowse = objcreate("itunes.application") if isobj($objtobrowse) then $colItems = $objtobrowse.buildinproperty For $objItem In $colItems ConsoleWrite($objItem.<Name> & " - " & $objItem.<Value> & @CRLF) Next EndIf  
×