-
Posts
13,093 -
Joined
-
Last visited
-
Days Won
1
Reputation Activity
-
PsaltyDS got a reaction from Tony4219 in SearchReg-example
Try this:
#include <Array.au3> Global $sUninstallKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" Global $sValName = "UninstallString" ; Get array of all "UninstallString" values $aUninstallKeys = _RegSearch($sUninstallKey, $sValName, 2, True) ; 2 = Match on Value Names only, True = return array ; Create 2D array for data Global $aUninstallStrings[UBound($aUninstallKeys)][2] = [[$aUninstallKeys[0], ""]] ; Populate 2D array with value location and data For $n = 1 To $aUninstallKeys[0] $aUninstallStrings[$n][0] = $aUninstallKeys[$n] $aUninstallStrings[$n][1] = RegRead(StringTrimRight($aUninstallStrings[$n][0], StringLen($sValName)), $sValName) Next ; Display results _ArrayDisplay($aUninstallStrings)
-
PsaltyDS got a reaction from Tony4219 in SearchReg-example
Don't like the re$triction$ on the REGFIND.exe in the resource kit, so...
Tweaked to use local variables only in the function and format to taste:
$SearchKey = "HKLM\SOFTWARE\Microsoft" $SearchString = "Files" $Timer = TimerInit() $Results = _RegSearch($SearchKey, $SearchString) $Timer = TimerDiff($Timer) / 1000 MsgBox(64, "Results", "Results of search for: " & $SearchString & @CRLF & _ "Time taken (in seconds): " & $Timer & @CRLF & _ "---------------------------------------" & @CRLF & _ $Results) ;***************************************************** ; Function _RegSearch($startkey, $searchval) ; Performs a recursive search of the registry ; Starting at $sStartKey, looking for $sSearchVal ; Returns a string containing a list of key names and values. ; If the key or value name contain the $sSearchVal, it is listed as a reg path: ; i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion ; If the data contains the $sSearchVal, the format is path = data: ; i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\CommonFilesDir = C:\Program Files\Common Files ;***************************************************** Func _RegSearch($startkey, $searchval) Local $val, $i, $key, $z, $found = "" $i = 1 While 1 $key = RegEnumKey($startkey, $i) If @error <> 0 Then ExitLoop $z = 1 While 1 $val = RegEnumVal($startkey & "\" & $key, $z) If @error <> 0 Then ExitLoop If StringInStr($val, $searchval) Then $found = $found & $startkey & "\" & $key & "\" & $val & @LF EndIf $readval = RegRead($startkey & "\" & $key, $val) If $readval <> "" And StringInStr($readval, $searchval) Then $found = $found & $startkey & "\" & $key & "\" & $val & " = " & $readval & @LF EndIf $z = $z + 1 WEnd _RegSearch($startkey & "\" & $key, $searchval) $i = $i + 1 WEnd Return $found EndFunc ;==>SearchReg
But surely there's a COM object provider for this... somewhere...???
P.S. The sample search in the demo above took about 25sec on my XP box.
-
PsaltyDS got a reaction from jaberwacky in Help please with TCP/IP script to control Onkyo receiver
Hex is a method to display data (like in the SciTE console pane), not encode it for transmission. The TCPSend() is given either string or binary data. What is called for and what did you pass? Since you haven't shared any code or a complete description of your method, we can't help much.
-
PsaltyDS got a reaction from jaberwacky in Help please with TCP/IP script to control Onkyo receiver
Cool!
I have an Onkyo home theater receiver, but I don't think it's an Ethernet enabled one. Interesting option.
-
PsaltyDS got a reaction from jaberwacky in Help please with TCP/IP script to control Onkyo receiver
You might get some help from this post: AVForums: Onkyo (TX-NR 1007) Webinterface Programming
The message formatting in VB.net looks like this:
Dim sendBytes(command.Length + 18) As Char sendBytes(0) = "I" sendBytes(1) = "S" sendBytes(2) = "C" sendBytes(3) = "P" sendBytes(4) = Chr(0) sendBytes(5) = Chr(0) sendBytes(6) = Chr(0) sendBytes(7) = Chr(16) sendBytes(8) = Chr(0) sendBytes(9) = Chr(0) sendBytes(10) = Chr(0) sendBytes(11) = Chr(command.Length + 3) sendBytes(12) = Chr(1) sendBytes(13) = Chr(0) sendBytes(14) = Chr(0) sendBytes(15) = Chr(0) sendBytes(16) = "!" 'Chr(33) sendBytes(17) = "1" 'Chr(49) ' 1 is for the Receiver Dim i As Int32 For i = 0 To (command.Length - 1) sendBytes(18 + i) = command.Chars(i) Next sendBytes(command.Length + 18) = Chr(13)Note there are null characters in the stream. So you want to convert it all to a binary before transmission (null terminates a string in AutoIt).
My interpretation in AutoIt:
; ISCP 00000010 00000007 01000000 !1PWR01 0D Global $binISCP_Header = StringToBinary("ISCP") Global $binISCP_HeaderSize = Binary("0x00000010") ; Header size = 16 Global $binISCP_DataSize = Binary("0x00000007") ; Data size (command length) = 7 chars Global $binISCP_Version = Binary("0x01000000") ; Version 1.0.0.0 Global $binISCP_Data = StringToBinary("!1PWR01") ; Command = !1PWR01 Global $binISCP_End = Binary("0x0D") ; @CR Global $binISCP_Message = $binISCP_Header & _ $binISCP_HeaderSize & _ $binISCP_DataSize & _ $binISCP_Version & _ $binISCP_Data & _ $binISCP_End ; ... TCPSend($ConnectedSocket, $binISCP_Message) ; Send message over connected socket
Not tested, of course.
Changing the end of my code to this:
; TCPSend($ConnectedSocket, $binISCP_Message) ; Send message over connected socket ConsoleWrite("$binISCP_Message = " & $binISCP_Message & @LF)I get this out:
$binISCP_Message = 0x49534350000000100000000701000000213150575230310D
-
PsaltyDS got a reaction from sonls2 in How to change a value in an Array
$C36 = "Wherever you got it from" $array[0][1] = $C36
-
PsaltyDS got a reaction from pixelsearch in How to catch event scrolling in _GUICtrlRichEdit
Oh, all right then, a guy can be wrong already!
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> Global $sText = "", $hGui, $hRichEdit For $n = 2 To 100 $sText &= $n & " - This is a single long line intended to cause a hoizontal scroll bar to appear in my RichEdit control." & @CRLF Next $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, $sText, 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL)) _GUICtrlRichEdit_SetEventMask($hRichEdit, BitOR($ENM_SCROLL, $ENM_SCROLLEVENTS)) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam) ; $tagEN_MSGFILTER = hwnd hWndFrom;uint_ptr IDFrom;INT Code;uint msg;wparam wParam;lparam lParam #forceref $iMsg, $iWparam Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu $tNMHDR = DllStructCreate($tagNMHDR, $iLparam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hRichEdit Select Case $iCode = $EN_MSGFILTER $tMsgFilter = DllStructCreate($tagEN_MSGFILTER, $iLparam) $aPos = _GUICtrlRichEdit_GetScrollPos($hRichEdit) Switch DllStructGetData($tMsgFilter, "msg") Case 276 ConsoleWrite("Debug: Horz Scroll: x = " & $aPos[0] & "; y = " & $aPos[1] & @LF) Case 277 ConsoleWrite("Debug: Vert Scroll: x = " & $aPos[0] & "; y = " & $aPos[1] & @LF) EndSwitch EndSelect EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
-
PsaltyDS got a reaction from ThomasBennett in Using "And" and "Or" statement help?
Basic logic error, if it matches one, it doesn't match the other.
You can select multiple matches in a single Case:
$State = "Test1" Switch $State Case "Test1", "Test2" MsgBox(1024,$State,"var is Test1 or Test2") Case Else MsgBox(1024,$State,"var is something other than Test1 or Test2") EndIf
Edit:
Or just change your Boolean operation to And:
If ($State <> "Test1") And ($State <> "Test2") Then The parens are not required, but good practice for readability.
-
PsaltyDS got a reaction from mistersquirrle in _ProcessListProperties()
The _ProcessListProperties() function has been floating around General Help and Support long enough. This is it's new home.
This function lists several properties of all processes (default), selected processes by name, or a single process by PID.
===> Important bug note: The SwbemRefresher object has a Microsoft bug that causes a memory leak when called repeatedly. Until a fix is found from Microsoft,
don't use _ProcessListProperties() in a tight loop. <===
Change Log: 05/05/2008 -- v1.0.0 -- First version placed in Example Scripts 05/07/2008 -- v1.0.1 -- Added the calling command line at [n][9] 06/10/2008 -- v2.0.0 -- Removed use of ProcessList() so remote access could work 06/12/2008 -- v2.0.1 -- Added geeky RegExp for WMI date conversion by weaponx 07/02/2008 -- v2.0.2 -- Fixed find by PID or Name, which was broken by removing ProcessList() usage 09/17/2008 -- v2.0.3 -- Added Debug (SeDebugPrivilege) to WMI call to retrieve fuller results 12/15/2008 -- v2.0.3 -- No change to function, cleaned up demo and added COM error handler to it12/01/2009 -- v2.0.4 -- Fixed check for null $Process so '0' could be used (System Idle Process)
Information is returned in a 2D array similar to the native ProcessList(), in fact the UDF uses ProcessList() internally.
This is the structure of the array:
[0][0] - Number of processes listed (can be 0 if no matches found)
[1][0] - 1st process name
[1][1] - 1st process PID
[1][2] - 1st process Parent PID
[1][3] - 1st process owner
[1][4] - 1st process priority (0 = low, 31 = high)
[1][5] - 1st process executable path
[1][6] - 1st process CPU usage
[1][7] - 1st process memory usage
[1][8] - 1st process creation date/time = "MM/DD/YYY hh:mm:ss"
[1][9] - 1st process command line string
...
[n][0] thru [n][9] - last process properties
Here is the function, with a running demo script:
#include <Array.au3>; Only for _ArrayDisplay() ; Install a custom error handler Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"), $f_COMError = False ; Globals Global $avRET, $iPID ; Demonstrate listing all processes $avRET = _ProcessListProperties() _ArrayDisplay($avRET, "All Processes") ; Demonstrate listing by name $avRET = _ProcessListProperties("svchost.exe") _ArrayDisplay($avRET, "By name: 'svchost.exe'") ; Demonstrate listing by PID (integer) $iPID = ProcessExists("svchost.exe") $avRET = _ProcessListProperties($iPID) _ArrayDisplay($avRET, "By int PID: " & $iPID) ; Demonstrate listing by PID (numeric string) $iPID = String($iPID) $avRET = _ProcessListProperties($iPID) _ArrayDisplay($avRET, "By string PID: " & $iPID) ; Demonstrate not found $avRET = _ProcessListProperties("NoSuchProcess.exe") _ArrayDisplay($avRET, "Not found: 'NoSuchProcess.exe'") ; This is my custom error handler Func MyErrFunc() Local $HexNumber=hex($oMyError.number,8) Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "WinDescription is: " & $oMyError.windescription & @CRLF & _ "Source is: " & $oMyError.source & @CRLF & _ "ScriptLine is: " & $oMyError.scriptline) $f_COMError = True; something to check for when this function returns Endfunc ;=============================================================================== ; Function Name: _ProcessListProperties() ; Description: Get various properties of a process, or all processes ; Call With: _ProcessListProperties( [$Process [, $sComputer]] ) ; Parameter(s): (optional) $Process - PID or name of a process, default is "" (all) ; (optional) $sComputer - remote computer to get list from, default is local ; Requirement(s): AutoIt v3.2.4.9+ ; Return Value(s): On Success - Returns a 2D array of processes, as in ProcessList() ; with additional columns added: ; [0][0] - Number of processes listed (can be 0 if no matches found) ; [1][0] - 1st process name ; [1][1] - 1st process PID ; [1][2] - 1st process Parent PID ; [1][3] - 1st process owner ; [1][4] - 1st process priority (0 = low, 31 = high) ; [1][5] - 1st process executable path ; [1][6] - 1st process CPU usage ; [1][7] - 1st process memory usage ; [1][8] - 1st process creation date/time = "MM/DD/YYY hh:mm:ss" (hh = 00 to 23) ; [1][9] - 1st process command line string ; ... ; [n][0] thru [n][9] - last process properties ; On Failure: Returns array with [0][0] = 0 and sets @Error to non-zero (see code below) ; Author(s): PsaltyDS at http://www.autoitscript.com/forum ; Date/Version: 12/01/2009 -- v2.0.4 ; Notes: If an integer PID or string process name is provided and no match is found, ; then [0][0] = 0 and @error = 0 (not treated as an error, same as ProcessList) ; This function requires admin permissions to the target computer. ; All properties come from the Win32_Process class in WMI. ; To get time-base properties (CPU and Memory usage), a 100ms SWbemRefresher is used. ;=============================================================================== Func _ProcessListProperties($Process = "", $sComputer = ".") Local $sUserName, $sMsg, $sUserDomain, $avProcs, $dtmDate Local $avProcs[1][2] = [[0, ""]], $n = 1 ; Convert PID if passed as string If StringIsInt($Process) Then $Process = Int($Process) ; Connect to WMI and get process objects $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy, (Debug)}!\\" & $sComputer & "\root\cimv2") If IsObj($oWMI) Then ; Get collection processes from Win32_Process If $Process == "" Then ; Get all $colProcs = $oWMI.ExecQuery("select * from win32_process") ElseIf IsInt($Process) Then ; Get by PID $colProcs = $oWMI.ExecQuery("select * from win32_process where ProcessId = " & $Process) Else ; Get by Name $colProcs = $oWMI.ExecQuery("select * from win32_process where Name = '" & $Process & "'") EndIf If IsObj($colProcs) Then ; Return for no matches If $colProcs.count = 0 Then Return $avProcs ; Size the array ReDim $avProcs[$colProcs.count + 1][10] $avProcs[0][0] = UBound($avProcs) - 1 ; For each process... For $oProc In $colProcs ; [n][0] = Process name $avProcs[$n][0] = $oProc.name ; [n][1] = Process PID $avProcs[$n][1] = $oProc.ProcessId ; [n][2] = Parent PID $avProcs[$n][2] = $oProc.ParentProcessId ; [n][3] = Owner If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n][3] = $sUserDomain & "\" & $sUserName ; [n][4] = Priority $avProcs[$n][4] = $oProc.Priority ; [n][5] = Executable path $avProcs[$n][5] = $oProc.ExecutablePath ; [n][8] = Creation date/time $dtmDate = $oProc.CreationDate If $dtmDate <> "" Then ; Back referencing RegExp pattern from weaponx Local $sRegExpPatt = "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)" $dtmDate = StringRegExpReplace($dtmDate, $sRegExpPatt, "$2/$3/$1 $4:$5:$6") EndIf $avProcs[$n][8] = $dtmDate ; [n][9] = Command line string $avProcs[$n][9] = $oProc.CommandLine ; increment index $n += 1 Next Else SetError(2); Error getting process collection from WMI EndIf ; release the collection object $colProcs = 0 ; Get collection of all processes from Win32_PerfFormattedData_PerfProc_Process ; Have to use an SWbemRefresher to pull the collection, or all Perf data will be zeros Local $oRefresher = ObjCreate("WbemScripting.SWbemRefresher") $colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet $oRefresher.Refresh ; Time delay before calling refresher Local $iTime = TimerInit() Do Sleep(20) Until TimerDiff($iTime) >= 100 $oRefresher.Refresh ; Get PerfProc data For $oProc In $colProcs ; Find it in the array For $n = 1 To $avProcs[0][0] If $avProcs[$n][1] = $oProc.IDProcess Then ; [n][6] = CPU usage $avProcs[$n][6] = $oProc.PercentProcessorTime ; [n][7] = memory usage $avProcs[$n][7] = $oProc.WorkingSet ExitLoop EndIf Next Next Else SetError(1); Error connecting to WMI EndIf ; Return array Return $avProcs EndFunc ;==>_ProcessListProperties
Constructive criticism welcome.
-
PsaltyDS got a reaction from behdadsoft in How to hook or modify IE HOMEPAGE in memory?
I'm still not sure what "in memory" means in this context, but if it's simply "from a script" then: RegWrite("HKCU\SOFTWARE\Microsoft\Internet Explorer\Main", "Start Page", "REG_SZ", "http://www.autoitscript.com")
-
PsaltyDS got a reaction from MrKm in Tutorial on DllCall() & DllStructs
Even more fun!
Made this after checking out LockWorkStation because of your DLL tutorial:
Get notification when session is locked and unlocked:
Global Const $NOTIFY_FOR_THIS_SESSION = 0x0 Global Const $NOTIFY_FOR_ALL_SESSIONS = 0x1 Global Const $WM_WTSSESSION_CHANGE = 0x2B1 Global Const $WTS_CONSOLE_CONNECT = 0x1 Global Const $WTS_CONSOLE_DISCONNECT = 0x2 Global Const $WTS_REMOTE_CONNECT = 0x3 Global Const $WTS_REMOTE_DISCONNECT = 0x4 Global Const $WTS_SESSION_LOGON = 0x5 Global Const $WTS_SESSION_LOGOFF = 0x6 Global Const $WTS_SESSION_LOCK = 0x7 Global Const $WTS_SESSION_UNLOCK = 0x8 Global Const $WTS_SESSION_REMOTE_CONTROL = 0x9 Global $hGUI = GUICreate("Message Sink", 400, 600); GUI to receive notification Global $sMsg = "$hGUI = " & $hGUI & @CRLF Global $ctrlEdit = GUICtrlCreateEdit($sMsg, 10, 10, 380, 580) GUISetState() GUIRegisterMsg($WM_WTSSESSION_CHANGE, "_WM_WTSSESSION_CHANGE") DllCall("Wtsapi32.dll", "int", "WTSRegisterSessionNotification", "hwnd", $hGUI, "dword", $NOTIFY_FOR_THIS_SESSION) DllCall("Kernel32.dll", "none", "Sleep", "dword", 1000) DllCall("User32.dll", "int", "LockWorkStation") While 1 If GUIGetMsg() = -3 Then ExitLoop WEnd DllCall("Wtsapi32.dll", "int", "WTSUnRegisterSessionNotification", "hwnd", $hGUI) Func _WM_WTSSESSION_CHANGE($hWnd, $iMsgID, $wParam, $lParam) $sMsg &= @CRLF & @HOUR & ":" & @Min & ":" & @SEC & " = " Switch $wParam Case $WTS_CONSOLE_CONNECT $sMsg &= "A session was connected to the console terminal." Case $WTS_CONSOLE_DISCONNECT $sMsg &= "A session was disconnected from the console terminal." Case $WTS_REMOTE_CONNECT $sMsg &= "A session was connected to the remote terminal." Case $WTS_REMOTE_DISCONNECT $sMsg &= "A session was disconnected from the remote terminal." Case $WTS_SESSION_LOGON $sMsg &= "A user has logged on to the session." Case $WTS_SESSION_LOGOFF $sMsg &= "A user has logged off the session." Case $WTS_SESSION_LOCK $sMsg &= "A session has been locked." Case $WTS_SESSION_UNLOCK $sMsg &= "A session has been unlocked." Case $WTS_SESSION_REMOTE_CONTROL $sMsg &= "A session has changed its remote controlled status." EndSwitch $sMsg &= @CRLF & "$hWnd = " & $hWnd & @CRLF & _ "$iMsgID = 0x" & Hex($iMsgID, 8) & @CRLF & _ "$wParam = " & $wParam & @CRLF & _ "$lParam = " & $lParam & @CRLF ControlSetText($hGUI, "", $ctrlEdit, $sMsg) EndFunc
Thank you, master monoceres, for my DLL-fu grows stronger! There must be great Chi in sitting around eating cereal in your underwear!
-
PsaltyDS got a reaction from ss26 in Pass object property as a variable
Execute(), as in:
Global $oDictionary, $oMyError Global $aDictItems[3][2] = [["one","uno"], ["two","dos"], ["three","tres"]] ; Initialize a COM error handler $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Create dictionary object $oDictionary = ObjCreate("Scripting.Dictionary") ; Add key/item pairs For $n = 0 to UBound($aDictItems) - 1 ; Normal syntax: $oDictionary.ADD($aDictItems[$n][0], $aDictItems[$n][1]) $sMethod = "Add" Execute("$oDictionary." & $sMethod & "($aDictItems[$n][0], $aDictItems[$n][1])") Next ; Read items For $n = 0 to UBound($aDictItems) - 1 ; Normal syntax: $oDictionary.Item($aDictItems[$n][0]) $sMethod = "Item" $sItem = Execute("$oDictionary." & $sMethod & "($aDictItems[$n][0])") ConsoleWrite($aDictItems[$n][0] & " = " & $sItem & @LF) Next ; This is my custom defined error handler Func MyErrFunc() Local $err = $oMyError.number MsgBox(16, "Error", "COM Error: " & $err) SetError($err) ; to check for after this function returns EndFunc ;==>MyErrFunc
Edit: Forgot COM error handler.
-
PsaltyDS got a reaction from sudeepjd in Zoom IE
There is no zoom in an IE ActiveX control (embedded) instance, even when done manually. So as far as I know you're out of luck.
Exactly as with the full IE instance, XDPI and YDPI are there for read-only reference, though:
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> _IEErrorHandlerRegister () $oIE = _IECreateEmbedded () GUICreate("Embedded Web control Test", 640, 580, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360) $GUI_Button_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30) $GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30) $GUI_Button_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30) $GUI_Button_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30) GUISetState() ;Show GUI _IENavigate ($oIE, "http://www.autoitscript.com") $oScreen = $oIE.document.parentwindow.screen $iXDPI = $oScreen.deviceXDPI $iYDPI = $oScreen.deviceYDPI $iLogicalXDPI = $oScreen.logicalXDPI $iLogicalYDPI = $oScreen.logicalYDPI $iXZoom = $iXDPI / $iLogicalXDPI * 100 $iYZoom = $iYDPI / $iLogicalYDPI * 100 ConsoleWrite("$iXDPI = " & $iXDPI & "; $iYDPI = " & $iYDPI & @LF) ConsoleWrite("$iLogicalXDPI = " & $iLogicalXDPI & "; $iLogicalYDPI = " & $iLogicalYDPI & @LF) ConsoleWrite("Horizontal Zoom = %" & $iXZoom & "; Vertical Zoom = %" & $iYZoom & @LF) ; Waiting for user to close the window While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $GUI_Button_Home _IENavigate ($oIE, "http://www.autoitscript.com") Case $msg = $GUI_Button_Back _IEAction ($oIE, "back") Case $msg = $GUI_Button_Forward _IEAction ($oIE, "forward") Case $msg = $GUI_Button_Stop _IEAction ($oIE, "stop") EndSelect WEnd GUIDelete() Exit
-
PsaltyDS got a reaction from Parsix in so.... no way for print preview?
Ah, found the execWB for it:
#include <GuiConstantsEx.au3> #include <IE.au3> $oIE = _IECreateEmbedded() $hGUI = GUICreate("Test", 600, 600) $idObj = GUICtrlCreateObj($oIE, 10, 10, 580, 530) $idButton = GUICtrlCreateButton("PrintPreview", 250, 550, 100, 30) _IENavigate($oIE, "http://www.autoitscript.com") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $idButton $oIE.execWB(7, 2) EndSwitch WEnd
For reference:
execWB method
OLECMDID values
OLECMDEXECOPT values
-
PsaltyDS got a reaction from queensoft in stdoutread problems
Do it this way to get ALL the output:
$foo = Run(@ComSpec & " /c c:\temp\runner.bat", "C:\temp\", @SW_HIDE, 2+4) ; handles to STDOUT and STDERR $OutLine = "" $ErrLine = "" While 1 $OutLine &= StdOutRead($foo) If @error Then ExitLoop $ErrLine &= StdErrRead($foo) If @error Then ExitLoop sleep(10) Wend msgbox(0,"Results","STDOUT: " & $OutLine & @CRLF & "ERROUT: " & $ErrLine)
-
PsaltyDS got a reaction from behdadsoft in GUI Window, hide Minimize, Maximize and Close Button
Various effects are achieved with the STYLE and EXTENDED STYLE parameters (see the help file under GuiCreate). This example uses the $DS_MODALFRAME style:#include <GuiConstants.au3> $hGui = GUICreate("Test", 300, 200, Default, Default, $DS_MODALFRAME) $Button = GUICtrlCreateButton("EXIT", 100, 130, 100, 30) GUISetState() Do Sleep(20) Until GUIGetMsg() = $Button
-
PsaltyDS got a reaction from PoojaKrishna in Z-Order, how to restore a window's position ?
WinList(), with no options, lists all windows in Z-order, allowing you to save the previous order in a 2D arra.
One usage of this is _WinPrevious().
-
PsaltyDS got a reaction from ratus69 in howto add rows to an array?
_ArrayAdd() only adds a single row, and only to a 1D array. I have a 2D version, but it still adds a single row. This will take either 1D or 2D for $avArray, and if you pass it a single value, or an array with $NestArray = True, then it gets stored as a single element at [n][0]. If $avArray is 2D and you pass a 1D array with $NestArray = False, then it adds one full row to the array with the elements from the 1D array used for each column.
It is still one row at a time. To append a 2D array onto a 2D array (multiple rows), you need a 2D version of _ArrayConcatenate(), not _ArrayAdd().
This is what I have for 2D add (including full demo), __ArrayAdd():
#include <Array.au3> Global $avTesting, $avAdd, $RET, $iErrSav, $iExtSav, $avTemp ; ---------------------------------------------- ; Demonstrate normal operation ; ---------------------------------------------- $sTitle = "Demonstrate normal operation" ; Add an element to a 1D array: $sMsg = "Add an element to a 1D array:" & @CRLF Global $avTesting[3] = [1, 2, 3] $RET = __ArrayAdd($avTesting, "Four") $iErrSav = @error $iExtSav = @extended _DisplyResults() ; Add a single element to a 2D array $sMsg = "Add a single element to a 2D array:" & @CRLF Global $avTesting[3][2] = [[1, 2],[3, 4],[5, 6]] $RET = __ArrayAdd($avTesting, "Test") $iErrSav = @error $iExtSav = @extended _DisplyResults() ; Add a row of elements to a 2D array $sMsg = "Add a row of elements to a 2D array:" & @CRLF Global $avTesting[3][2] = [[1, 2],[3, 4],[5, 6]] Global $avAdd[2] = ["x", "y"] $RET = __ArrayAdd($avTesting, $avAdd, False) $iErrSav = @error $iExtSav = @extended _DisplyResults() ; Same as above, but nest array as an element $sMsg = "Same as above, but nest array as an element:" & @CRLF Global $avTesting[3][2] = [[1, 2],[3, 4],[5, 6]] Global $avAdd[2] = ["x", "y"] $RET = __ArrayAdd($avTesting, $avAdd) $iErrSav = @error $iExtSav = @extended $avTemp = $avTesting[$RET][0] $sMsg &= "$RET = " & $RET & " @error = " & $iErrSav & " @extended = " & $iExtSav SplashTextOn($sTitle, $sMsg, 400, 100, @DesktopWidth - 500, 100, 16) _ArrayDisplay($avTemp, "$avTemp") ; ---------------------------------------------- ; Demonstrate error handling ; ---------------------------------------------- $sTitle = "Demonstrate error handling" ; $avArray is not an array - @extended = 0 $sMsg = "$avArray is not an array:" & @CRLF Global $avTesting = 0 $RET = __ArrayAdd($avTesting, "Test") $iErrSav = @error $iExtSav = @extended _DisplyResults() ; $avArray is greater than 2D - @extended = 1 $sMsg = "$avArray is greater than 2D:" & @CRLF Global $avTesting[2][2][2] = [[[1, 2],[3, 4]],[[5, 6],[7, 8]]] $RET = __ArrayAdd($avTesting, "Test") $iErrSav = @error $iExtSav = @extended _DisplyResults() ; $vValue as an array is not 1D - @extended = 2 $sMsg = "$vValue as an array is not 1D:" & @CRLF Global $avTesting[3][2] = [[1, 2],[3, 4],[5, 6]] Global $avAdd[2][2] = [["w", "x"],["y", "z"]] $RET = __ArrayAdd($avTesting, $avAdd, False) $iErrSav = @error $iExtSav = @extended _DisplyResults() ; $vValue as an array is too long - @extended = 3 $sMsg = "$vValue as an array is too long:" & @CRLF Global $avTesting[3][2] = [[1, 2],[3, 4],[5, 6]] Global $avAdd[3] = ["w", "x", "y"] $RET = __ArrayAdd($avTesting, $avAdd, False) $iErrSav = @error $iExtSav = @extended _DisplyResults() Func _DisplyResults() $sMsg &= "$RET = " & $RET & " @error = " & $iErrSav & " @extended = " & $iExtSav SplashTextOn($sTitle, $sMsg, 500, 100, @DesktopWidth - 600, 100, 16) If IsArray($avTesting) And UBound($avTesting, 0) < 3 Then _ArrayDisplay($avTesting, "$avTesting") Else MsgBox(64, "Pause", "Pause") EndIf EndFunc ;==>_DisplyResults ; #FUNCTION# ==================================================================================================== ================ ; Name...........: __ArrayAdd ; Description ...: Adds a specified value or row at the end of an existing 1D or 2D array. ; Syntax.........: __ArrayAdd(ByRef $avArray, $vValue [, $NestArray = True]) ; Parameters ....: $avArray - Array to modify ByRef ; $vValue - Value to add, can be a 1D array if $avArray = 2D and $NestArray = False ; $NestArray - Optional flag if False causes array passed as $vValue to be interpreted as a 1D array ; of values to place in a single new row of a 2D array. Default = True, saves array as ; a single element. This flag is ignored if $avArray is 1D or $vValue is not an array. ; Return values .: Success - Index of last added item ; Failure - -1, sets @error to 1, and sets @extended to specify failure (see code below) ; Author ........: Jos van der Zande <jdeb at autoitscript dot com> ; Modified.......: Ultima - code cleanup ; ; PsaltyDS - Array and 2D $vValue inputs added ; Remarks .......: Each call to this function adds exactly one new row to $avArray. To add more rows use _ArrayConcatenate. ; Related .......: _ArrayConcatenate, _ArrayDelete, _ArrayInsert, _ArrayPop, _ArrayPush ; Link ..........; ; Example .......; Yes ; ==================================================================================================== =========================== Func __ArrayAdd(ByRef $avArray, $vValue, $NestArray = True) Local $iBoundArray0, $iBoundArray1, $iBoundArray2, $iBoundValue1 If IsArray($avArray) = 0 Then Return SetError(1, 0, -1); $avArray is not an array $iBoundArray0 = UBound($avArray, 0); No. of dimesions in array If $iBoundArray0 > 2 Then Return SetError(1, 1, -1); $avArray is more than 2D $iBoundArray1 = UBound($avArray, 1); Size of array in first dimension If $iBoundArray0 = 2 Then $iBoundArray2 = UBound($avArray, 2); Size of array in second dimension If ($iBoundArray0 = 1) Or (IsArray($vValue) = 0) Or $NestArray Then ; If input array is 1D, or $vValue is not an array, or $NestArray = True (default) then save $vValue literally If $iBoundArray0 = 1 Then ; Add to 1D array ReDim $avArray[$iBoundArray1 + 1] $avArray[$iBoundArray1] = $vValue Else ; Add to 2D array at [n][0] ReDim $avArray[$iBoundArray1 + 1][$iBoundArray2] $avArray[$iBoundArray1][0] = $vValue EndIf Else ; If input array is 2D, and $vValue is an array, and $NestArray = False, ; then $vValue is a 1D array of values to add as a new row. If UBound($vValue, 0) <> 1 Then Return SetError(1, 2, -1); $vValue array is not 1D $iBoundValue1 = UBound($vValue, 1) If $iBoundArray2 < $iBoundValue1 Then Return SetError(1, 3, -1); $vValue array has too many elements ReDim $avArray[$iBoundArray1 + 1][$iBoundArray2] For $n = 0 To $iBoundValue1 - 1 $avArray[$iBoundArray1][$n] = $vValue[$n] Next EndIf ; Return index of new last row in $avArray Return $iBoundArray1 EndFunc ;==>__ArrayAdd
-
PsaltyDS got a reaction from BigDaddyO in Converting hwnd to int (long)
AutoIt's variant for a handle does not work as an input to Int(), but does for String(), then it can input to Int(): ; Get handle to active window $hActive = WinGetHandle("") ConsoleWrite("$hActive = " & $hActive & @LF) ; Convert to string $sActive = String($hActive) ConsoleWrite("$sActive = " & $sActive & @LF) ; Convert to integer $iActive = Int($sActive) ConsoleWrite("$iActive = " & $iActive & @LF) ; Convert back to handle $hActive = HWnd($iActive) ConsoleWrite("$hActive = " & $hActive & @LF) ; Test the handle $sTitle = WinGetTitle($hActive) ConsoleWrite("$sTitle = " & $sTitle & @LF)
-
PsaltyDS got a reaction from yyywww in HotKeySet function parameters
No. You can't and you don't need to. Just set them all to the same function and use the @HotKeyPressed macro to determine your actions:
HotKeySet("^!u", "HotKeyFunc") HotKeySet("^!o", "HotKeyFunc") HotKeySet("^!i", "HotKeyFunc") HotKeySet("{ESC}", "_Quit") While 1 Sleep(100) WEnd Func HotKeyFunc() Switch @HotKeyPressed Case "^!u" SendUnicode("ü") Case "^!o" SendUnicode("ö") Case "^!i" SendUnicode("ï") EndSwitch EndFunc ;==>HotKeyFunc Func SendUnicode($text) ConsoleWrite("Debug: " & $text & @LF) EndFunc ;==>SendUnicode Func _Quit() Exit EndFunc
-
PsaltyDS got a reaction from RestrictedUser in Workgroup or Domain - how to identify?
Try this:
$oMyError = ObjEvent("AutoIt.Error", "ComErrFunc") ; Prevents COM error crashing script $oAD = ObjCreate("ADSystemInfo") If IsObj($oAD) Then $sComputer = $oAD.ComputerName If @error Then MsgBox(64, "Results", "Not a domain member: " & @ComputerName) Else MsgBox(64, "Results", "Domain member: " & $sComputer) EndIf Else MsgBox(16, "Error", "Failed to create $oAD ADSystemInfo object.") EndIf Func ComErrFunc() $HexNumber = Hex($oMyError.number, 8) Return SetError(1, $HexNumber, 0) EndFunc ;==>ComErrFunc
-
-
PsaltyDS got a reaction from JiBe in Connect a AD from a computer of an other domain
I can't test this right now, but it should get a connection to LDAP using alternative credentials. It's just AutoIt conversion of some VBScript examples floating around on MSDN via Google:
Global Const $ADS_SECURE_AUTHENTICATION = 0x1 Global Const $ADS_SERVER_BIND = 0x200 Global $sLDAPServer = "MyServerName" Global $sLDAPPath = "LDAP://" & $sLDAPServer & "/DC=MySubDomain,DC=MyDomain,DC=com" Global $sUserName = "MyUser" Global $sPassword = "MyPa$$word" Global $iFlags = $ADS_SECURE_AUTHENTICATION + $ADS_SERVER_BIND Global $oDSO = ObjGet("LDAP:") Global $oLDAP = $oDSO.OpenDSObject($sLDAPPath, $sUserName, $sPassword, $iFlags)
Post the results if you get to try it.
-
PsaltyDS got a reaction from AndrewSchultz in How to use parentheses in If...Then
As Tvern posted, Switch/Case/EndSwitch is a much better choice for the function. But to address the compare logic:
The NOT operator is simple boolean negation. And NOT is first operator in the order of operations, so be careful with it.
($format = NOT "JPG") will first perform (NOT "JPG") because of order of operations. For strings, if the string is not empty, it evaluates as TRUE, so "JPG" evaluates as Boolean TRUE, and (NOT "JPG") evaluates as FALSE. The actual contents of the string are not evaluated, so (NOT "FALSE") still evaluates as Boolean FALSE because the string "FALSE" is not empty. The result is $format = FALSE for every string except and empty one.
This version suffers from the same problem: NOT ($format = "BMP")
The correct test would be: If $format <> "BMP" Then
So, if for some reason you couldn't use Switch/Case/EndSwitch, the full test would be:
If ($format <> "JPG") AND ($format <> "BMP") AND ($format <> "GIF") AND ($format <> "PNG") AND ($format <> "TIF") Then ; Not valid input Else ; Valid input EndIf Or, put the other way around:
If ($format = "JPG") OR ($format = "BMP") OR ($format = "GIF") OR ($format = "PNG") OR ($format "TIF") Then ; Valid input Else ; Not valid input EndIf
-
PsaltyDS got a reaction from GoogleGonnaSaveUs in Importing text file into array
You don't have to FileOpen/FileClose for _FileReadToArray(). It will do that for itself. And you were almost there. The $test array already has all the lines in it and $test[0] is the count. You create the 2D array (a 1D array is just a list, a 2D array is just a table with rows and columns) using $test[0] to tell you how big to make it. The loop reads each line from $test, splits into $array, and then copies the parts to the new array:
#include <file.au3> #include <array.au3> ; only for _ArrayDisplay() $sFile = "c:\Temp\ipaddr.txt" ;Read in lines of text into 1D array Dim $text If Not _FileReadToArray($sFile, $text) Then MsgBox(4096, "Error", " Error reading text file to Array error:" & @error) Exit EndIf _ArrayDisplay($text, "Debug: $text") ; Split lines into 2D array Dim $avIPs[$text[0] + 1][2] = [["old ip address", "new ip address"]] For $x = 1 To $text[0] $array = StringSplit($text[$x], ",") If $array[0] = 2 Then $avIPs[$x][0] = $array[1] $avIPs[$x][1] = $array[2] EndIf Next _ArrayDisplay($avIPs, "Debug: $avIPs")