Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/13/2019 in all areas

  1. I must apologize for my cryptic answer, hastily writen. It wasn't meant to be rude to you, just pointing out that such code isn't a valuable, efficient solution. I feel this now turns out as a code optimization request, rather than a failed demo that plain vanilla code is inferior. I gently suggest you open a new thread in General Help forum with a significant sample of input data and your requirements for processing. I strongly suspect there are faster regular ways to process text (ASCII) data than convert the wole thing to binary then extract the wanted pieces out of a large chunk of converted binary. The goal of most of the fora here is to maximize usefulness of AutoIt-based code. So we're fully spot-on and there is a number of seasonned contributors here willing to provide as much help as possible.
    2 points
  2. [BUGFIX VERSION] - 6 Apr 24 Fixed: UDF failed if header colours were initialised but not specifically set. New UDF in the zip below. -------------------------------------------------------------------------------------- Note: This is a new recoded and expanded version of my earlier UDF of the same name. If you move to this new version there might well be several script-breaking changes, particularly when setting which columns are to be editable. Please read the "Beginner's Guide" and look at the included example scripts to see where things have changed. -------------------------------------------------------------------------------------- This UDF allows you to do much more with ListView controls (either native or UDF created): Edit the content with plain text, combos or date-time pickers - and edit the headers too Move rows within the ListView Drag rows both within the ListView and to other ListViews in the same GUI (or not as required) Insert and delete columns and rows Sort columns by simply clicking the header Colour individual ListView items and headers Only select a single cell rather then the entire row Save and load entire ListViews For the advanced user: If you use certain Windows message handlers (In particular WM_NOTIFY) in your script, please read the function headers for the equivalent handlers within the UDF. Here is the UDF, with 6 examples and the guide, in zip format: GUIListViewEx.zip Credit to: martin (basic drag code), Array.au3 authors (array functions), KaFu and ProgAndy (font function), LarsJ (colouring code) Happy to take compliments or criticism - preferably the former! M23
    1 point
  3. The GUI looks like shown in the picture: It contains a main menu, a treeview in left pane that lists UI Automation elements, a listview in right pane that displays detail information for the selected element, and a splitterbar to adjust the width of the two panes. Detect element The "Detect element" main menu is used to detect elements under the mouse with function keys F1 - F4. See How to topics number 2. Left pane The left pane is a treeview that initially lists open programs and windows. Generally, the left pane shows UI Automation elements represented as treeview items. Right pane The right pane is a listview that displays detail information for the selected treeview element. The information is grouped into different types of information. Only the relevant information for each type is displayed. Invalid elements When a window is closed the elements in UIASpy becomes invalid. But the elements are not deleted in UIASpy and can still be handled and selected in the treeview. Detail information for an element that was calculated before the window was closed can still be seen in the listview. In this way it's possible for UIASpy to show information for eg. a context menu that is closed as soon as it loses focus. Listview features Listview features Help system With completion of the Help system, a lot of information has been moved from this post and other posts into the Help system. Sample code creation Sample code creation is implemented through the UI element Detail info listview page and through the Sample code main menu. Sample code creates code snippets based on data in one or more selected rows in the Detail info listview page or based on the clicked Sample code menu item. UI Automation code is largely based on COM interface objects and thus on the function ObjCreateInterface(), which is one of the advanced functions in AutoIt. The main purpose of Sample code functionality is to eliminate the complexity of ObjCreateInterface(). Sample code creation either through the Detail info listview page or through the Sample code main menu can create all the interface objects required in UI Automation code. Another purpose is of course to make it easier and faster to implement code for simple automation tasks. Through Sample code creation, you can more or less create all code in a simple automation task: Create UI Automation initial code Create condition and find application window Create condition and find control in window Get information about windows and controls Create pattern objects to perform actions Get information related to pattern objects Perform actions with pattern object methods Add a Sleep() statement if necessary Note that the UI element used in sample code is named after the selected element in the treeview. Also note that both the Sample code menu items and the sections in the Detail info listview page are placed in approximately the order they are used in a simple automation task. Sample code creation through Detail info listview page Sample code creation through Sample code main menu Supported applications Most browsers including Google Chrome To be able to spy on web content in Google Chrome it's necessary to enable accessibility by entering chrome://accessibility/ in the address bar of a new tab item, and then check the five check boxes that are located in a column in upper left corner down along the left edge. Then the accessibility tab can be closed again. It's a global setting that applies to all open and new tabs until Chrome is closed. Without accessibility enabled you are only able to investigate the outer elements of Chrome but not web content. Internet Explorer Microsoft Edge Mozilla Firefox Most Microsoft applications and applications developed with Microsoft software including Classic Windows applications based on the standard control library Modern Universal Windows Platform apps like the Windows 10 Calculator Programs implemented through .NET Framework eg. Windows Forms applications Most applications provided by major development companies Automation issues Automation issues How to topics If UI Automation or the UIASpy tool is new to you, then you should read the How to topics. Examples Examples that demonstrates the features of UIASpy: Automating Notepad. Very detailed example. Automating Notepad - Windows XP Examples about Sample code creation: Automating Notepad with Sample code - step by step Automating Notepad with Sample code - all at once Chrome - Clicking an extension. Compact summary example. Click Save As... issue in Notepad examples: Using Expand() instead of Invoke() Updates Windows 8, Windows 8.1 and Windows 10 updates Threads UI Automation UDFs contains all include files. In Using UI Automation Code in AutoIt you can find and download examples and read information about using UIA code. UI Automation Events is about implementing event handlers and includes GUIs to detect events. IUIAutomation MS framework automate chrome, FF, IE, .... created by junkew August 2013 is the first AutoIt thread on UIA code. Zip-file The zip contains source files for UIASpy GUI. Note that UI Automation UDFs must be installed in the Includes folder. You need AutoIt 3.3.12 or later. Tested on Windows XP, Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. UIASpy.7z
    1 point
  4. (Edited from original. Please note that I AM NOT AN AUTOIT EXPERT. I write code using Autoit frequently but I am no expert, especially when it comes to I/O. So any remarks that start with "Why did you..." can be answered by referring to the first sentence. This project was done in Autoit because of an interface I built to display the data.) Attached is a program and ascii input file I wrote to read stock price data, convert it to binary and then read it back into the program in binary. The goal was to show increased performance for reading the files in binary and provide a demo on how to read/write binary for int32, int64, double and strings for anyone who might find it helpful. The results on my PC show the following: Time to read ascii file only: 456.981951167202 Ascii read & process time: 6061.83075631701 Binary write file time: 14787.9184635239 Time just to read binary file: 42.418867292311 Binary read and process time: 4515.16129830537 A couple things to note: 1) The 32 MB ascii file took 10x longer to read than the 15 MB binary file. Not entirely sure why. Both were read into a buffer. 2) The Binary write takes a long time but I made no effort to optimize this because the plan was to write this file one time only so I don't mind if it takes longer to write this file. I care much more about how long it takes to read the file because I will be reading it many times. 3) There was a modest gain in converting the ascii file to binary in terms of file size and reading speed. So big picture... not sure it's worth the effort to convert the files to binary even though most of the data is numerical data in the binary file. That was actually surprising as I expected there would be more of a difference. Any ideas on how to get the binary data to read at a faster rate would be great. binary.au3 2019_02_08.zip
    1 point
  5. Gif

    WMI Tasks

    Hello everyone, This is my first OFFICIAL post on the example scripts forum as i tend to post only things that might help other people or are advanced enough. Well i at least hope that someone might find them useful. It's a list of WMI Tasks concerning several subjects such as Disks, Hardware, Software, Operating System etc. etc. I hope those functions will come useful and someone might like some of them Opt('MustDeclareVars', 1) #region #NoTrayIcon #Include <Array.au3> #endregion ;==================================================================================== ; Programmed by: Tefkros Pavlou (Gif) , www.randomsoft.tk ; Reference at: http://msdn2.microsoft.com ; WINMGMTS functions ;==================================================================================== MsgBox(64, 'Mouse Properties', _Mouse_Properties()) MsgBox(64, 'Processor Speed', _Processor_Speed()) MsgBox(64, 'Computer Type', _Computer_Type()) MsgBox(64, 'Total RAM installed', _Physical_RAM_Available()) MsgBox(64, 'Number of Processors', _Number_Of_Processors()) MsgBox(64, 'Floppy check', _Check_Floppy()) MsgBox(64, 'MS Office Version', _Office_GetVersion()) MsgBox(64, 'Operating System Status', _Determine_Operating_System_Status()) MsgBox(64, 'Detailed Date/Time', _Retrieve_Date_And_Time()) MsgBox(64, 'Time Zone', _Get_Time_Zone()) MsgBox(64, 'Username', _Get_Username()) Global $Accounts_Array = _Get_Local_Accounts() If ($Accounts_Array <> 0) Then _ArrayDisplay($Accounts_Array, 'Local Accounts') Global $Drives_Array = _Drives_Determine() If ($Drives_Array <> 0) Then _ArrayDisplay($Drives_Array, 'Drives (determine DVD drives)') Global $usb_Array = _USB_Devices() If ($usb_Array <> 0) Then _ArrayDisplay($usb_Array, 'USB Devices') Global $Logs_Array = _Get_Events_From_Log() If ($Logs_Array <> 0) Then _ArrayDisplay($Logs_Array, 'Local Accounts') Global $Startup_Services_Array = _Get_Startup_Services() If ($Startup_Services_Array <> 0) Then _ArrayDisplay($Startup_Services_Array, 'Startup Items') Exit (0) Func _Mouse_Properties() Local $a_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_PointingDevice') Local $Obj_Item For $Obj_Item In $Col_Items Local $a_Text = 'Description: ' & $Obj_Item.Description & @CRLF $a_Text &= 'Device ID: ' & $Obj_Item.DeviceID & @CRLF $a_Text &= 'Device Interface: ' & $Obj_Item.DeviceInterface & @CRLF $a_Text &= 'Double Speed Threshold: ' & $Obj_Item.DoubleSpeedThreshold & @CRLF $a_Text &= 'Handedness: ' & $Obj_Item.Handedness & @CRLF $a_Text &= 'Hardware Type: ' & $Obj_Item.HardwareType & @CRLF $a_Text &= 'INF File Name: ' & $Obj_Item.InfFileName & @CRLF $a_Text &= 'INF Section: ' & $Obj_Item.InfSection & @CRLF $a_Text &= 'Manufacturer: ' & $Obj_Item.Manufacturer & @CRLF $a_Text &= 'Name: ' & $Obj_Item.Name & @CRLF $a_Text &= 'Number Of Buttons: ' & $Obj_Item.NumberOfButtons & @CRLF $a_Text &= 'PNP Device ID: ' & $Obj_Item.PNPDeviceID & @CRLF $a_Text &= 'Pointing Type: ' & $Obj_Item.PointingType & @CRLF $a_Text &= 'Quad Speed Threshold: ' & $Obj_Item.QuadSpeedThreshold & @CRLF $a_Text &= 'Resolution: ' & $Obj_Item.Resolution & @CRLF $a_Text &= 'Sample Rate: ' & $Obj_Item.SampleRate & @CRLF $a_Text &= 'Synch: ' & $Obj_Item.Synch Next Return String($a_Text) Else Return 0 EndIf EndFunc Func _Processor_Speed() Local $s_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_Processor') Local $Obj_Item For $Obj_Item In $Col_Items Local $s_Text = 'Processor Id: ' & $Obj_Item.ProcessorId & @CRLF $s_Text &= 'Maximum Clock Speed: ' & $Obj_Item.MaxClockSpeed Next Return String($s_Text) Else Return 0 EndIf EndFunc Func _Computer_Type() Local $u_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Chassis = $Obj_WMIService.ExecQuery('Select * from Win32_SystemEnclosure') Local $Obj_Chassis For $Obj_Chassis In $Col_Chassis Local $Obj_Items For $Obj_Item In $Obj_Chassis.ChassisTypes If (Number($Obj_Item) = 1) Then Local $u_Text = 'Type: Other' & @CRLF ElseIf (Number($Obj_Item) = 2) Then Local $u_Text = 'Type: Unknown' & @CRLF ElseIf (Number($Obj_Item) = 3) Then Local $u_Text = 'Type: Desktop' & @CRLF ElseIf (Number($Obj_Item) = 4) Then Local $u_Text = 'Type: Low profile Desktop' & @CRLF ElseIf (Number($Obj_Item) = 5) Then Local $u_Text = 'Type: Pizza Box' & @CRLF ElseIf (Number($Obj_Item) = 6) Then Local $u_Text = 'Type: Mini Tower' & @CRLF ElseIf (Number($Obj_Item) = 7) Then Local $u_Text = 'Type: Tower' & @CRLF ElseIf (Number($Obj_Item) = 8) Then Local $u_Text = 'Type: Portable' & @CRLF ElseIf (Number($Obj_Item) = 9) Then Local $u_Text = 'Type: Laptop' & @CRLF ElseIf (Number($Obj_Item) = 10) Then Local $u_Text = 'Type: Notebook' & @CRLF ElseIf (Number($Obj_Item) = 11) Then Local $u_Text = 'Type: Hand Held' & @CRLF ElseIf (Number($Obj_Item) = 12) Then Local $u_Text = 'Type: Docking Station' & @CRLF ElseIf (Number($Obj_Item) = 13) Then Local $u_Text = 'Type: All in One' & @CRLF ElseIf (Number($Obj_Item) = 14) Then Local $u_Text = 'Type: Sub Notebook' & @CRLF ElseIf (Number($Obj_Item) = 15) Then Local $u_Text = 'Type: Space saving' & @CRLF ElseIf (Number($Obj_Item) = 16) Then Local $u_Text = 'Type: Lunch Box' & @CRLF ElseIf (Number($Obj_Item) = 17) Then Local $u_Text = 'Type: Main System Chassis' & @CRLF ElseIf (Number($Obj_Item) = 18) Then Local $u_Text = 'Type: Expansion Chassis' & @CRLF ElseIf (Number($Obj_Item) = 19) Then Local $u_Text = 'Type: SubChassis' & @CRLF ElseIf (Number($Obj_Item) = 20) Then Local $u_Text = 'Type: Bus Expansion Chassis' & @CRLF ElseIf (Number($Obj_Item) = 21) Then Local $u_Text = 'Type: Peripheral Chassis' & @CRLF ElseIf (Number($Obj_Item) = 22) Then Local $u_Text = 'Type: Storage Chassis' & @CRLF ElseIf (Number($Obj_Item) = 23) Then Local $u_Text = 'Type: Rack Mount Chassis' & @CRLF ElseIf (Number($Obj_Item) = 24) Then Local $u_Text = 'Type: Sealed-Case PC' & @CRLF Else Local $u_Text = 'Type: Unable to retrieve' & @CRLF EndIf Next ; Might not work properly $u_Text &= 'Name: ' & $Obj_Chassis.Name & @CRLF $u_Text &= 'Caption: ' & $Obj_Chassis.Caption & @CRLF $u_Text &= 'Manufacturer: ' & $Obj_Chassis.Manufacturer & @CRLF $u_Text &= 'Model: ' & $Obj_Chassis.Model & @CRLF $u_Text &= 'Description: ' & $Obj_Chassis.Description & @CRLF $u_Text &= 'Height: ' & $Obj_Chassis.Height & @CRLF $u_Text &= 'Width: ' & $Obj_Chassis.Width & @CRLF $u_Text &= 'Weight: ' & $Obj_Chassis.Weight & @CRLF $u_Text &= 'Depth: ' & $Obj_Chassis.Depth & @CRLF $u_Text &= 'Heat Generation: ' & $Obj_Chassis.HeatGeneration & @CRLF $u_Text &= 'Install Date: ' & $Obj_Chassis.InstallDate & @CRLF Next Return String($u_Text) Else Return 0 EndIf EndFunc Func _Physical_RAM_Available() Local $y_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_ComputerSystem') Local $Obj_Items For $Obj_Items In $Col_Items Local $y_Text = 'RAM: ' & Round((($Obj_Items.TotalPhysicalMemory / 1024) / 1024), 3) & ' MB' Next Return String($y_Text) Else Return 0 EndIf EndFunc Func _Number_Of_Processors() Local $z_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_ComputerSystem') Local $Obj_Items For $Obj_Items In $Col_Items Local $z_Text = 'Found: ' & $Obj_Items.NumberOfProcessors & ' processor(s)' Next Return String($z_Text) Else Return 0 EndIf EndFunc Func _Drives_Determine() Local $Columns = 4 Local $Number_DRV = DriveGetDrive('CDROM') Local $Drives[($Number_DRV[0] + 1)][$Columns] $Drives[0][0] = -1 Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_CDROMDrive') Local $Obj_Items For $Obj_Items In $Col_Items $Drives[0][0] += 1 $Drives[Number($Drives[0][0] + 1)][0] = $Obj_Items.DeviceID $Drives[Number($Drives[0][0] + 1)][1] = $Obj_Items.Description $Drives[Number($Drives[0][0] + 1)][2] = $Obj_Items.Name $Drives[Number($Drives[0][0] + 1)][3] = $Obj_Items.Drive Next $Drives[0][0] += 1 Return $Drives Else Return 0 EndIf EndFunc Func _USB_Devices() Local $Columns = 3 Local $usb_Array[9][$Columns] $usb_Array[0][0] = -1 Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_USBHub') Local $Obj_Items For $Obj_Items In $Col_Items $usb_Array[0][0] += 1 $usb_Array[Number($usb_Array[0][0] + 1)][0] = $Obj_Items.DeviceID $usb_Array[Number($usb_Array[0][0] + 1)][1] = $Obj_Items.PNPDeviceID $usb_Array[Number($usb_Array[0][0] + 1)][2] = $Obj_Items.Description If (($Obj_Items.Description) <> ($Obj_Items.Name)) Then ReDim $usb_Array[Number($usb_Array[0][0] + 1)][$Columns + 1] $usb_Array[Number($usb_Array[0][0] + 1)][3] = $Obj_Items.Name EndIf Next $usb_Array[0][0] += 1 Return $usb_Array Else Return 0 EndIf EndFunc Func _Check_Floppy() Local $m_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery("Select * From Win32_LogicalDisk Where DeviceID = 'A:'") For $Obj_Items In $Col_Items Local $IntFreeSpace = $Obj_Items.FreeSpace If (IsNull($IntFreeSpace)) Then Local $m_Text = 'No disk in floppy drive.' Else Local $m_Text = 'Disk found in the floppy drive.' EndIf Next Return String($m_Text) Else Return 0 EndIf EndFunc Func _Office_GetVersion() Local $h_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_Product ' & _ 'Where IdentifyingNumber =' _ & " '{90280409-6000-11D3-8CFE-0050048383C9}'") Local $Obj_Items For $Obj_Items In $Col_Items Local $h_Text = 'Name: ' & $Obj_Items.Name & @CRLF $h_Text &= 'Version: ' & $Obj_Items.Version Next Return String($h_Text) Else Return 0 EndIf EndFunc Func _Get_Startup_Services() Local $Columns = 6 Local $Startup_Services_Array[2][$Columns] $Startup_Services_Array[0][0] = 0 Dim $Obj_WMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_StartupCommand') Local $Obj_Items For $Obj_Items In $Col_Items $Startup_Services_Array[0][0] += 1 $Startup_Services_Array[Number($Startup_Services_Array[0][0])][0] = $Obj_Items.Command $Startup_Services_Array[Number($Startup_Services_Array[0][0])][1] = $Obj_Items.Description $Startup_Services_Array[Number($Startup_Services_Array[0][0])][2] = $Obj_Items.Location $Startup_Services_Array[Number($Startup_Services_Array[0][0])][3] = $Obj_Items.Name $Startup_Services_Array[Number($Startup_Services_Array[0][0])][4] = $Obj_Items.SettingID $Startup_Services_Array[Number($Startup_Services_Array[0][0])][5] = $Obj_Items.User ReDim $Startup_Services_Array[Number($Startup_Services_Array[0][0] + 2)][$Columns] Next $Startup_Services_Array[0][0] += 1 Return $Startup_Services_Array Else Return 0 EndIf EndFunc Func _Determine_Operating_System_Status() Local $j_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_WindowsProductActivation') Local $Obj_Items For $Obj_Items In $Col_Items Global $Active_Require = $Obj_Items.ActivationRequired Switch $Active_Require Case 0 Local $j_Text = 'Activation Not Required' & @CRLF Case 1 Local $j_Text = 'Activation Is Required' & @CRLF Case Else Local $j_Text = 'unknown' & @CRLF EndSwitch $j_Text &= 'Remaining Evaluation Period (in days): ' & $Obj_Items.RemainingEvaluationPeriod & @CRLF $j_Text &= 'Remaining Grace Period: (in days): ' & $Obj_Items.RemainingGracePeriod Next Return String($j_Text) Else Return 0 EndIf EndFunc Func _Retrieve_Date_And_Time() Local $t_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_LocalTime') Local $Obj_Items For $Obj_Items In $Col_Items Local $t_Text = 'Day: ' & $Obj_Items.Day & @CRLF $t_Text &= 'Day Of Week: ' & $Obj_Items.DayOfWeek & @CRLF $t_Text &= 'Hour: ' & $Obj_Items.Hour & @CRLF $t_Text &= 'Minute: ' & $Obj_Items.Minute & @CRLF $t_Text &= 'Month: ' & $Obj_Items.Month & @CRLF $t_Text &= 'Quarter: ' & $Obj_Items.Quarter & @CRLF $t_Text &= 'Second: ' & $Obj_Items.Second & @CRLF $t_Text &= 'Week In Month: ' & $Obj_Items.WeekInMonth & @CRLF $t_Text &= 'Year: ' & $Obj_Items.Year Next Return String($t_Text) Else Return 0 EndIf EndFunc Func _Get_Time_Zone() Local $l_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_TimeZone') Local $Obj_Items For $Obj_Items In $Col_Items Local $l_Text = 'Description: ' & $Obj_Items.Description & @CRLF $l_Text &= 'Daylight Name: ' & $Obj_Items.DaylightName & @CRLF $l_Text &= 'Standard Name: ' & $Obj_Items.StandardName Next Return String($l_Text) Else Return 0 EndIf EndFunc Func _Get_Username() Local $p_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_ComputerSystem') Local $Obj_Items For $Obj_Items In $Col_Items Local $p_Text = 'Name: ' & $Obj_Items.Name & @CRLF $p_Text &= 'Username: ' & $Obj_Items.Username Next Return String($p_Text) Else Return 0 EndIf EndFunc Func _Get_Local_Accounts() Local $Columns = 4 Local $Local_Accounts_Array[2][$Columns] $Local_Accounts_Array[0][0] = 0 Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_Group Where LocalAccount = True') Local $Obj_Items For $Obj_Items In $Col_Items $Local_Accounts_Array[0][0] += 1 $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][0] = $Obj_Items.Name $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][1] = $Obj_Items.Sid Local $Sz_SetType = Number($Obj_Items.SidType) Select Case $Sz_SetType = 1 $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][2] = 'User' Case $Sz_SetType = 2 $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][2] = 'Group' Case $Sz_SetType = 3 $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][2] = 'Domain' Case $Sz_SetType = 4 $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][2] = 'Alias' Case $Sz_SetType = 5 $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][2] = 'Well Known Group' Case $Sz_SetType = 6 $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][2] = 'Deleted Account' Case $Sz_SetType = 7 $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][2] = 'Invalid' Case $Sz_SetType = 8 $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][2] = 'Unknown' Case $Sz_SetType = 9 $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][2] = 'Computer' EndSelect $Local_Accounts_Array[Number($Local_Accounts_Array[0][0])][3] = $Obj_Items.Status ReDim $Local_Accounts_Array[Number($Local_Accounts_Array[0][0] + 2)][$Columns] Next Return $Local_Accounts_Array Else Return 0 EndIf EndFunc Func _Get_Events_From_Log() Local $Columns = 9 Local $Events_Array[2][$Columns] $Events_Array[0][0] = 0 Dim $Obj_WMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery("Select * from Win32_NTLogEvent " _ & "Where Logfile = 'System'") Local $Obj_Items For $Obj_Items In $Col_Items $Events_Array[0][0] += 1 $Events_Array[Number($Events_Array[0][0])][0] = $Obj_Items.Category $Events_Array[Number($Events_Array[0][0])][1] = $Obj_Items.ComputerName $Events_Array[Number($Events_Array[0][0])][2] = $Obj_Items.EventCode $Events_Array[Number($Events_Array[0][0])][3] = $Obj_Items.Message $Events_Array[Number($Events_Array[0][0])][4] = $Obj_Items.RecordNumber $Events_Array[Number($Events_Array[0][0])][5] = $Obj_Items.SourceName $Events_Array[Number($Events_Array[0][0])][6] = $Obj_Items.TimeWritten $Events_Array[Number($Events_Array[0][0])][7] = $Obj_Items.Type $Events_Array[Number($Events_Array[0][0])][8] = $Obj_Items.User ReDim $Events_Array[Number($Events_Array[0][0] + 2)][$Columns] Next Return $Events_Array Else Return 0 EndIf EndFunc Func _Rename_Computer($iName = @ComputerName) Local $z_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('Select * from Win32_ComputerSystem') Local $Obj_Items For $Obj_Items In $Col_Items Local $z_Text = $Obj_Items.Rename(String($iName)) Next EndIf EndFunc ; Logic IsNull() expression [http://msdn2.microsoft.com/en-us/library/zbchw6hz.aspx] Func IsNull($g_Var) If ((String($g_Var) == '') Or (IsBinary($g_Var)) Or (Not String($g_Var)) Or (StringIsSpace($g_Var)) Or (@error)) Then Return True Else Return False EndIf EndFunc ps: _Get_Startup_Services() And _Get_Events_From_Log() will take a long time to be executed.
    1 point
  6. Using old code (without checking it) and resurrecting old thread will hardly give the right results Try this instead and check help file to understand the changes I applied. #include <Constants.au3> #include <GUIConstants.au3> #include <WinAPISysWin.au3> #include <WinAPIGdi.au3> $hGui = GUICreate("Test GUI", 320, 240) $idButton = GUICtrlCreateButton ("Quit", 130, 210, 60, 20) Run('notepad.exe',"", @SW_HIDE) $hChild = WinWait("[CLASS:Notepad]", "", 5) _WinAPI_SetWindowLong ($hChild, $GWL_STYLE,$WS_BORDER) _WinAPI_SetWindowLong ($hChild, $GWL_EXSTYLE, $WS_EX_MDICHILD) _WinAPI_SetParent($hChild, $hGui) WinMove($hChild, "", 0, 0,320,200) GUISetState(@SW_SHOW, $hGui) WinSetState($hChild,"",@SW_SHOW) _WinAPI_RedrawWindow ($hGUI) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton ExitLoop EndSwitch WEnd GUIDelete ($hGui)
    1 point
  7. You could also use a function with default param like Func _test ($p1, $p2 = 0, $p3 = 0, $p4 = 0, $p5 = 0, $p6 = 0, $p7 = 0, $p8 = 0, $p9 = 0) return (isString ($p1) or isString ($p2) or isString ($p3) or isString ($p4) or isString ($p5) or isString ($p6) or isString ($p7) or _ isString ($p8) or isString ($p9)) EndFunc
    1 point
  8. Based on this naive response, you have made everyone on this forum who knows the depth of jchd's technical knowledge laugh.
    1 point
  9. Thanks for your response. I think a detailed explanation may be helpful. Let's go through an example that may make it clear the importance of not treating numerical data as a string. Let's say I have a large number: 2141231231 (10 characters) I have two options to write that number to a file... as a string of 11 bytes (written either in ascii or binary with a deliminator) or as an Int32 which is 4 bytes (written in binary). The BinaryToString and StringToBinary will treat this as 11 bytes so the file size is larger but admittedly dependent on the number of characters in the number. The file size could potentially be smaller if the numerical data on average was made up of numbers from -9 to 99 (remember, still need a 1 char deliminator). But that's not the real problem. After reading in this data as a string you still need to convert this string to a number so that it can be used in mathematical calculations. The string is of no value for calculations. That requires several steps with a computational penalty for each step. For every data point I read in binary as a string I first have to use BinaryToString to get the data in string format, I then have to use StringSplit to separate the large string into individual strings for each number and finally I have to use the Number algorithm to convert the string into a number. When you have millions of data points this is very slow and unnecessary. Much better to write the data in binary as an Int32, Int64 or Double and read it in binary as the same data type. By doing that I eliminate BinaryToString, StringSplit and Number from the process. For small file sizes this is a non-issue in regards to time savings although I think it's actually easier to read/write these files in the method I outlined than use multiple steps to convert between strings and numbers. But for large datasets the time savings in reading these files in the way I outlined is significant. You definitely don't want to read/write numbers as a string whenever dealing with a lot of data. Hope that helps.
    1 point
  10. iamtheky

    AutoIt Snippets

    using _arrayadd instead of stringsplit and ubound Just dropped this in a thread and thought it slightly clever, cant remember if its been explored already. You are probably eating some time penalties for being lazy, but look how lazy you can be. #include<array.au3> $str = "computer:user:45ms" ;~ $str = "computer:user45ms" ;~ $str = "computeruser45ms" local $arr[0] for $i = 0 to _ArrayAdd($arr , $str , 0 , ":") msgbox(0, $i + 1 & ' of ' & ubound($arr), $arr[$i]) next
    1 point
  11. edit: more complete example showing behavior with various numbers of colons (including none) and made the msgbox title useful. #include<array.au3> $str = "computer:user:45ms" ;~ $str = "computer:user45ms" ;~ $str = "computeruser45ms" local $arr[0] for $i = 0 to _ArrayAdd($arr , $str , 0 , ":") msgbox(0, $i + 1 & ' of ' & ubound($arr), $arr[$i]) next
    1 point
  12. Yes WinWait is a very good alternative. You could even put a timer on it and do something else while waiting for the application to come back.
    1 point
  13. @Nine your update above is more inline with what the OP describes. The first version of your code just exited once the window was closed and there was no way for any further checks to occur. I took a stab at this and made a few changes to @Nines code. is equal to TRUE, so for readability I changed this to $BooleanMessageDisplayed = TRUE , below. While True     WinWait("BoxTop Advantage"); wait till application is back             If _Timer_GetIdleTime() >= $WarningMessageTime Then         If $BooleanMessageDisplayed = TRUE Then            $BooleanMessageDisplayed = FALSE            MessageBoxTimeOut()         EndIf     Endif     If _Timer_GetIdleTime() >= $InactivityTime Then CloseBoxTop()     Sleep (10) ; reduce CPU impact WEnd You can add a timeout to WinWait if you want, the script is essentially locked until the window reappears in this code snippit otherwise. I don't like using NOT especially with booleans, just write it out in plain as possible language will remove confusion.
    1 point
  14. The script has to manage the fact that the inactivity period would continue after window closure. The exitloop was a way to stop the script in checking inactivity. @Rhys_A you could use something like : While True If not WinExists ("[TITLE:BoxTop Advantage]") then ; wait till application is back Sleep (1000) ContinueLoop Endif If _Timer_GetIdleTime() >= $WarningMessageTime Then If Not $BooleanMessageDisplayed Then $BooleanMessageDisplayed = True MessageBoxTimeOut () EndIf Endif If _Timer_GetIdleTime() >= $InactivityTime Then CloseBoxTop() Sleep (100) ; reduce CPU impact WEnd
    1 point
  15. Remove the ExitLoop after CloseBoxTop() This will keep the While Loop running and your application will not exit after CloseBoxTop() runs
    1 point
  16. Or this : Global $Config = "C:\Users\--\Desktop\INI\Config.ini" Global $InactivityTime = IniRead($Config, "Config", "InactivityTime", 30000) Global $WarningMessageTime = $InactivityTime - 10000 Global $MessageBoxTimeOut = IniRead($Config, "Config", "MessageBoxTimeOut", 10) Global $BooleanMessageDisplayed = False ; I do not see a reason to have this in .ini While True If _Timer_GetIdleTime() >= $WarningMessageTime Then If Not $BooleanMessageDisplayed Then $BooleanMessageDisplayed = True MessageBoxTimeOut () EndIf Endif If _Timer_GetIdleTime() >= $InactivityTime Then CloseBoxTop() ExitLoop EndIf WEnd Func CloseBoxTop() WinClose("[TITLE:BoxTop Advantage]", "") ControlClick("[CLASS:#32770]", "&Yes", 6, "left", 1) EndFunc ;==>CloseBoxTop Func MessageBoxTimeOut() Local iMsgBoxAnswer $iMsgBoxAnswer = MsgBox($MB_OK + $MB_ICONQUESTION, "Insufficient Activity", "BoxTop will close in 2 minutes unless there is user Input, or OK is pressed.", $MessageBoxTimeOut) If $iMsgBoxAnswer = $IDOK Then $BooleanMessageDisplayed = False EndFunc ;==>MessageBoxTimeOut
    1 point
  17. Would something like this work for you? #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Timers.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("WinTitleMatchMode", 3) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Global $hGUI, $Window = 'Desktop';"[CLASS:OMain]" Global $BooleanMessageDisplayed = 0, $MessageBoxTimeOut = 10 ;Global $Config = 'C:\Users\&'@UserName'&\Desktop\INI\Config.ini' ;Global $BooleanMessageDisplayed = IniRead($Config, "Config", "BooleanMessageDisplayed", 0) Global $InactivityTime = 10000 ;IniRead($Config, "Config", "InactivityTime", 30000) Global $WarningMessageTime = $InactivityTime - 5000 ;Global $MessageBoxTimeOut = IniRead($Config, "Config", "MessageBoxTimeOut", 10) While 1 $TimerIdle = _Timer_GetIdleTime() If $TimerIdle > $WarningMessageTime Then If WinExists($Window) = 1 And WinExists('Insufficient Activity') = 0 Then $hGUI = GUICreate('Insufficient Activity', 300, 100, -1, -1, $WS_POPUP, $WS_EX_TOPMOST) GUICtrlCreateLabel("BoxTop will close in 2 minutes unless there is user Input", 10, 10, 285, 25) GUISetState(@SW_SHOW, $hGUI) EndIf EndIf If $TimerIdle >= $InactivityTime Then If WinExists($Window) Then WinClose($Window) GUIDelete($hGUI) Exit EndIf EndIf If $TimerIdle = 0 Then If WinExists($hGUI) Then GUIDelete($hGUI) EndIf EndIf ConsoleWrite($TimerIdle &@CRLF&WinExists('Insufficient Activity')&@CRLF) Sleep(100) WEnd Func CloseMsg() GUIDelete($hGUI) EndFunc ;==>MessageBoxTimeOut
    1 point
  18. The message box interrupts the script, are you ok with a different type of notification?
    1 point
  19. Anyhelp about what ? What is the problem ? I can see some wrong things in your script but what is the issue actually?
    1 point
  20. @caramen #include <Constants.au3> #include <Array.au3> Const $PROCESS_NAME = "firefox.exe" Const $MB_LIMIT = 250 Global $aMemStats , $aProcessList Global $nMemKB, $nMemMB While 1 ;Get process list $aProcessList = ProcessList ($PROCESS_NAME) If Not IsArray($aProcessList) Or $aProcessList[0][0] = 0 Then MsgBox($MB_ICONERROR, "ERROR", StringFormat('Unable to get process list for "%s".', $PROCESS_NAME)) Exit EndIf ;Calculate total kb of processes $nMemKB = 0 For $i = 1 To $aProcessList[0][0] $aMemStats = ProcessGetStats($aProcessList[$i][1]) $nMemKB += ($aMemStats[0] / 1024) Next ;Convert bytes kb to mb $nMemMB = $nMemKB / 1024 ConsoleWrite(StringFormat("Total KB = %i", $nMemKB) & @CRLF) ConsoleWrite(StringFormat("Total MB = %i", $nMemMB) & @CRLF) ;If threshhold exceeded If $nMemMB > $MB_LIMIT Then ;Display message and exit MsgBox($MB_ICONWARNING, "WARNING", _ StringFormat("Firefox memory limit exceeded.\nActual MB = %i\nLimit MB = %i", $nMemMB, $MB_LIMIT) _ ) Exit EndIf ;Wait a second Sleep(1000) WEnd
    1 point
  21. Answering my own question (again) Using SplashTextOn() solved my problem. Thanks for reading
    1 point
×
×
  • Create New...