Search the Community
Showing results for tags 'COM'.
-
Hi all. Today I would like to introduce the beginning of the UDF. How to get started: http://winscp.net/eng/docs/library http://winscp.net/eng/docs/library_install Original readme_automation.txt: now I have only one function (standard FTP on standard port) to show the future possibilities: Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") Const Enum _ $__eWSCP_SO_Protocol_Sftp, _ $__eWSCP_SO_Protocol_Scp, _ $__eWSCP_SO_Protocol_Ftp Const Enum _ $__eWSCP_TO_TransferMode_Binary, _ $__eWSCP_TO_TransferMode_Ascii, _ $__eWSCP_TO_TransferMode_Automatic Example_PutFile('YOUR FTP HOST NAME', 'YOUR USER NAME', 'YOUR PASSWORD') Func Example_PutFile($sHostName, $sUserName, $sPassword) Local $sFileFullPath = StringReplace(@ScriptFullPath, '\', '\\') Local $sFilesToPut = StringReplace(@ScriptDir & '\*.au3', '\', '\\') ; based on: ; http://winscp.net/eng/docs/library_com_wsh#vbscript Local $oSessionOptions = ObjCreate("WinSCP.SessionOptions"); With $oSessionOptions .Protocol = $__eWSCP_SO_Protocol_Ftp .HostName = $sHostName; .UserName = $sUserName; .Password = $sPassword; ; below not jet tested ; .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" EndWith Local $oSession = ObjCreate("WinSCP.Session"); With $oSession ; Connect: Open sesion with defined options .Open($oSessionOptions); ; Set TransferOptions Local $oTransferOptions = ObjCreate("WinSCP.TransferOptions") $oTransferOptions.TransferMode = $__eWSCP_TO_TransferMode_Binary ; Upload files: put @ScriptFullPath to the ROOT directory Local $oTransferResult = .PutFiles($sFilesToPut, '/'); ; Throw on any error $oTransferResult.Check ; Print results For $oTransfer In $oTransferResult.Transfers ConsoleWrite("Upload of " & $oTransfer.FileName & " succeeded" & @CRLF) Next ;' Disconnect, clean up .Dispose() EndWith ; CleanUp $oSession = '' $oSessionOptions = '' EndFunc ;==>Example_PutFile Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc EDIT: 2014-06-20 04:47 - script changed
-
; 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:
- 5 replies
-
- net_fw
- hnetcfg.fwpolicy2
-
(and 1 more)
Tagged with:
-
I tried to implement the code in this topic: Firstly, i have no idea how these lines of code work but meanwhile i noticed that: ; Everytime autoit wants to call a method, get or set a property in a object it needs to go to ; IDispatch::GetIDsFromNames. This is our version of that function, note that by defining this ourselves ; we can fool autoit to believe that the object supports a lot of different properties/methods. Func __IDispatch_GetIDsFromNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId) ... EndFunc The problem is i ran into is that some object calls didn't go through IDispatch::GetIDsFromNames. Here is the code to replicate what i'm mentioning: I followed the example in the topic and tried to do the same thing with method .Documents (line 193) and .Open (line 194) but didn't get the same result because .Documents was being passed through __IDispatch_GetIDsFromNames while .Open didn't. $Au3_CallByName = 'Documents' Local $oDoc = $oAppl.Au3_CallByName $Au3_CallByName = 'Open' $oDoc = $oDoc.Au3_CallByName($sFilePath, $bConfirmConversions, $bReadOnly, $bAddToRecentFiles, $sOpenPassword, "", $bRevert, $sWritePassword, "", $iFormat) Console outputs: ==> The requested action with this object has failed.: $oDoc = $oDoc.Au3_CallByName($sFilePath, $bConfirmConversions, $bReadOnly, $bAddToRecentFiles, $sOpenPassword, "", $bRevert, $sWritePassword, "", $iFormat) $oDoc = $oDoc^ ERROR Is there any workarounds to solve this? Thank you!
-
Trying to figure out how to do CallByName on AutoIt COM objects due to the lack of being able to set properties within an Execute() statement Several Ideas were Tried https://www.autoitscript.com/forum/topic/200129-set-object-properties-with-propertyname-and-value-taken-from-an-array/ I think this is the best; Patching the vtable of IDispatch so we can intercept a Fake function call ($obj.Au3_CallByName) use it like this Local $oDictionary = ObjCreate("Scripting.Dictionary") ; EXAMPLE Au3_CallByname_Init() ; (you can optionally provide a classname here but we patch the main Idispatch interface so really no need) $Au3_CallByName = "Add" ; Method we want to call $oDictionary.Au3_CallByName("Test", "Value") Au3_CallByname_Init(False) ; (Not Strictly Needed unhooked on exit) NOTE: Au3_CallByname_Init() doesn't have to be called at the top of the script, just call it before you need to call by name... Code + Example #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;Au3CallByName, Bilgus Global $Au3_CallByName = 0 Local $hKernel32 = DllOpen("Kernel32.dll") OnAutoItExitRegister(__CallByNameCleanup) Func __CallByNameCleanup() Au3_CallByName_Init(False) ;Unload DllClose($hKernel32) EndFunc ;==>__CallByNameCleanup ; Takes a pointer to the v-table in a class and replaces specified member Id in it to a new one. Func __HookVTableEntry($pVtable, $iVtableOffset, $pHook, ByRef $pOldRet) ;;https://www.autoitscript.com/forum/topic/107678-hooking-into-the-idispatch-interface/ Local Const $PAGE_READWRITE = 0x04 Local $tpVtable = DllStructCreate("ptr", $pVtable) Local $szPtr = DllStructGetSize($tpVtable) Local $pFirstEntry, $pEntry, $tEntry, $aCall, $flOldProtect, $bStatus ; Dereference the vtable pointer $pFirstEntry = DllStructGetData($tpVtable, 1) $pEntry = $pFirstEntry + ($iVtableOffset * $szPtr) ; Make the memory free for all. Yay! $aCall = DllCall($hKernel32, "int", "VirtualProtect", "ptr", $pEntry, "long", $szPtr, "dword", $PAGE_READWRITE, "dword*", 0) If @error Or Not $aCall[0] Then ConsoleWriteError("Error: Failed To hook vTable" & @CRLF) Return False EndIf $flOldProtect = $aCall[4] $tEntry = DllStructCreate("ptr", $pEntry) $pOldRet = DllStructGetData($tEntry, 1) If $pOldRet <> $pHook Then DllStructSetData($tEntry, 1, $pHook) $bStatus = True Else ;Already Hooked ConsoleWriteError("Error: vTable is already hooked" & @CRLF) $bStatus = False EndIf ;put the memory protect back how we found it DllCall($hKernel32, "int", "VirtualProtect", "ptr", $pEntry, "long", $szPtr, "dword", $flOldProtect, "dword*", 0) Return $bStatus EndFunc ;==>__HookVTableEntry ; Everytime autoit wants to call a method, get or set a property in a object it needs to go to ; IDispatch::GetIDsFromNames. This is our version of that function, note that by defining this ourselves ; we can fool autoit to believe that the object supports a lot of different properties/methods. Func __IDispatch_GetIDsFromNames($pSelf, $riid, $rgszNames, $cNames, $lcid, $rgDispId) Local Const $CSTR_EQUAL = 0x02 Local Const $LOCALE_SYSTEM_DEFAULT = 0x800 Local Const $DISP_E_UNKNOWNNAME = 0x80020006 Local Static $pGIFN = __Pointer_GetIDsFromNames() Local Static $tpMember = DllStructCreate("ptr") If $Au3_CallByName Then Local $hRes, $aCall, $tMember ;autoit only asks for one member $aCall = DllCall($hKernel32, 'int', 'CompareStringW', 'dword', $LOCALE_SYSTEM_DEFAULT, 'dword', 0, 'wstr', "Au3_CallByName", 'int', -1, _ 'struct*', DllStructGetData(DllStructCreate("ptr[" & $cNames & "]", $rgszNames), 1, 1), 'int', -1) If Not @error And $aCall[0] = $CSTR_EQUAL Then ;ConsoleWrite("CallByName: " & $Au3_CallByName & @CRLF) $tMember = DllStructCreate("wchar[" & StringLen($Au3_CallByName) + 1 & "]") DllStructSetData($tMember, 1, $Au3_CallByName) DllStructSetData($tpMember, 1, DllStructGetPtr($tMember)) $rgszNames = $tpMember $Au3_CallByName = 0 EndIf EndIf ;Call the original GetIDsFromNames $hRes = DllCallAddress("LRESULT", $pGIFN, "ptr", $pSelf, "ptr", $riid, _ "struct*", $rgszNames, "dword", $cNames, "dword", $lcid, "ptr", $rgDispId) If @error Then ConsoleWrite("Error: GetIDsFromNames: " & @error & @CRLF) Return $DISP_E_UNKNOWNNAME EndIf Return $hRes[0] EndFunc ;==>__IDispatch_GetIDsFromNames Func __Pointer_GetIDsFromNames($ptr = 0) Local Static $pOldGIFN = $ptr If $ptr <> 0 Then $pOldGIFN = $ptr Return $pOldGIFN EndFunc ;==>__Pointer_GetIDsFromNames Func Au3_CallByName_Init($bHook = True, $classname = "shell.application") Local Const $iOffset_GetIDsFromNames = 5 Local Static $IDispatch_GetIDsFromNames_Callback = 0 Local $oObject, $pObject, $pHook, $pOldGIFN If $bHook Then If $IDispatch_GetIDsFromNames_Callback = 0 Then $IDispatch_GetIDsFromNames_Callback = DllCallbackRegister("__IDispatch_GetIDsFromNames", "LRESULT", "ptr;ptr;ptr;dword;dword;ptr") EndIf $pHook = DllCallbackGetPtr($IDispatch_GetIDsFromNames_Callback) Else $pHook = __Pointer_GetIDsFromNames() If $pHook <= 0 Then Return ;Already Unloaded EndIf $oObject = ObjCreate($classname) $pObject = DllStructSetData(DllStructCreate("ptr"), 1, $oObject) If __HookVTableEntry($pObject, $iOffset_GetIDsFromNames, $pHook, $pOldGIFN) Then __Pointer_GetIDsFromNames($pOldGIFN) ;Save the original pointer to GetIDsFromNames If Not $bHook Then DllCallbackFree($IDispatch_GetIDsFromNames_Callback) $IDispatch_GetIDsFromNames_Callback = 0 EndIf Else ;Error EndIf $oObject = 0 EndFunc ;==>Au3_CallByName_Init ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;TESTS; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Au3_CallByName_Init() #include <ie.au3> Global $oRegistrationInfo = _IECreate() Global $aRegistrationInfo[] = ['Left=10', 'Top= 10', 'Width=450', 'Height=600'] Global $oObject = $oRegistrationInfo Local $oDictionary = ObjCreate("Scripting.Dictionary") Local $oDictionary2 = ObjCreate("Scripting.Dictionary") ;Au3_CallByName_Init($oObject) __TS_TaskPropertiesSet($oObject, $aRegistrationInfo) MsgBox(0, "Info", "Press OK to exit") $oRegistrationInfo.quit $oRegistrationInfo = 0 $oObject = 0 Sleep(1000) For $i = 1 To 10 $Au3_CallByName = "Add" $oDictionary.Au3_CallByName("test1:" & $i, "Dictionary Item: " & $i) Next $Au3_CallByName = "keys" For $sKey In $oDictionary.Au3_CallByName() For $j = 0 To 1 $Au3_CallByName = ($j = 0) ? "Item" : "Exists" ConsoleWrite($sKey & " -> " & $oDictionary.Au3_CallByName($sKey) & @CRLF) Next Next Au3_CallByName_Init(False) ;Unload Au3_CallByName_Init() Local $aRegistrationInfo[] = ['Left=1000', 'Width=450'] ConsoleWrite(@CRLF & "NEW IE" & @CRLF & @CRLF) $oRegistrationInfo = _IECreate() __TS_TaskPropertiesSet($oRegistrationInfo, $aRegistrationInfo) MsgBox(0, "Info", "Press OK to exit") $oRegistrationInfo.quit For $i = 1 To 10 $Au3_CallByName = "Add" $oDictionary2.Au3_CallByName("test2:" & $i, "Dictionary Item: " & $i) Next $Au3_CallByName = "keys" For $sKey In $oDictionary2.Au3_CallByName() For $j = 0 To 1 $Au3_CallByName = ($j = 0) ? "Item" : "Exists" ConsoleWrite($sKey & " -> " & $oDictionary2.Au3_CallByName($sKey) & @CRLF) Next Next Au3_CallByName_Init(False) ;Unload (Not Strictly Needed, Done on Script Close) Func __TS_TaskPropertiesSet(ByRef $oObject, $aProperties) Local $aTemp If IsArray($aProperties) Then For $i = 0 To UBound($aProperties) - 1 $aTemp = StringSplit($aProperties[$i], "=", 2) ; 2 -> $STR_NOCOUNT) If @error Then ContinueLoop ConsoleWrite("Command: $oObject." & $aTemp[0] & " = " & $aTemp[1] & @CRLF) $Au3_CallByName = $aTemp[0] $oObject.Au3_CallByName = $aTemp[1] ConsoleWrite("Result : " & Hex(@error) & @CRLF) ; If @error Then Return SetError(1, @error, 0) Next EndIf EndFunc ;==>__TS_TaskPropertiesSet
-
I'm using Python to call AutoIt functions, but some functions don't work. Is there a reason for this? If so, can I fix it? from win32com.client import Dispatch Auto = Dispatch("AutoItX3.Control") def autoTest(): print Auto.MsgBox('') When I run it I get this error: line 516, in __getattr__ raise AttributeError("%s.%s" % (self._username_, attr)) AttributeError: AutoItX3.Control.MsgBox It seems like it's reading 'MsgBox' as an attribute and not a function. Any thoughts?
-
Today, in the end as well, worked out using the Acrobat Reader ActiveX COM Object "AcroPDF.PDF.1" #include-once #include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <MenuConstants.au3> #include <WinAPI.au3> ;~ Thanks to BrewManNH ;~ http://www.autoitscript.com/forum/topic/134878-guiregistermsg-replacement-for-guictrlsetonevent-and-guigetmsg/ ;~ Thanks to mikell ;~ http://www.autoitscript.com/forum/topic/161985-how-to-close-gui-with-guiregistermsg/ ; Install a custom error handler Global $oMyError = ObjEvent("AutoIt.Error", "_ComErrFunc") Global $__hExampleGUI Global $__idOPEN Global $_fExit Global $__hACROBAT_GUI = '' Global $__idACROBAT_GUI_CTRL_AX = '' Global $__oACROBAT_READER = '' #include <GUIConstantsEx.au3> ;~ GUIRegisterMsg($WM_ERASEBKGND, "_WM_EXTRACTOR") ;~ GUIRegisterMsg($WM_PAINT, "_WM_EXTRACTOR") ;~ GUIRegisterMsg($WM_ACTIVATE, "_WM_EXTRACTOR") ;~ GUIRegisterMsg($WM_CAPTURECHANGED, "_WM_EXTRACTOR") ;~ GUIRegisterMsg($WM_DEVICECHANGE, "_WM_EXTRACTOR") GUIRegisterMsg($WM_EXITSIZEMOVE, "_WM_EXTRACTOR") GUIRegisterMsg($WM_COMMAND, "_WM_EXTRACTOR") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_EXTRACTOR") GUIRegisterMsg($WM_HSCROLL, "_WM_EXTRACTOR") _ExampleProgram_Gui() While 1 Sleep(10) If $_fExit Then _ACROBAT_GUI_DELETE() DeleteGui() Exit EndIf WEnd Func DeleteGui() GUIDelete($__hExampleGUI) EndFunc ;==>DeleteGui Func _ExampleProgram_Gui() ; Create a GUI with various controls. $__hExampleGUI = GUICreate("Example") $__idOPEN = GUICtrlCreateButton("&Open", 310, 370, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $__hExampleGUI) EndFunc ;==>_ExampleProgram_Gui #Region ACROBAT FUNCTION Func _AcrobatInit() $__oACROBAT_READER = ObjCreate("AcroPDF.PDF.1"); Return $__oACROBAT_READER.GetVersions EndFunc ;==>_AcrobatInit Func _Acrobat_Events(ByRef $aMSG) If $aMSG[1] = $__hACROBAT_GUI Then Switch $aMSG[0] Case $GUI_EVENT_CLOSE _ACROBAT_GUI_DELETE() EndSwitch EndIf EndFunc ;==>_Acrobat_Events Func _ACROBAT_Destroy() $__oACROBAT_READER = "" ;~ MsgBox(1,'test','destroyed') EndFunc ;==>_ACROBAT_Destroy Func _AcrobatShow($sFile, $sTitle = "PDF ", $iLeft = 50, $iTop = 0, $iWidth = 1000, $iHeight = 700) If FileExists($sFile) Then _AcrobatInit() ; Set option $__oACROBAT_READER.src = $sFile $__oACROBAT_READER.SetLayoutMode(4) $__oACROBAT_READER.SetPageMode(1) $__oACROBAT_READER.SetShowToolbar(0) $__oACROBAT_READER.SetView(1) ; Create GUI $__hACROBAT_GUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX)) $__idACROBAT_GUI_CTRL_AX = GUICtrlCreateObj($__oACROBAT_READER, 5, 5, $iWidth - 20, $iHeight - 10) GUICtrlSetStyle($__idACROBAT_GUI_CTRL_AX, $WS_VISIBLE) GUISetState() EndIf EndFunc ;==>_AcrobatShow Func _ACROBAT_Refresh() If IsObj($__oACROBAT_READER) Then Local $hPreviouslyGui = GUISwitch($__hACROBAT_GUI) GUISetState(@SW_LOCK) Local $iGUI_PDFWidth = WinGetPos($__hACROBAT_GUI)[2] - 20 Local $iGUI_PDFHeight = WinGetPos($__hACROBAT_GUI)[3] - 40 Local $sFile = $__oACROBAT_READER.src ; this below line do not works with Acro Reader ; Local $iCurrentPage = $__oACROBAT_READER.GetNumber Local $iCurrentPage = 0 _ACROBAT_Destroy() GUICtrlDelete($__idACROBAT_GUI_CTRL_AX) _AcrobatInit() $__idACROBAT_GUI_CTRL_AX = GUICtrlCreateObj($__oACROBAT_READER, 5, 5, $iGUI_PDFWidth, $iGUI_PDFHeight) $__oACROBAT_READER.src = $sFile ;~ $__oACROBAT_READER.SetCurrentPage($iCurrentPage) GUISetState(@SW_UNLOCK) GUISwitch($hPreviouslyGui) EndIf EndFunc ;==>_ACROBAT_Refresh Func _ACROBAT_GUI_DELETE() _ACROBAT_Destroy() if IsHWnd($__hACROBAT_GUI) then GUIDelete($__hACROBAT_GUI) EndFunc ;==>_ACROBAT_GUI_DELETE #EndRegion ACROBAT FUNCTION #Region MSG and ERROR HANDLER Func _WM_EXTRACTOR($hWnd, $iMsg, $wParam, $lParam) ;~ ConsoleWrite('! $hWnd = ' & $hWnd & ' $iMsg = ' & $iMsg & '('&HEX($iMsg)&')'& ' $wParam = ' & $wParam & ' $lParam = ' & $lParam & @CRLF) If $hWnd = ControlGetHandle($__hACROBAT_GUI, '', $__idACROBAT_GUI_CTRL_AX) Then ConsoleWrite('! -------------- $hWnd = ' & $hWnd & ' $iMsg = ' & $iMsg & '(' & Hex($iMsg) & ')' & ' $wParam = ' & $wParam & ' $lParam = ' & $lParam & @CRLF) EndIf If $hWnd = $__hACROBAT_GUI Then Switch $iMsg Case $WM_COMMAND #cs Case $WM_ACTIVATE Local $test = BitAND($wParam, 0x00000004) if $test <> 0 then MsgBox(1,'$WM_ACTIVATE','test') _ACROBAT_Refresh() EndIf Case $WM_ERASEBKGND WinGetHandle("[ACTIVE]") if $__hACROBAT_GUI <> _WinAPI_GetWindow ( $__hACROBAT_GUI, $GW_HWNDPREV ) then ConsoleWrite('! Case $WM_ERASEBKGND' & @CRLF) _ACROBAT_Refresh() _WinAPI_RedrawWindow($__hACROBAT_GUI,0,0,$RDW_NOERASE) EndIf Case $WM_PAINT _WinAPI_RedrawWindow($__hACROBAT_GUI,0,0,$RDW_NOERASE) Case $WM_CAPTURECHANGED _ACROBAT_Refresh() Case $WM_DEVICECHANGE _ACROBAT_Refresh() #ce Case $WM_EXITSIZEMOVE _ACROBAT_Refresh() Case $WM_SYSCOMMAND ;~ Local $test = BitAND($wParam, 0xFFF0) Local $test = BitAND($wParam, 0x0000FFFF) Switch $test Case $SC_CLOSE _ACROBAT_GUI_DELETE() Case $SC_CONTEXTHELP Case $SC_DEFAULT Case $SC_HOTKEY Case $SC_HSCROLL Case $SC_KEYMENU Case $SC_MAXIMIZE _ACROBAT_Refresh() Case $SC_MINIMIZE Case $SC_MONITORPOWER Case $SC_MOUSEMENU Case $SC_MOVE ;~ _ACROBAT_Refresh() Case $SC_NEXTWINDOW ;~ _ACROBAT_Refresh() Case $SC_PREVWINDOW ;~ _ACROBAT_Refresh() Case $SC_RESTORE _ACROBAT_Refresh() Case $SC_SCREENSAVE Case $SC_SIZE Case $SC_TASKLIST Case $SC_VSCROLL EndSwitch EndSwitch EndIf If $hWnd = $__hExampleGUI Then Switch $iMsg Case $WM_COMMAND Local $nID = BitAND($wParam, 0x0000FFFF) Local $hCtrl = $lParam Switch $nID Case $__idOPEN if not IsObj($__oACROBAT_READER) then _AcrobatShow(FileOpenDialog("Choose PDF", "C:\Temp", "PDF Files(*.pdf)", 3)) ; put your own start folder here) EndIf EndSwitch Case $WM_SYSCOMMAND Local $test = BitAND($wParam, 0xFFF0) Switch $test Case $SC_CLOSE $_fExit = True Case $SC_CONTEXTHELP Case $SC_DEFAULT Case $SC_HOTKEY Case $SC_HSCROLL Case $SC_KEYMENU Case $SC_MAXIMIZE Case $SC_MINIMIZE Case $SC_MONITORPOWER Case $SC_MOUSEMENU Case $SC_MOVE Case $SC_NEXTWINDOW Case $SC_PREVWINDOW Case $SC_RESTORE Case $SC_SCREENSAVE Case $SC_SIZE Case $SC_TASKLIST Case $SC_VSCROLL EndSwitch EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_EXTRACTOR Func _ComErrFunc() Local $HexNumber = Hex($oMyError.number, 8) MsgBox(0, "AutoItCOM Test", _ "We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) EndFunc ;==>_ComErrFunc #EndRegion MSG and ERROR HANDLER Any comments are welcome. Cheers mLipok
- 20 replies
-
- acrobat reader
-
(and 3 more)
Tagged with:
-
One web created Excel sheet is crashing when calling the _Excel_BookOpen function. "C:\Program Files (x86)\AutoIt3\Include\Excel.au3" (227) : ==> Variable must be of type "Object".: $oExcel.Windows($oWorkbook.Name).Visible = $bVisible $oExcel.Windows($oWorkbook.Name)^ ERRORLocal $oWorkbook = $oExcel.Workbooks.Open($sFilePath, $bUpdateLinks, $bReadOnly, Default, $sPassword, $sWritePassword) in line 225 seems to load the file but no error is set. Is there any way to catch those errors to avoid app crash? ObjEvent("AutoIt.Error", "ErrFunc") doesn't catch it! Tested on 3.3.14.2 and 3.3.15.0 and Office 2013.
-
Hi all, I'm trying to write a script that connects with a VBA/COM API to get the status of a connected phone. I've been looking up and down this forum for tips or other user's experiences, but I can't seem to find anything (even remotely) similar. It shouldn't be so hard to do, however. Software I'm trying to connect to I'm trying to integrate CallCenter by using their API, which is documented over here : JustRemotePhone API Reference Things I've tried I've tried using ObjCreate but I don't get any result, it always returns the same (negative) error. #Version 1 tried ObjCreate("JustRemotePhone.RemotePhoneService") #Version 2 tried ObjCreate("JustRemotePhoneCOM.RemotePhoneService") #Version 3 tried ObjCreate("JustRemotePhoneCOM.RemotePhoneService.Application") None of the three versions I tried seem to deliver any result other than a negative error value which basically says that the given class is not valid. I am starting to get the hang of AutoIt by now, but unmanaged programming languages and object-oriented stuff is still quite a grey zone for me. If anyone could help me 'talk' to this application, I'd be immensely grateful! Thanks in advance and kind regards from Belgium! Jan
-
Hello again, i have a code that changes username to favorite, my problem is how to use ObjEvent() function to catch errors, i've red Help File and Forum's Topics but i can't understand too much😐 Here is a code (I've copied this codes from a user of AutoIt Forum): $sOldUser = "Administrator" $sNewUser = "Admin" $oUser = ObjGet("WinNT://" & @ComputerName & "/" & $sOldUser & ",user") $oComputer = ObjGet("WinNT://" & @ComputerName) $oNewUser = $oComputer.MoveHere($oUser.ADsPath, $sNewUser) Thanks for your care, I'm new to AutoIt and days should be passed with my coding and practicing to don't bother you :)❤
- 6 replies
-
- obj
- error handling
-
(and 1 more)
Tagged with:
-
So I'm trying to do some as400 automation and hit a wall when trying to get a COM object. The code on line 8 is failing, the as400.ws file opens with PCSWS.exe so I tried using that as the file path too but that didn't work either. Any and all help is greatly appreciated! $file = "C:\Users\Rhidlor\Desktop\as400.ws" If Not FileExists($file) Then MsgBox(0, "Error", "Error finding file") Exit EndIf $object = ObjGet($file) If @error Then MsgBox(0, "Error", "Error getting object") Exit EndIf $object.SendKeys("05")
-
Ever wondered how to interact with your compiled .NET assembly and AutoIt script using COM? Then look no further, as I try to explain in simple terms the approach at which to achieve this. The code (AutoIt): As quite a few of you know, I am against the use of Global variables, as more often than not a simple approach such as encapsulating a Local Static variable in a wrapper function is just as good. Some may point out the use of the enumeration, but this is only for the purposes of doing away with "magic numbers", with the chances to expand in the future and not having to remember which number represents what etc... To create the .NET dll: In Visual Studio select a new project and class library. From there, go ahead and rename the namespace and class to something meaningful as you will need it later on when you connect to the COM interface of your .NET assembly. Add [ComVisible(true)] above the class declaration line << IMPORTANT. Once you've added all your wonderful C# related code, build the assembly and copy the .dll file to the location of your AutoIt script. Then it's just as simple as calling the _DotNet_Load() function with the filename of the .dll and voila, you have the power of AutoIt and .NET in one script. Example use of Functions: #include <File.au3> Global Const $DOTNET_PATHS_INDEX = 0, $DOTNET_REGASM_OK = 0 Global Enum $DOTNET_LOADDLL, $DOTNET_UNLOADDLL, $DOTNET_UNLOADDLLALL ; Enumeration used for the _DotNet_* functions. Global Enum $DOTNET_PATHS_FILEPATH, $DOTNET_PATHS_GUID, $DOTNET_PATHS_MAX ; Enumeration used for the internal filepath array. #cs NOTE: Don't forget to add [ComVisible(true)] to the top of the class in the class library. Otherwise it won't work. #ce Example() ; A simple example of registering and unregistering the AutoIt.dll Func Example() If _DotNet_Load('AutoIt.dll') Then ; Load the .NET compiled dll. Local $oPerson = ObjCreate('AutoIt.Person') ; Namespace.Class. If IsObj($oPerson) Then $oPerson.Name = "guinness" $oPerson.Age = Random(18, 99, 1) ConsoleWrite('Person''s age => ' & $oPerson.Age & @CRLF) $oPerson.IncreaseAge() ; A silly method to show the encapsulation of the object around the Age property. ConsoleWrite('Person''s new age => ' & $oPerson.Age & @CRLF) ConsoleWrite($oPerson.ToString() & @CRLF) ; Call the ToString() method which was overriden. Else ConsoleWrite('An error occurred when registering the Dll.' & @CRLF) EndIf Else ConsoleWrite('An error occurred when registering the Dll.' & @CRLF) EndIf ; The dll is automatically unloaded when the application closes. EndFunc ;==>Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DotNet_Load ; Description ...: Load a .NET compiled dll assembly. ; Syntax ........: _DotNet_Load($sDllPath) ; Parameters ....: $sDllPath - A .NET compiled dll assembly located in the @ScriptDir directory. ; $bAddAsCurrentUser - [optional] True or false to add to the current user (supresses UAC). Default is False, all users. ; Return values .: Success: True ; Failure: False and sets @error to non-zero: ; 1 = Incorrect filetype aka not a dll. ; 2 = Dll does not exist in the @ScriptDir location. ; 3 = .NET RegAsm.exe file not found. ; 4 = Dll already registered. ; 5 = Unable to retrieve the GUID for registering as a current user. ; Author ........: guinness ; Remarks .......: With ideas by funkey for running under the current user. ; Example .......: Yes ; =============================================================================================================================== Func _DotNet_Load($sDllPath, $bAddAsCurrentUser = Default) If $bAddAsCurrentUser = Default Then $bAddAsCurrentUser = False Local $bReturn = __DotNet_Wrapper($sDllPath, $DOTNET_LOADDLL, $bAddAsCurrentUser) Return SetError(@error, @extended, $bReturn) EndFunc ;==>_DotNet_Load ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DotNet_Unload ; Description ...: Unload a previously registered .NET compiled dll assembly. ; Syntax ........: _DotNet_Unload($sDllPath) ; Parameters ....: $sDllPath - A .NET compiled dll assembly located in the @ScriptDir directory. ; Return values .: Success: True ; Failure: False and sets @error to non-zero: ; 1 = Incorrect filetype aka not a dll. ; 2 = Dll does not exist in the @ScriptDir location. ; 3 = .NET RegAsm.exe file not found. ; Author ........: guinness ; Remarks .......: With ideas by funkey for running under the current user. ; Example .......: Yes ; =============================================================================================================================== Func _DotNet_Unload($sDllPath) Local $bReturn = __DotNet_Wrapper($sDllPath, $DOTNET_UNLOADDLL, Default) Return SetError(@error, @extended, $bReturn) EndFunc ;==>_DotNet_Unload ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DotNet_UnloadAll ; Description ...: Unload all previously registered .NET compiled dll assemblies. ; Syntax ........: _DotNet_UnloadAll() ; Parameters ....: None ; Return values .: Success: True ; Failure: False and sets @error to non-zero: ; 1 = Incorrect filetype aka not a dll. ; 2 = Dll does not exist in the @ScriptDir location. ; 3 = .NET RegAsm.exe file not found. ; 4 = Dll already registered. ; 5 = Unable to retrieve the GUID for registering as a current user. ; Author ........: guinness ; Remarks .......: With ideas by funkey for running under the current user. ; Example .......: Yes ; =============================================================================================================================== Func _DotNet_UnloadAll() Local $bReturn = __DotNet_Wrapper(Null, $DOTNET_UNLOADDLLALL, Default) Return SetError(@error, @extended, $bReturn) EndFunc ;==>_DotNet_UnloadAll ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __DotNet_Wrapper ; Description ...: A wrapper for the _DotNet_* functions. ; Syntax ........: __DotNet_Wrapper($sDllPath, $iType) ; Parameters ....: $sDllPath - A .NET compiled dll assembly located in the @ScriptDir directory. ; $iType - A $DOTNET_* constant. ; Return values .: Success: True ; Failure: False and sets @error to non-zero: ; 1 = Incorrect filetype aka not a dll. ; 2 = Dll does not exist in the @ScriptDir location. ; 3 = .NET RegAsm.exe file not found. ; 4 = Dll already registered. ; 5 = Unable to retrieve the GUID for registering as current user. ; Author ........: guinness ; Remarks .......: ### DO NOT INVOKE, AS THIS IS A WRAPPER FOR THE ABOVE FUNCTIONS. ### ; Remarks .......: With ideas by funkey for running under the current user. ; Related .......: Thanks to Bugfix for the initial idea: http://www.autoitscript.com/forum/topic/129164-create-a-net-class-and-run-it-as-object-from-your-autoit-script/?p=938459 ; Example .......: Yes ; =============================================================================================================================== Func __DotNet_Wrapper($sDllPath, $iType, $bAddAsCurrentUser) Local Static $aDllPaths[Ceiling($DOTNET_PATHS_MAX * 1.3)][$DOTNET_PATHS_MAX] = [[0, 0]], _ $sRegAsmPath = Null If Not ($iType = $DOTNET_UNLOADDLLALL) Then If Not (StringRight($sDllPath, StringLen('dll')) == 'dll') Then ; Check the correct filetype was passed. Return SetError(1, 0, False) ; Incorrect filetype. EndIf If Not FileExists($sDllPath) Then ; Check the filepath exists in @ScriptDir. Return SetError(2, 0, False) ; Filepath does not exist. EndIf EndIf If $sRegAsmPath == Null Then $sRegAsmPath = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework', 'InstallRoot') If @error Then $sRegAsmPath = '' ; Set to an empty string to acknowledge that searching for the path happened. Else Local $aFilePaths = _FileListToArray($sRegAsmPath, '*', $FLTA_FOLDERS), _ $sNETFolder = '' If Not @error Then For $i = UBound($aFilePaths) - 1 To 1 Step -1 If StringRegExp($aFilePaths[$i], '(?:[vV]4\.0\.\d+)') Then $sNETFolder = $aFilePaths[$i] ExitLoop ElseIf StringRegExp($aFilePaths[$i], '(?:[vV]2\.0\.\d+)') Then $sNETFolder = $aFilePaths[$i] ExitLoop EndIf Next EndIf $sRegAsmPath &= $sNETFolder & '\RegAsm.exe' If FileExists($sRegAsmPath) Then OnAutoItExitRegister(_DotNet_UnloadAll) ; Register when the AutoIt executable is closed. Else $sRegAsmPath = '' ; Set to an empty string to acknowledge that searching for the path happened. EndIf EndIf EndIf If $sRegAsmPath == '' Then Return SetError(3, 0, False) ; .NET Framework 2.0 or 4.0 required. EndIf Switch $iType Case $DOTNET_LOADDLL Local $iIndex = -1 For $i = $DOTNET_PATHS_MAX To $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] If $sDllPath = $aDllPaths[$i][$DOTNET_PATHS_FILEPATH] Then Return SetError(4, 0, False) ; Dll already registered. EndIf If $iIndex = -1 And $aDllPaths[$i][$DOTNET_PATHS_FILEPATH] == '' Then $iIndex = $i ExitLoop EndIf Next If $iIndex = -1 Then $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] += 1 $iIndex = $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] EndIf Local Const $iUBound = UBound($aDllPaths) If $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] >= $iUBound Then ReDim $aDllPaths[Ceiling($iUBound * 1.3)][$DOTNET_PATHS_MAX] EndIf $aDllPaths[$iIndex][$DOTNET_PATHS_FILEPATH] = $sDllPath $aDllPaths[$iIndex][$DOTNET_PATHS_GUID] = Null If $bAddAsCurrentUser Then ; Idea by funkey, with modification by guinness. Local $sTempDllPath = @TempDir & '\' & $sDllPath & '.reg' If Not (RunWait($sRegAsmPath & ' /s /codebase ' & $sDllPath & ' /regfile:"' & $sTempDllPath & '"', @ScriptDir, @SW_HIDE) = $DOTNET_REGASM_OK) Then Return SetError(5, 0, False) ; Unable to retrieve the GUID for registering as current user. EndIf Local Const $hFileOpen = FileOpen($sTempDllPath, BitOR($FO_READ, $FO_APPEND)) If $hFileOpen > -1 Then FileSetPos($hFileOpen, 0, $FILE_BEGIN) Local $sData = FileRead($hFileOpen) If @error Then $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] -= 1 ; Decrease the index due to failure. Return SetError(5, 0, False) ; Unable to retrieve the GUID for registering as current user. EndIf $sData = StringReplace($sData, 'HKEY_CLASSES_ROOT', 'HKEY_CURRENT_USER\Software\Classes') FileSetPos($hFileOpen, 0, $FILE_BEGIN) If Not FileWrite($hFileOpen, $sData) Then $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] -= 1 ; Decrease the index due to failure. Return SetError(5, 0, False) ; Unable to retrieve the GUID for registering as current user. EndIf FileClose($hFileOpen) Local $aSRE = StringRegExp($sData, '(?:\R@="{([[:xdigit:]\-]{36})}"\R)', $STR_REGEXPARRAYGLOBALMATCH) If @error Then $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] -= 1 ; Decrease the index due to failure. Return SetError(5, 0, False) ; Unable to retrieve the GUID for registering as current user. EndIf $aDllPaths[$iIndex][$DOTNET_PATHS_GUID] = $aSRE[0] ; GUID of the registry key. RunWait('reg import "' & $sTempDllPath & '"', @ScriptDir, @SW_HIDE) ; Import to current users' classes FileDelete($sTempDllPath) EndIf Else Return RunWait($sRegAsmPath & ' /codebase ' & $sDllPath, @ScriptDir, @SW_HIDE) = $DOTNET_REGASM_OK ; Register the .NET Dll. EndIf Case $DOTNET_UNLOADDLL For $i = $DOTNET_PATHS_MAX To $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] If $sDllPath = $aDllPaths[$i][$DOTNET_PATHS_FILEPATH] And Not ($aDllPaths[$i][$DOTNET_PATHS_FILEPATH] == Null) Then Return __DotNet_Unregister($sRegAsmPath, $aDllPaths[$i][$DOTNET_PATHS_FILEPATH], $aDllPaths[$iIndex][$DOTNET_PATHS_GUID]) EndIf Next Case $DOTNET_UNLOADDLLALL Local $iCount = 0 If $sDllPath == Null And $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] > 0 Then For $i = $DOTNET_PATHS_MAX To $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] If Not ($aDllPaths[$i][$DOTNET_PATHS_FILEPATH] == Null) Then $iCount += (__DotNet_Unregister($sRegAsmPath, $aDllPaths[$i][$DOTNET_PATHS_FILEPATH], $aDllPaths[$iIndex][$DOTNET_PATHS_GUID]) ? 1 : 0) EndIf Next $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] = 0 ; Reset the count. Return $iCount == $aDllPaths[$DOTNET_PATHS_INDEX][$DOTNET_PATHS_FILEPATH] EndIf EndSwitch Return True EndFunc ;==>__DotNet_Wrapper Func __DotNet_Unregister($sRegAsmPath, ByRef $sDllPath, ByRef $sGUID) Local $bReturn = RunWait($sRegAsmPath & ' /unregister ' & $sDllPath, @ScriptDir, @SW_HIDE) = $DOTNET_REGASM_OK ; Unregister the .NET Dll. If $bReturn Then If Not ($sGUID == Null) Then RegDelete('HKEY_CURRENT_USER\Software\Classes\CLSID\' & $sGUID) ; 32-bit path. RegDelete('HKEY_CLASSES_ROOT\Wow6432Node\CLSID\' & $sGUID) ; 64-bit path. $sGUID = Null ; Remove item. EndIf $sDllPath = Null ; Remove item. EndIf Return $bReturn EndFunc ;==>__DotNet_UnregisterI look forward to the comments and questions people have on this interesting subject, as well as any suggestions of improvement people might have. The ZIP file contains all related source code for both AutoIt and .NET. Dot-NET Assembly in AutoIt.zip
-
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..
-
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)
-
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
-
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
-
Hey all. I'm a little stuck starting with COM interfacing with Microsoft OneNote. The msdn doc is there : https://msdn.microsoft.com/en-us/library/office/jj680118.aspx?f=255&MSPPError=-2147217396 I found, with the OleViewer what I need to access : // Generated .IDL file (by the OLE/COM Object Viewer) // // typelib filename: 3 [ uuid(0EA692EE-BB50-4E3C-AEF0-356D91732725), version(1.1), helpstring("Microsoft OneNote 15.0 Object Library"), custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 134218339), custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 2147483647), custom(DE77BA65-517C-11D1-A2DA-0000F8773CE9, Created by MIDL version 8.00.0611 at Mon Jan 18 19:14:07 2038 ), custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Microsoft.Office.Interop.OneNote.dll) ] library OneNote { // TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046} importlib("stdole2.tlb"); // Forward declare all types defined in this typelib interface IQuickFilingDialog; interface IQuickFilingDialogCallback; interface IApplication; interface Windows; interface Window; dispinterface IOneNoteEvents; typedef [uuid(552E0E02-B287-4EC6-9CC0-4BA019EE5EA1)] enum { hsSelf = 0, hsChildren = 1, hsNotebooks = 2, hsSections = 3, hsPages = 4 } HierarchyScope; typedef [uuid(41C8F6EA-0AF0-4A4F-99E9-5EB01EBFC9A3)] enum { heNone = 0, heNotebooks = 1, heSectionGroups = 2, heSections = 4, hePages = 8 } HierarchyElement; typedef [uuid(4DB67B4F-CC7D-45B5-88FE-569AE5798FF2)] enum { rrtNone = 0, rrtFiling = 1, rrtSearch = 2, rrtLinks = 3 } RecentResultType; typedef [uuid(B5EB9D34-5278-4D8A-AE1F-2F88EA56BBCE)] enum { cftNone = 0, cftNotebook = 1, cftFolder = 2, cftSection = 3 } CreateFileType; typedef [uuid(D6E78E55-7EE7-4A31-BF3E-B01E819599BA)] enum { piBasic = 0, piBinaryData = 1, piSelection = 2, piFileType = 4, piBinaryDataSelection = 3, piBinaryDataFileType = 5, piSelectionFileType = 6, piAll = 7 } PageInfo; typedef [uuid(D6166973-3665-4EDB-94B0-77C65C34B51C)] enum { pfOneNote = 0, pfOneNotePackage = 1, pfMHTML = 2, pfPDF = 3, pfXPS = 4, pfWord = 5, pfEMF = 6, pfHTML = 7, pfOneNote2007 = 8 } PublishFormat; typedef [uuid(E195F3E3-8EC3-4A67-81FE-DDBEC2B42D3F)] enum { slBackUpFolder = 0, slUnfiledNotesSection = 1, slDefaultNotebookFolder = 2 } SpecialLocation; typedef [uuid(452D048E-7F61-4258-94B9-A39E19C290DA)] enum { flEMail = 0, flContacts = 1, flTasks = 2, flMeetings = 3, flWebContent = 4, flPrintOuts = 5 } FilingLocation; typedef [uuid(82FC5A95-FEB7-4242-95E1-369C5DFE3F49)] enum { fltNamedSectionNewPage = 0, fltCurrentSectionNewPage = 1, fltCurrentPage = 2, fltNamedPage = 4 } FilingLocationType; typedef [uuid(226CC8E6-1ED0-4770-A7F1-A80BB4DDF07B)] enum { npsDefault = 0, npsBlankPageWithTitle = 1, npsBlankPageNoTitle = 2 } NewPageStyle; typedef [uuid(B67BC7E1-91B9-4F50-8471-77C76F8D63D6)] enum { dlDefault = 0xffffffff, dlNone = 0, dlLeft = 1, dlRight = 2, dlTop = 3, dlBottom = 4 } DockLocation; typedef [uuid(68555133-B62F-4490-9D66-9E9BFC68F6C6)] enum { xs2007 = 0, xs2010 = 1, xs2013 = 2, xsCurrent = 2 } XMLSchema; typedef [uuid(1ECC88B3-6D2B-4EDD-8DD5-BB11E5D34C09)] enum { tcsExpanded = 0, tcsCollapsed = 1 } TreeCollapsedStateType; typedef [uuid(13F18B04-E76F-42E0-97E6-8B6ABF38B484)] enum { nfoLocal = 1, nfoNetwork = 2, nfoWeb = 4, nfoNoWacUrl = 8 } NotebookFilterOutType; [ odl, uuid(1D12BD3F-89B6-4077-AA2C-C9DC2BCA42F9), helpstring("IQuickFilingUI Interface"), dual, oleautomation ] interface IQuickFilingDialog : IDispatch { [id(00000000), propget] HRESULT Title([out, retval] BSTR* bstrTitle); [id(00000000), propput] HRESULT Title([in] BSTR bstrTitle); [id(0x00000001), propget] HRESULT Description([out, retval] BSTR* bstrDescription); [id(0x00000001), propput] HRESULT Description([in] BSTR bstrDescription); [id(0x00000002), propget] HRESULT CheckboxText([out, retval] BSTR* bstrText); [id(0x00000002), propput] HRESULT CheckboxText([in] BSTR bstrText); [id(0x00000003), propget] HRESULT CheckboxState([out, retval] VARIANT_BOOL* pfChecked); [id(0x00000003), propput] HRESULT CheckboxState([in] VARIANT_BOOL pfChecked); [id(0x00000004), propget] HRESULT WindowHandle([out, retval] uint64* pHWNDWindow); [id(0x00000005), propget] HRESULT TreeDepth([out, retval] HierarchyElement* pTreeDepth); [id(0x00000005), propput] HRESULT TreeDepth([in] HierarchyElement pTreeDepth); [id(0x00000006), propget] HRESULT ParentWindowHandle([out, retval] uint64* pHWNDParentWindow); [id(0x00000006), propput] HRESULT ParentWindowHandle([in] uint64 pHWNDParentWindow); [id(0x00000007), propget] HRESULT Position([out, retval] tagPOINT* pPoint); [id(0x00000007), propput] HRESULT Position([in] tagPOINT pPoint); [id(0x00000008)] HRESULT SetRecentResults( [in] RecentResultType recentResults, [in] VARIANT_BOOL fShowCurrentSection, [in] VARIANT_BOOL fShowCurrentPage, [in] VARIANT_BOOL fShowUnfiledNotes); [id(0x0000000a)] HRESULT AddButton( [in] BSTR bstrText, [in] HierarchyElement allowedElements, [in] HierarchyElement allowedReadOnlyElements, [in] VARIANT_BOOL fDefault); [id(0x0000000b)] HRESULT Run([in] IQuickFilingDialogCallback* piCallback); [id(0x0000000c), propget] HRESULT SelectedItem([out, retval] BSTR* pbstrSelectedNodeID); [id(0x0000000d), propget] HRESULT PressedButton([out, retval] unsigned long* pButtonIndex); [id(0x0000000e), propput] HRESULT TreeCollapsedState([in] TreeCollapsedStateType rhs); [id(0x0000000f), propput] HRESULT NotebookFilterOut([in] NotebookFilterOutType rhs); [id(0x00000010)] HRESULT ShowCreateNewNotebook(); [id(0x00000011)] HRESULT AddInitialEditor(BSTR initialEditor); [id(0x00000012)] HRESULT ClearInitialEditors(); [id(0x00000013)] HRESULT ShowSharingHyperlink(); }; typedef struct tagtagPOINT { long x; long y; } tagPOINT; [ odl, uuid(627EA7B4-95B5-4980-84C1-9D20DA4460B1), helpstring("IQuickFilingDialogCallback Interface"), dual, oleautomation ] interface IQuickFilingDialogCallback : IDispatch { [id(0x60020000)] HRESULT OnDialogClosed([in] IQuickFilingDialog* dialog); }; [ odl, uuid(452AC71A-B655-4967-A208-A4CC39DD7949), helpstring("IApplication Interface"), dual, oleautomation ] interface IApplication : IDispatch { [id(0x60020000)] HRESULT GetHierarchy( [in] BSTR bstrStartNodeID, [in] HierarchyScope hsScope, [out] BSTR* pbstrHierarchyXmlOut, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020001)] HRESULT UpdateHierarchy( [in] BSTR bstrChangesXmlIn, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020002)] HRESULT OpenHierarchy( [in] BSTR bstrPath, [in] BSTR bstrRelativeToObjectID, [out] BSTR* pbstrObjectID, [in, optional, defaultvalue(0)] CreateFileType cftIfNotExist); [id(0x60020003)] HRESULT DeleteHierarchy( [in] BSTR bstrObjectID, [in, optional, defaultvalue(00:00:00)] DATE dateExpectedLastModified, [in, optional, defaultvalue(0)] VARIANT_BOOL deletePermanently); [id(0x60020004)] HRESULT CreateNewPage( [in] BSTR bstrSectionID, [out] BSTR* pbstrPageID, [in, optional, defaultvalue(0)] NewPageStyle npsNewPageStyle); [id(0x60020005)] HRESULT CloseNotebook( [in] BSTR bstrNotebookID, [in, optional, defaultvalue(0)] VARIANT_BOOL force); [id(0x60020006)] HRESULT GetHierarchyParent( [in] BSTR bstrObjectID, [out] BSTR* pbstrParentID); [id(0x60020007)] HRESULT GetPageContent( [in] BSTR bstrPageID, [out] BSTR* pbstrPageXmlOut, [in, optional, defaultvalue(0)] PageInfo pageInfoToExport, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020008)] HRESULT UpdatePageContent( [in] BSTR bstrPageChangesXmlIn, [in, optional, defaultvalue(00:00:00)] DATE dateExpectedLastModified, [in, optional, defaultvalue(2)] XMLSchema xsSchema, [in, optional, defaultvalue(0)] VARIANT_BOOL force); [id(0x60020009)] HRESULT GetBinaryPageContent( [in] BSTR bstrPageID, [in] BSTR bstrCallbackID, [out] BSTR* pbstrBinaryObjectB64Out); [id(0x6002000a)] HRESULT DeletePageContent( [in] BSTR bstrPageID, [in] BSTR bstrObjectID, [in, optional, defaultvalue(00:00:00)] DATE dateExpectedLastModified, [in, optional, defaultvalue(0)] VARIANT_BOOL force); [id(0x6002000b)] HRESULT NavigateTo( [in] BSTR bstrHierarchyObjectID, [in, optional, defaultvalue("")] BSTR bstrObjectID, [in, optional, defaultvalue(0)] VARIANT_BOOL fNewWindow); [id(0x6002000c)] HRESULT NavigateToUrl( [in] BSTR bstrUrl, [in, optional, defaultvalue(0)] VARIANT_BOOL fNewWindow); [id(0x6002000d)] HRESULT Publish( [in] BSTR bstrHierarchyID, [in] BSTR bstrTargetFilePath, [in, optional, defaultvalue(0)] PublishFormat pfPublishFormat, [in, optional, defaultvalue("")] BSTR bstrCLSIDofExporter); [id(0x6002000e)] HRESULT OpenPackage( [in] BSTR bstrPathPackage, [in] BSTR bstrPathDest, [out] BSTR* pbstrPathOut); [id(0x6002000f)] HRESULT GetHyperlinkToObject( [in] BSTR bstrHierarchyID, [in] BSTR bstrPageContentObjectID, [out] BSTR* pbstrHyperlinkOut); [id(0x60020010)] HRESULT FindPages( [in] BSTR bstrStartNodeID, [in] BSTR bstrSearchString, [out] BSTR* pbstrHierarchyXmlOut, [in, optional, defaultvalue(0)] VARIANT_BOOL fIncludeUnindexedPages, [in, optional, defaultvalue(0)] VARIANT_BOOL fDisplay, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020011)] HRESULT FindMeta( [in] BSTR bstrStartNodeID, [in] BSTR bstrSearchStringName, [out] BSTR* pbstrHierarchyXmlOut, [in, optional, defaultvalue(0)] VARIANT_BOOL fIncludeUnindexedPages, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020012)] HRESULT GetSpecialLocation( [in] SpecialLocation slToGet, [out] BSTR* pbstrSpecialLocationPath); [id(0x60020013)] HRESULT MergeFiles( [in] BSTR bstrBaseFile, [in] BSTR bstrClientFile, [in] BSTR bstrServerFile, [in] BSTR bstrTargetFile); [id(0x60020014)] HRESULT QuickFiling([out, retval] IQuickFilingDialog** ppiDialog); [id(0x60020015)] HRESULT SyncHierarchy([in] BSTR bstrHierarchyID); [id(0x60020016)] HRESULT SetFilingLocation( [in] FilingLocation flToSet, [in] FilingLocationType fltToSet, [in] BSTR bstrFilingSectionID); [id(0x00000064), propget] HRESULT Windows([out, retval] Windows** ppONWindows); [id(0x00000066), propget, hidden] HRESULT Dummy1([out, retval] VARIANT_BOOL* pBool); [id(0x60020019)] HRESULT MergeSections( [in] BSTR bstrSectionSourceId, [in] BSTR bstrSectionDestinationId); [id(0x00000068), propget] HRESULT COMAddIns([out, retval] IDispatch** ppiComAddins); [id(0x00000069), propget] HRESULT LanguageSettings([out, retval] IDispatch** ppiLanguageSettings); [id(0x6002001c)] HRESULT GetWebHyperlinkToObject( [in] BSTR bstrHierarchyID, [in] BSTR bstrPageContentObjectID, [out] BSTR* pbstrHyperlinkOut); }; [ odl, uuid(6D4B9C3E-CC05-493F-85E2-43D1006DF96A), helpstring("List of our Windows Interface"), dual, oleautomation ] interface Windows : IDispatch { [id(00000000), propget] HRESULT Item( [in] unsigned long Index, [out, retval] Window** Item); [id(0x00000001), propget] HRESULT Count([out, retval] unsigned long* Count); [id(0xfffffffc), propget] HRESULT _NewEnum([out, retval] IUnknown** _NewEnum); [id(0x00000003), propget] HRESULT CurrentWindow([out, retval] Window** ppCurrentWindow); }; [ odl, uuid(8E8304B8-CBD1-44F8-B0E8-89C625B2002E), helpstring("Window Interface"), dual, oleautomation ] interface Window : IDispatch { [id(00000000), propget] HRESULT WindowHandle([out, retval] uint64* pHWNDWindow); [id(0x00000001), propget] HRESULT CurrentPageId([out, retval] BSTR* pbstrPageObjectId); [id(0x00000002), propget] HRESULT CurrentSectionId([out, retval] BSTR* pbstrSectionObjectId); [id(0x00000003), propget] HRESULT CurrentSectionGroupId([out, retval] BSTR* pbstrSectionObjectId); [id(0x00000004), propget] HRESULT CurrentNotebookId([out, retval] BSTR* pbstrNotebookObjectId); [id(0x00000009)] HRESULT NavigateTo( [in] BSTR bstrHierarchyObjectID, [in, optional, defaultvalue("0")] BSTR bstrObjectID); [id(0x0000000a), propget] HRESULT FullPageView([out, retval] VARIANT_BOOL* pIsFullPageView); [id(0x0000000a), propput] HRESULT FullPageView(VARIANT_BOOL pIsFullPageView); [id(0x0000000b), propget] HRESULT Active([out, retval] VARIANT_BOOL* pIsActive); [id(0x0000000b), propput] HRESULT Active(VARIANT_BOOL pIsActive); [id(0x0000000d), propget] HRESULT DockedLocation([out, retval] DockLocation* pDockLocation); [id(0x0000000d), propput] HRESULT DockedLocation(DockLocation pDockLocation); [id(0x0000000e), propget] HRESULT Application([out, retval] IApplication** ppiApp); [id(0x0000000f), propget] HRESULT SideNote([out, retval] VARIANT_BOOL* pIsSideNote); [id(0x00000010)] HRESULT NavigateToUrl([in] BSTR bstrUrl); [id(0x00000011)] HRESULT SetDockedLocation( [in] DockLocation DockLocation, [in] tagPOINT ptMonitor); }; [ uuid(E2E1511D-502D-4BD0-8B3A-8A89A05CDCAE), helpstring("IOneNoteEvents Interface"), nonextensible ] dispinterface IOneNoteEvents { properties: methods: [id(0x00000001)] void OnNavigate(); [id(0x00000002)] void OnHierarchyChange([in] BSTR bstrActivePageID); }; [ uuid(D7FAC39E-7FF1-49AA-98CF-A1DDD316337E), version(1.0), helpstring("Application Class") ] coclass Application { [default] interface IApplication; [default, source] dispinterface IOneNoteEvents; }; typedef [uuid(D3F5A756-4BAC-4D3D-9BAF-90935121AAA6)] enum { hrMalformedXML = 0x80042000, hrInvalidXML = 0x80042001, hrCreatingSection = 0x80042002, hrOpeningSection = 0x80042003, hrSectionDoesNotExist = 0x80042004, hrPageDoesNotExist = 0x80042005, hrFileDoesNotExist = 0x80042006, hrInsertingImage = 0x80042007, hrInsertingInk = 0x80042008, hrInsertingHtml = 0x80042009, hrNavigatingToPage = 0x8004200a, hrSectionReadOnly = 0x8004200b, hrPageReadOnly = 0x8004200c, hrInsertingOutlineText = 0x8004200d, hrPageObjectDoesNotExist = 0x8004200e, hrBinaryObjectDoesNotExist = 0x8004200f, hrLastModifiedDateDidNotMatch = 0x80042010, hrGroupDoesNotExist = 0x80042011, hrPageDoesNotExistInGroup = 0x80042012, hrNoActiveSelection = 0x80042013, hrObjectDoesNotExist = 0x80042014, hrNotebookDoesNotExist = 0x80042015, hrInsertingFile = 0x80042016, hrInvalidName = 0x80042017, hrFolderDoesNotExist = 0x80042018, hrInvalidQuery = 0x80042019, hrFileAlreadyExists = 0x8004201a, hrSectionEncryptedAndLocked = 0x8004201b, hrDisabledByPolicy = 0x8004201c, hrNotYetSynchronized = 0x8004201d, hrLegacySection = 0x8004201e, hrMergeFailed = 0x8004201f, hrInvalidXMLSchema = 0x80042020, hrFutureContentLoss = 0x80042022, hrTimeOut = 0x80042023, hrRecordingInProgress = 0x80042024, hrUnknownLinkedNoteState = 0x80042025, hrNoShortNameForLinkedNote = 0x80042026, hrNoFriendlyNameForLinkedNote = 0x80042027, hrInvalidLinkedNoteUri = 0x80042028, hrInvalidLinkedNoteThumbnail = 0x80042029, hrImportLNTThumbnailFailed = 0x8004202a, hrUnreadDisabledForNotebook = 0x8004202b, hrInvalidSelection = 0x8004202c, hrConvertFailed = 0x8004202d, hrRecycleBinEditFailed = 0x8004202e, hrAppInModalUI = 0x80042030 } Error; [ uuid(DC67E480-C3CB-49F8-8232-60B0C2056C8E), version(1.0), helpstring("Application2 Class") ] coclass Application2 { [default] interface IApplication; [default, source] dispinterface IOneNoteEvents; }; }; So far, I didn't manage to be able to interact with it : There is my code (based on same issue someone had in 2011 #AutoIt3Wrapper_UseX64=n #include <Array.au3> #include "AutoItObject\AutoItObject.au3" ;=============================================================================== ;interface "OneNoteIApplication" Global Const $sCLSID_OneNoteApplication = "{0039FFEC-A022-4232-8274-6B34787BFC27}" Global Const $sIID_IOneNoteApplication = "{2DA16203-3F58-404F-839D-E4CDE7DD0DED}" ; Definition Global $dtagIOneNoteWindows = $dtagIDispatch Global $dtagIOneNoteApplication = $dtagIDispatch & _ "GetHierarchy hresult(bstr;dword;bstr*);" & _ "UpdateHierarchy hresult(bstr);" & _ "OpenHierarchy hresult(bstr;bstr;bstr*;dword);" & _ "DeleteHierarchy hresult(bstr;double);" & _ "CreateNewPage hresult(bstr;bstr*;dword);" & _ "CloseNotebook hresult(bstr);" & _ "GetHierarchyParent hresult(bstr;bstr*);" & _ "GetPageContent hresult(bstr;bstr*;dword);" & _ "UpdatePageContent hresult(bstr;double);" & _ "GetBinaryPageContent hresult(bstr;bstr;bstr*);" & _ "DeletePageContent hresult(bstr;bstr;dword);" & _ "NavigateTo hresult(bstr;bstr;bool);" & _ "Publish hresult(bstr;bstr;dword;bstr);" & _ "OpenPackage hresult(bstr;bstr;bstr*);" & _ "GetHyperlinkToObject hresult(bstr;bstr;bstr*);" & _ "FindPages hresult(bstr;bstr;bstr*;bool;bool);" & _ "FindMeta hresult(bstr;bstr;bstr*;bool);" & _ "GetSpecialLocation hresult(dword;bstr*);" ; List Global $ltagIOneNoteApplication = $ltagIDispatch & _ "GetHierarchy;" & _ "UpdateHierarchy;" & _ "OpenHierarchy;" & _ "DeleteHierarchy;" & _ "CreateNewPage;" & _ "CloseNotebook;" & _ "GetHierarchyParent;" & _ "GetPageContent;" & _ "UpdatePageContent;" & _ "GetBinaryPageContent;" & _ "DeletePageContent;" & _ "NavigateTo;" & _ "Publish;" & _ "OpenPackage;" & _ "GetHyperlinkToObject;" & _ "FindPages;" & _ "FindMeta;" & _ "GetSpecialLocation;" ;=============================================================================== _AutoItObject_StartUp() Global $objOneNote = ObjCreate("OneNote.Application") Global $pOneNote = _AutoItObject_IDispatchToPtr($objOneNote) _AutoItObject_IUnknownAddRef($objOneNote) Global $oOneNote = _AutoItObject_WrapperCreate($pOneNote, $dtagIOneNoteWindows) ;~ Global $oOnenote = ObjCreateInterface($sCLSID_OneNoteApplication,$sIID_IOneNoteApplication,$dtagIOneNoteApplication,True) ;~ ; Check if object is created: If Not IsObj($oOneNote) Then MsgBox(48, "Error", "Object not created. Something is wrong.") Exit EndIf $aCall = $oOneNote.GetTypeInfoCount(0) $iTypeInfoCount = $aCall[1] ConsoleWrite("$iTypeInfoCount = " & $iTypeInfoCount & @CRLF) $Window = $oOneNote.Windows ;~ ConsoleWrite("Test = " & $Window.CurrentPageId & @CRLF) $str = "onenote:///R:\Software\OneNote%20EOD\EOD%20Scrum\Sprint%20136.one#section-id={D2EB7AEB-362B-490A-9CE0-0B9316DF0DAD}&end" $hBSTR = DllCall("oleaut32.dll", "ptr", "SysAllocString", "wstr", $str) $aCall = $oOnenote.NavigateToUrl($hBSTR[0]) Can someone help me to go in the good direction? I'm a little lost with what's needed, (CLSID and IID whereas I have only a UUID and can't find a good starting doc online) Thanks a lot,
-
Hello, I found a VB snippet which I would love to use in AutoIt strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Process") For Each objItem in colItems Wscript.Echo objItem.Name Wscript.Echo objItem.CommandLine Next Despite my best efforts, I am not able to understand a thing from that piece of code . All I know is that it outputs the Name and Commandline of all the processes currently running (Let's see if I am right). Can anyone help me with convert this into AutoIt? Thanks in Advance!
-
Skype UDF v1.2 Introduction :Skype4COM represents the Skype API as objects, with :methodspropertieseventscollectionscachingSkype4COM provides an ActiveX interface to the Skype API. Develop for Skype in a familiar programming environment, such as Visual Studio or Delphi, using preferred scripting languages such as VBScript, PHP, or Javascript. Requirements : Skype 3.0+ must be installedWindows 2000, XP+ Update : Version 1.2 Fixed _Skype_ProfileGetHandle function Version 1.1 Fixed _Skype_ChatGetBookmarked function Added missing _Skype_ChatGetTopic function Version 1.0 Fixed _Skype_ChatGetAll function Version 0.9 Fixed Mute value returned by the _Skype_OnEventMute callback function Version 0.8 Error ObjEvent is set if none already set Version 0.7 Changed _Skype_GetChatActive to _Skype_GetChatAllActive Version 0.6 Added _Skype_GetCache Added _Skype_SetCache Changed Skype_Error function Minor bugs fixed Version 0.5 Fixed _Skype_ChatCreate Version 0.4 Fixed _Skype_ChatGetMessages Fixed "Skype - SciTE.au3" script Version 0.3 Minor changes Updated Skype in AutoIt example Version 0.2 Fixed _Skype_ChatAddMembers Various bugs fixed _Functions list : (346) Example GUI : Notes : Skype's access control must be accepted manually :After running the example script, click on the "Allow access" button of SkypeThis version is NOT complete If you are running on a 64 bits OS, add this line to your script : #AutoIt3Wrapper_UseX64=n Attachments :Pack (UDF + ExampleGUI)Version 1.2 : Skype-UDF_1.0.0.2.zip Examples : (put them into the "Example folder")-Answers to incomming calls even if you are already in a call : Auto Answer.au3-Shows how to use the OnMute event : Mute Event.au3 Happy coding
-
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
-
Hi all. I am trying to do 2 things but i cannot seem to get any traction on how to read/implement this idea. Premise: PowerPoint file in C\temp\presentation.pptx that contains on the first slide 2 entries as "<one>" and "<two>" which need to be replaced with "user1" and "user2", then a silent Outlook send mail containing the file with a predefined body and subject. I narrowed it down to COM objects as the Office does not like intrusive open AutoIt functions. I installed OLE/COM Object Viewer to understand how to create the commands but i am still stuck. So far i am trying to user water's code but i suck COM object i was originally trying to modify Dim $oPPT, $oPres $oPPT = ObjCreate("PowerPoint.Application") $oPPT.Visible = True $oPres = $oPPT.Presentations.Read Water's code below (0.1% modified) #include <File.au3> #include "PowerPoint.au3" #include <misc.au3> Global $sFile = "C:\temp\presentation.pptx" Global $sString2Search = "<username>", $sString2Replace = "Password", $iReplaceOnce = 1, $sFullLogFile = "C:\temp\pptxlog.txt" _ProcessPpt($sFile) Func _ProcessPpt($sFile) $oApp = _PPT_PowerPointApp() Local $bChange = False Local $oInterface = $oApp.Presentations Local $oPresentation = $oInterface.Open($sFile, False, False, False) If @error Then _FileWriteLog($sFullLogFile, "E Error " & @error & " opening File " & $sFile) Return SetError(1, 0, 0) EndIf ;it does not even open my file and from here not sure how to read the text and replace it EndFunc ;==>_ProcessPpt
-
I am having a very unique, but repeatable problem with ImageMagick COM interface. Here are the applicable lines of code: $oIM=ObjCreate("ImageMagickObject.MagickImage.1") and then later on... $oIM.Convert(String($arFileList[$nFileIndex])&'[0]',"-alpha", "remove",@TempDir&"\temp.jpg") the array points to a pdf file with the "convert" command converting the first page of the pdf to a jpg with any alpha layer removed. Every time, without fail, the first time I run the script on a freshly booted machine it crashes on the $oIM.Convert command. It does this if it isn't compiled and says there is an error executing the command on the object. If compiled, i get an error that autoit has stopped responding. Anytime I run the script, compiled or not, after this initial crash everything works perfectly fine. I am totally at a loss as to why this is occurring and how to correct it.
- 3 replies
-
- imagemagick
- com
-
(and 1 more)
Tagged with:
-
Is there a way to read data directly from the Windows Component Object Model (COM) interface? I am trying to make a really simple disk space reporter tool for accounts on an Active Directory domain, to read the disk quota limit for the logged on user's home directory, and report how much disk space they are currently using. , MSDN: IDiskQuotaUser interface https://msdn.microsoft.com/en-us/library/windows/desktop/aa365033(v=vs.85).aspx GetQuotaLimit GetQuotaUsed
-
I wrote this very simple functions to parse command line arguments. It can get: Simple key/value Example. The following code: #include "cmdline.au3" MsgBox(0, _CmdLine_Get('color')) Will return "white" if you run the script in one of these ways (quotes are optional but mandatory if you're going to use spaces): script.exe -color "white" script.exe --color white script.exe /color white Existence Example. The following code: #include "cmdline.au3" If _CmdLine_KeyExists('givemecoffee') Then ConsoleWrite('You want coffee.') Else ConsoleWrite('You do not want coffee.') EndIf Will return "You want coffee." if you run one of these: script.exe -givemecoffee script.exe --givemecoffee script.exe /givemecoffee And the following code: #include "cmdline.au3" If _CmdLine_ValueExists('givemecoffee') Then ConsoleWrite('You want coffee.') Else ConsoleWrite('You do not want coffee.') EndIf Will return "You want coffee." if you run one of these: script.exe givemecoffee script.exe "givemecoffee" Flags Example. This script: #include "cmdline.au3" ConsoleWrite("You want: ") If _CmdLine_FlagEnabled('C') Then ConsoleWrite("coffee ") EndIf If _CmdLine_FlagEnabled('B') Then ConsoleWrite("beer ") EndIf ConsoleWrite(" and you do not want: ") If _CmdLine_FlagDisabled('V') Then ConsoleWrite("vodka ") EndIf If _CmdLine_FlagDisabled('W') Then ConsoleWrite("wine ") EndIf ConsoleWrite(" but you did not tell me if you want: ") If Not _CmdLine_FlagExists('S') Then ConsoleWrite("soda ") EndIf If Not _CmdLine_FlagExists('J') Then ConsoleWrite("juice ") EndIf Will return "You want: coffee beer and you do not want: vodka wine but you did not tell me if you want: soda juice" if you run: script.exe +CB -VW Getting argument by its index You can also read the $CmdLine (1-based index) through this function. The advantage is that if the index does not exist (the user did not specify the argument), it won't break your script. It will just return the value you specify in the second function parameter. #include "cmdline.au3" $first_argument = _CmdLine_GetValByIndex(1, False) If Not $first_argument Then ConsoleWrite("You did not specify any argument.") Else ConsoleWrite("First argument is: " & $first_argument) EndIf Just a note: The second value of _CmdLine_GetValByIndex function can be an integer value, a string, a boolean value, an array or anything you want it to return if the index does not exist in $CmdLine array. This parameter is also available in _CmdLine_Get() function, also as a second function parameter. In this case, it will return this value if the key was not found. Example: #include "cmdline.au3" $user_wants = _CmdLine_Get("iwant", "nothing") ConsoleWrite("You want " & $user_wants) So, if you run: script.exe /iwant water It will return "You want water". But if you run just: script.exe It will return "You want nothing". Please note that, as these two are the only functions in this library meant to return strings, the second parameter is not available for the other functions. By default, if you do not specify any fallback value, it returns null if the wanted value could not be found. Also, please note that this UDF can NOT parse arguments in the format (key=value). Example: script.exe key=value IT WILL NOT WORK Here is the code: #include-once #comments-start CmdLine small UDF coder: Jefrey (jefrey[at]jefrey.ml) #comments-end Func _CmdLine_Get($sKey, $mDefault = Null) For $i = 1 To $CmdLine[0] If $CmdLine[$i] = "/" & $sKey OR $CmdLine[$i] = "-" & $sKey OR $CmdLine[$i] = "--" & $sKey Then If $CmdLine[0] >= $i+1 Then Return $CmdLine[$i+1] EndIf EndIf Next Return $mDefault EndFunc Func _CmdLine_KeyExists($sKey) For $i = 1 To $CmdLine[0] If $CmdLine[$i] = "/" & $sKey OR $CmdLine[$i] = "-" & $sKey OR $CmdLine[$i] = "--" & $sKey Then Return True EndIf Next Return False EndFunc Func _CmdLine_ValueExists($sValue) For $i = 1 To $CmdLine[0] If $CmdLine[$i] = $sValue Then Return True EndIf Next Return False EndFunc Func _CmdLine_FlagEnabled($sKey) For $i = 1 To $CmdLine[0] If StringRegExp($CmdLine[$i], "\+([a-zA-Z]*)" & $sKey & "([a-zA-Z]*)") Then Return True EndIf Next Return False EndFunc Func _CmdLine_FlagDisabled($sKey) For $i = 1 To $CmdLine[0] If StringRegExp($CmdLine[$i], "\-([a-zA-Z]*)" & $sKey & "([a-zA-Z]*)") Then Return True EndIf Next Return False EndFunc Func _CmdLine_FlagExists($sKey) For $i = 1 To $CmdLine[0] If StringRegExp($CmdLine[$i], "(\+|\-)([a-zA-Z]*)" & $sKey & "([a-zA-Z]*)") Then Return True EndIf Next Return False EndFunc Func _CmdLine_GetValByIndex($iIndex, $mDefault = Null) If $CmdLine[0] >= $iIndex Then Return $CmdLine[$iIndex] Else Return $mDefault EndIf EndFunc
-
Hi All, I've coded the small script below, but it can't seem to get the instance of Windows Media player as it keeps going to @error, I've not used com objects before so any assistance would be appreciate. I already have WMP open and minimised. I retrieved "WMPlayerApp" from the AutoIT info tool, I've included a copy below. I'm using these sources: https://msdn.microsoft.com/en-us/library/dd564085.aspx https://msdn.microsoft.com/en-us/library/dd564018.aspx $oWMP = ObjGet("", "WMPlayerApp") If @error Then MsgBox(0, "Can't get WMP", "Couldn't connect to the WMP instance") Exit EndIf $wmpPlayState = $oWMP.playState MsgBox(0, "Play State", $wmpPlayState) $wmpSongName = $oWMP.currentMedia.name MsgBox(0, "Play State", $wmpSongName) I've also seen references to the below, but I want to get an existing open WMP: ObjCreate("wmplayer.OCX") and have looked at the WMP.udf but can't see how it will do either of the functions I've coded above.
-
Hi all (Especially @water) I wonder how to do this task in word from autoit. Assume that i pasted some text into word with this code. Local $oWord = ObjGet("","Word.Application") Local $wRangeObj = _Word_DocRangeSet($oWord, 0) Local $data = ClipGet() $wRangeObj.Text = $data $wRangeObj.Font.Bold = True So far so good. Now, i need to enter a new line in word and turn the Font.Bold = False. Currently, i did it with activating the word window and Send() function. But i would like to do it with the help of COM object. How can i do that ?