Jump to content

Function for montor disk activity in % simil task manager performance tab


Recommended Posts

There numerous ways to get disk activity and performance counters.  One way to get such information is by querying Win32 Performance Counters using WMI.  The example script below monitors and displays performance counters from the Win32_PerfFormattedData_PerfDisk_LogicalDisk class.  The script is configured to update the information, roughly, 2 times per second.

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>
#include <Array.au3>

Global $gbQuitRequested = False

logical_disk_performance_example()

Func logical_disk_performance_example()
    Local $sStatsMsg   = ""
    Local $hSplashText = -1

    ;Set hotkey that stops script
    HotKeySet("{ESC}", quit_requested)

    ;Display splash window
    $hSplashText = SplashTextOn("Performance stats for drive C:  (Press ESC to QUIT)", _
                                "", _
                                350, 400, _
                                -1, -1, _
                                $DLG_TEXTLEFT + $DLG_MOVEABLE, _
                                "Consolas" _
                                )
    ;Get & display performance stats for logical drive C:
    With ObjGet("winmgmts:Win32_PerfFormattedData_PerfDisk_LogicalDisk='C:'")
        Do
            ;Build message
            $sStatsMsg =  "Free Megabytes:       " & .FreeMegabytes & @CRLF
            $sStatsMsg &= "%FreeSpace:           " & .PercentFreeSpace & @CRLF
            $sStatsMsg &= "%IdleTime:            " & .PercentIdleTime & @CRLF
            $sStatsMsg &= "%DiskReadTime:        " & .PercentDiskReadTime & @CRLF
            $sStatsMsg &= "%PercentDiskTime:     " & .PercentDiskTime & @CRLF
            $sStatsMsg &= "%DiskWriteTime:       " & .PercentDiskWriteTime & @CRLF
            $sStatsMsg &= @CRLF
            $sStatsMsg &= "DiskBytesPersec:      " & .DiskBytesPersec & @CRLF
            $sStatsMsg &= "DiskReadBytesPersec:  " & .DiskReadBytesPersec & @CRLF
            $sStatsMsg &= "DiskReadsPersec:      " & .DiskReadsPersec & @CRLF
            $sStatsMsg &= "DiskTransfersPersec:  " & .DiskTransfersPersec & @CRLF
            $sStatsMsg &= "DiskWriteBytesPersec: " & .DiskWriteBytesPersec & @CRLF
            $sStatsMsg &= "DiskWritesPersec:     " & .DiskWritesPersec & @CRLF

            ;Update splash window
            ControlSetText($hSplashText, "", "Static1", $sStatsMsg)

            Sleep(500)

            ;Get latest object stats
            .Refresh_
        Until $gbQuitRequested
    EndWith
EndFunc

Func quit_requested()
    $gbQuitRequested = True
EndFunc

Example display:

image.png.65423fa904551024a5e02eae63a19e10.png

Edited by TheXman
Link to comment
Share on other sites

thank you the problem is adapt to my script because i don't know to programming it, i use openai for make this with some problem made an almost working script.

I have difficulties in adapting the title of the window as I would like and the function of HDD activities remains fixed at 0%

Link to comment
Share on other sites

Unfortunately, I'm having a hard time understanding what you are trying to communicate.  I can't tell whether you are just saying what you had tried or whether you are asking for additional assistance.  Maybe you could use a translation tool instead of trying to write it yourself.  In any case, I provided the example for you to learn from and possibly build upon once you have developed a decent understanding of what it is doing.

1 hour ago, erik501 said:

i don't know to programming it

So what is you goal?  Is it to learn how to become a proficient scripter?  Or, is you goal to get someone to write your solution for you?  If you are requesting additional assistance and you are truly trying to learn, then you should start providing the script that isn't working, describing in detail the problem(s) you are having, and what the expected outcome should be.

1 hour ago, erik501 said:

HDD activities remains fixed at 0%

The information changes whenever the underlying data in the object changes.  If you want to see a lot of changing data, then do something that will cause a lot of reads and writes on the drive, like opening an app, refreshing your browser, or doing a ChkDsk command.  If the drive is not active, then the data in that particular object will not change.  If you want to see a lot of numbers, then use the raw data object (Win32_PerfRawData_PerfDisk_LogicalDisk) and calculate your own percentages.

image.png.c843f3349102398893ca7f5b9f7ab3c3.png

Edited by TheXman
Link to comment
Share on other sites

I tried to modify some things to adapt them for my purpose but I did not succeed. I am going crazy to create this script, if someone kindly offered to review it and adapt it to my use it would be great. This script launches Total Commander renowns him in Tcultrapack aims for Version.ini for n. Version then aims at tcultrapack.ini for the settings of what to view in the title. I would like the script to identify only the total commander window launched and modified only that, in the title I would like the values to be seen inside the parenthesis for example 😄 (free space %), (Activity%), 😧 (free space%), (Activity%), RAM Free: (RAM Free%) | CPU Used : (CPU%)

This script works but some details as bad impagination and hdd's activity is fixed to 0%

Func GetCpuUsage()
    Local $objWMI = ObjGet("winmgmts:\\.\root\cimv2")
    Local $cpuQuery = $objWMI.ExecQuery("Select * from Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
    Local $cpuUsage = 0
    For $cpu In $cpuQuery
        $cpuUsage = $cpu.PercentProcessorTime
    Next
    Return $cpuUsage
EndFunc


Func MemGetFreePhys()
Local $st_MemInfo = DllStructCreate("dword;dword;dword;dword;dword;dword")
Local $a_Return = DllCall("Kernel32.dll", "BOOL", "GlobalMemoryStatusEx", "struct*", $st_MemInfo)
If Not $a_Return[0] Then Return SetError(1, 0, 0)
Return DllStructGetData($st_MemInfo, 4)
EndFunc

Func GetTotalMemory()
    Local $memoryInfo = MemGetStats()
    Return $memoryInfo[1]
EndFunc

Func GetFreeMemory()
    Local $memoryInfo = MemGetStats()
    Return $memoryInfo[2]
EndFunc

Func GetDriveActivity($drive_letter)
    Local $hDevice = DllCall("kernel32.dll", "hwnd", "CreateFile", "str", "\\.\PhysicalDrive" & Asc(StringUpper($drive_letter)) - 64, _
                             "dword", 0, "dword", 3, "ptr", 0, "dword", 3, "dword", 0, "ptr", 0)
    If @error Or $hDevice[0] = -1 Then Return -1
    Local $tPerf = DllStructCreate("dword ReadCount; dword WriteCount; qword ReadBytes; qword WriteBytes; dword ReadTime; dword WriteTime; dword IdleTime; dword ReadQueue; dword WriteQueue; dword SplitCount; dword QueryTime")
    Local $iSize = DllCall("kernel32.dll", "dword", "DeviceIoControl", "hwnd", $hDevice[0], _
                           "dword", 0x70000, "ptr", 0, "dword", 0, "ptr", DllStructGetPtr($tPerf), "dword", DllStructGetSize($tPerf), _
                           "dword*", 0, "ptr", 0)
    DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice[0])
    If @error Or $iSize[0] = 0 Then Return -1
    Return DllStructGetData($tPerf, "ReadCount") + DllStructGetData($tPerf, "WriteCount")
EndFunc

Local $TCUltraPack_ini = @ScriptDir & "\TCUltraPack.ini"
Local $drives_freespace_option = IniRead($TCUltraPack_ini, "hdd", "freespace", "all")
Local $drives_activity_option = IniRead($TCUltraPack_ini, "hdd", "activity", "all")
Local $ram_option = IniRead($TCUltraPack_ini, "ram", "option", "1")
Local $cpu_option = IniRead($TCUltraPack_ini, "cpu", "option", "1")

If $drives_freespace_option = "all" Then $drives_freespace_option = "cdefghijklmnopqrstuvwxyz"
If $drives_activity_option = "all" Then $drives_activity_option = "cdefghijklmnopqrstuvwxyz"

$drives_freespace_array = StringSplit($drives_freespace_option, "", 1)
$drives_activity_array = StringSplit($drives_activity_option, "", 1)

Run(@ScriptDir & '\TOTALCMD64.EXE')
Sleep(100)

While WinExists("[CLASS:TTOTAL_CMD]")
Local $windows = WinList("[CLASS:TTOTAL_CMD]")
For $i = 1 To UBound($windows) - 1
Local $process_id = WinGetProcess($windows[$i][1])
If $process_id Then
Local $version = IniRead(@ScriptDir & "\version.ini", "Setup", "Version", "Default Value")
Local $new_title = "TC UltraPack X64 v" & $version
Local $drives_free_string = "", $drives_activity_string = "", $new_title_with_info = $new_title
For $j = 1 To UBound($drives_freespace_array) - 1
$drive_letter = $drives_freespace_array[$j]
If DriveStatus($drive_letter & ":\") = "READY" Then
$free_space_percent = Round(DriveSpaceFree($drive_letter & ":\") / DriveSpaceTotal($drive_letter & ":\") * 100, 2)
$drives_free_string &= StringUpper($drive_letter) & ": " & $free_space_percent & "%, "
EndIf
Next
For $j = 1 To UBound($drives_activity_array) - 1
$drive_letter = $drives_activity_array[$j]
If DriveStatus($drive_letter & ":\") = "READY" Then
$drive_activity = Round(GetDriveActivity($drive_letter) / 10, 2)
$drives_activity_string &= StringUpper($drive_letter) & ": " & $drive_activity & "%, "
EndIf
Next

If $drives_free_string <> "" And $drives_activity_string <> "" Then
$new_title_with_info &= " - HDD's (Free)(Act.): "
For $j = 1 To UBound($drives_freespace_array) - 1
$drive_letter = $drives_freespace_array[$j]
If DriveStatus($drive_letter & ":\") = "READY" Then
$free_space_percent = Round(DriveSpaceFree($drive_letter & ":\") / DriveSpaceTotal($drive_letter & ":\") * 100, 2)
$drive_activity = Round(GetDriveActivity($drive_letter) / 10, 2)
$new_title_with_info &= StringUpper($drive_letter) & ": " & $free_space_percent & "%, " & $drive_activity & "% | "
EndIf
Next
$new_title_with_info = StringTrimRight($new_title_with_info, 3)
ElseIf $drives_free_string <> "" Then
$new_title_with_info &= " - HDD's free space: " & StringTrimRight($drives_free_string, 2)
ElseIf $drives_activity_string <> "" Then
$new_title_with_info &= " - HDD's activity: " & StringTrimRight($drives_activity_string, 2)
EndIf

If $ram_option = "1" Then
$ram_free = Round(100 * GetFreeMemory() / GetTotalMemory(), 2)
$new_title_with_info &= " | RAM free: " & $ram_free & "%"
EndIf

If $cpu_option = "1" Then
$cpu_usage = Round(GetCpuUsage(), 2)
$new_title_with_info &= " | CPU used: " & $cpu_usage & "%"
EndIf

WinSetTitle($windows[$i][1], "", $new_title_with_info)
EndIf
Next
Sleep(1000)
WEnd

Screenshot_1.png

Edited by erik501
Link to comment
Share on other sites

As it says in my About Me, I'm only interest in helping people who are actively trying to learn, not passively seeking solutions & answers.  Hopefully, someone else will come around and do your work for you.  Given that this topic looks exactly like your previous topic, which I wish I had read first, it might be time to think about hiring someone to do it for you.  ;)

 

Link to comment
Share on other sites

This is not completely correct, in those messages I asked for some things that I then managed to do alone as you can also see the image and managed to obtain a satisfactory version of that project to which I now want to add the monotor function of the activity of the Hdd's that I have tried many times without ever being able to make it go. If someone wants to help me well hindsight continuing to bang my head until I succeed. I also leave you the script, work perfectly of the version without monitoring of the HDD's activities so see what I managed to do.

#NoTrayIcon

Func GetCpuUsage()
    Local $objWMI = ObjGet("winmgmts:\\.\root\cimv2")
    Local $cpuQuery = $objWMI.ExecQuery("Select * from Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
    Local $cpuUsage = 0
    For $cpu In $cpuQuery
        $cpuUsage = $cpu.PercentProcessorTime
    Next
    Return $cpuUsage
EndFunc


Func MemGetFreePhys()
Local $st_MemInfo = DllStructCreate("dword;dword;dword;dword;dword;dword")
Local $a_Return = DllCall("Kernel32.dll", "BOOL", "GlobalMemoryStatusEx", "struct*", $st_MemInfo)
If Not $a_Return[0] Then Return SetError(1, 0, 0)
Return DllStructGetData($st_MemInfo, 4)
EndFunc

Func GetTotalMemory()
    Local $memoryInfo = MemGetStats()
    Return $memoryInfo[1]
EndFunc

Func GetFreeMemory()
    Local $memoryInfo = MemGetStats()
    Return $memoryInfo[2]
EndFunc


Local $TCUltraPack_ini = @ScriptDir & "\TCUltraPack.ini"
Local $drives_option = IniRead($TCUltraPack_ini, "hdd", "option", "all")
Local $ram_option = IniRead($TCUltraPack_ini, "ram", "option", "1")
Local $cpu_option = IniRead($TCUltraPack_ini, "cpu", "option", "1")

If StringInStr($drives_option, "list") > 0 Then
    Local $drives_list = IniRead($TCUltraPack_ini, "hdd", "list", "")
    $drives_option = StringReplace($drives_list, ",", "")
EndIf

If $drives_option = "all" Then
    $drives_option = "cdefghijklmnopqrstuvwxyz"
EndIf

Run(@ScriptDir & '\TOTALCMD64.EXE')
Sleep(100)

If WinExists("[CLASS:TTOTAL_CMD]") Then
    Local $process_id = WinGetProcess(WinGetHandle("[CLASS:TTOTAL_CMD]"))
    Local $version = IniRead(@ScriptDir & "\version.ini", "Setup", "Version", "Default Value")
    Local $new_title = "TC UltraPack X64 v" & $version

    While WinExists("[CLASS:TTOTAL_CMD]")
        Sleep(1000)
        Local $windows = WinList("[CLASS:TTOTAL_CMD]")
        If IsArray($windows) Then
            For $i = 1 To UBound($windows) - 1
                If WinGetProcess($windows[$i][1]) = $process_id Then
                    Local $drives_string = ""
                    If $drives_option <> "" Then
                        For $j = 1 To StringLen($drives_option)
                            $drive_letter = StringMid($drives_option, $j, 1)
                            If DriveStatus($drive_letter & ":\") = "READY" Then
$drives_string &= StringUpper($drive_letter) & ": (" & Round(DriveSpaceFree($drive_letter & ":\") / DriveSpaceTotal($drive_letter & ":\") * 100, 2) & "%), "
                            EndIf
                        Next
                    EndIf
                    
                    $new_title_with_info = $new_title
                    
                    If $drives_option <> "" And $drives_string <> "" Then
                        $new_title_with_info &= " - Drive's free Space: " & StringTrimRight($drives_string, 2)
                    EndIf
                    
                    If $ram_option = "1" Then
                        $ram_free = Round(100 * GetFreeMemory() / GetTotalMemory(), 2)
                        $new_title_with_info &= " | RAM free: (" & Round($ram_free, 2) & "%)"
                    EndIf
                    
                    If $cpu_option = "1" Then
                        $cpu_usage = Round(GetCpuUsage(), 2)
                        $new_title_with_info &= " | Used CPU: (" & Round($cpu_usage, 2) & "%)"
                    EndIf
                    
                    WinSetTitle($windows[$i][1], "", $new_title_with_info)
                EndIf
            Next
        EndIf
    WEnd
EndIf

 

Link to comment
Share on other sites

2 hours ago, erik501 said:

If someone wants to help me well....

Ok. In "Local $TCUltraPack_ini" and all those Locals, they should be a Globals.
At "If WinExists("[CLASS:TTOTAL_CMD]") Then" the rest should go in a Function and don't declare a Local within a loop.

We all want to help, and do. If anyone shows suspicion is because your code looks very copy and paste. In any case, respect your elders ! :) 
( I'd call elders those in the forum with a lot of participation and/or post count ) 

I hope you find any sense of offence misplaced and keep presenting yourself kindly. 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Certainly respect for everyone is needed,Using the translator not all my sentences take on the same meaning if portrayed by the translator in my language. My code is a copy and paste has been done by me using GPT chat. If it weren't for chat gpt I would never have been able to do. It As I said I'm not a programmer but I want to be able to do this. At the moment I solved almost all the visualization problems only that the function of monitoring the hard disk in the title does not go remains stopped at -0.1.

I attach the updated script.

 

#include <TCfunction.au3>

Func GetDrivesActivityString($drives_activity_array)
    Local $drives_activity_string = ""
    For $j = 1 To UBound($drives_activity_array) - 1
        $drive_letter = $drives_activity_array[$j]
        If DriveStatus($drive_letter & ":\") = "READY" Then
            $drive_activity = Round(GetDriveActivity($drive_letter) / 10, 2)
            $drives_activity_string &= StringUpper($drive_letter) & ":(" & $drive_activity & "%) "
        EndIf
    Next
    If $drives_activity_string <> "" Then
        $drives_activity_string = "Activity: " & StringTrimRight($drives_activity_string, 1)
    EndIf
    Return $drives_activity_string
EndFunc

Local $TCUltraPack_ini = @ScriptDir & "\TCUltraPack.ini"
Local $drives_freespace_option = IniRead($TCUltraPack_ini, "hdd", "freespace", "all")
Local $drives_activity_option = IniRead($TCUltraPack_ini, "hdd", "activity", "all")
Local $ram_option = IniRead($TCUltraPack_ini, "ram", "option", "1")
Local $cpu_option = IniRead($TCUltraPack_ini, "cpu", "option", "1")

If $drives_freespace_option = "all" Then $drives_freespace_option = "cdefghijklmnopqrstuvwxyz"
If $drives_activity_option = "all" Then $drives_activity_option = "cdefghijklmnopqrstuvwxyz"

$drives_freespace_array = StringSplit($drives_freespace_option, "", 1)
$drives_activity_array = StringSplit($drives_activity_option, "", 1)

Local $pid =Run(@ScriptDir & '\TOTALCMD64.EXE')
Sleep(100)

While WinExists("[CLASS:TTOTAL_CMD]")
Local $windows = WinList("[CLASS:TTOTAL_CMD]")
For $i = 1 To UBound($windows) - 1
Local $process_id = WinGetProcess($windows[$i][1])
If $process_id = $pid Then
Local $version = IniRead(@ScriptDir & "\version.ini", "Setup", "Version", "Default Value")
Local $new_title = "TC UltraPack X64 v" & $version
Local $drives_free_string = "", $drives_activity_string = "", $new_title_with_info = $new_title
For $j = 1 To UBound($drives_freespace_array) - 1
$drive_letter = $drives_freespace_array[$j]
If DriveStatus($drive_letter & ":\") = "READY" Then
$free_space_percent = Round(DriveSpaceFree($drive_letter & ":\") / DriveSpaceTotal($drive_letter & ":\") * 100, 2)
$drives_free_string &= StringUpper($drive_letter) & ": (" & $free_space_percent & "%) "
EndIf
Next
For $j = 1 To UBound($drives_activity_array) - 1
$drive_letter = $drives_activity_array[$j]
If DriveStatus($drive_letter & ":\") = "READY" Then
$drive_activity = Round(GetDriveActivity($drive_letter) / 10, 2)
$drives_activity_string &= StringUpper($drive_letter) & ":(" & $drive_activity & "%)"
EndIf
Next

If $drives_free_string <> "" And $drives_activity_string <> "" Then
$new_title_with_info &= " - HDD's (Free)(Act.): "
For $j = 1 To UBound($drives_freespace_array) - 1
$drive_letter = $drives_freespace_array[$j]
If DriveStatus($drive_letter & ":\") = "READY" Then
$free_space_percent = Round(DriveSpaceFree($drive_letter & ":\") / DriveSpaceTotal($drive_letter & ":\") * 100, 2)
$drive_activity = Round(GetDriveActivity($drive_letter) / 10, 2)
$new_title_with_info &= StringUpper($drive_letter) & ": (" & $free_space_percent & "% )(" & $drive_activity & ") | "
EndIf
Next
$new_title_with_info = StringTrimRight($new_title_with_info, 3)
ElseIf $drives_free_string <> "" Then
$new_title_with_info &= " - HDD's free Space: " & StringTrimRight($drives_free_string, 2) & ")"

ElseIf $drives_activity_string <> "" Then
$new_title_with_info = "Activity: " & StringReplace(StringTrimRight($drives_activity_string, 2), " ", "") & ")"
EndIf

If $ram_option = "1" Then
$ram_free = Round(100 * GetFreeMemory() / GetTotalMemory(), 2)
$new_title_with_info &= " | RAM Free: (" & $ram_free & "%)"
EndIf

If $cpu_option = "1" Then
$cpu_usage = Round(GetCpuUsage(), 2)
$new_title_with_info &= " | CPU Used:( " & $cpu_usage & "%)"
EndIf

WinSetTitle($windows[$i][1], "", $new_title_with_info)
EndIf
Next
Sleep(1000)
WEnd

 

Edited by erik501
Link to comment
Share on other sites

51 minutes ago, erik501 said:

If it weren't for chat gpt I would never have been able to do.

I will have to disagree. The bot/AI is an aid, but the concepts, is you who needs to know them.
The advise I gave you, you did not apply it. Maybe you can tell or train the AI to use it.
In any case, you show to have a good head on your shoulders and you'll come around ( applying best practices ) once you gain sufficient experience.
I know how pressing a desired project can get when we first start. We all go thru these "growing pains" while learning something new. 
Have fun coding and keep at it.

And thanks for posting the evolution on the project and do post the final code.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

I did not apply your advice because I had not read the message. The script has not yet finished because it does not work the HDD activity remains fixed at 0.1.CHAT GPT always stops before finishing the work and I must Try to ask the correct question and add the various parts. He has been working enough for us about a month.

Link to comment
Share on other sites

This script should be the final version of my work, it is missing just testing it for some time to discover any errors.

Func GetCpuUsage()
    Local $objWMI = ObjGet("winmgmts:\\.\root\cimv2")
    Local $cpuQuery = $objWMI.ExecQuery("Select * from Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
    Local $cpuUsage = 0
    For $cpu In $cpuQuery
        $cpuUsage = $cpu.PercentProcessorTime
    Next
    Return $cpuUsage
EndFunc


Func MemGetFreePhys()
Local $st_MemInfo = DllStructCreate("dword;dword;dword;dword;dword;dword")
Local $a_Return = DllCall("Kernel32.dll", "BOOL", "GlobalMemoryStatusEx", "struct*", $st_MemInfo)
If Not $a_Return[0] Then Return SetError(1, 0, 0)
Return DllStructGetData($st_MemInfo, 4)
EndFunc

Func GetTotalMemory()
    Local $memoryInfo = MemGetStats()
    Return $memoryInfo[1]
EndFunc

Func GetFreeMemory()
    Local $memoryInfo = MemGetStats()
    Return $memoryInfo[2]
EndFunc


Func GetDriveActivity($drive_letter)
Local $objWMI = ObjGet("winmgmts:\\.\root\cimv2")
Local $drive_activity = 0
If DriveStatus($drive_letter & ":\") = "READY" Then
$drive_activity_query = $objWMI.ExecQuery("SELECT PercentDiskTime FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk WHERE Name='" & $drive_letter & ":'")
For $drive In $drive_activity_query
$drive_activity = Round($drive.PercentDiskTime / 10)
If $drive_activity > 100 Then $drive_activity = 100
Next
EndIf
Return StringFormat("%02d", $drive_activity)
EndFunc
Local $TCUltraPack_ini = @ScriptDir & "\TCUltraPack.ini"
Local $drives_freespace_option = IniRead($TCUltraPack_ini, "hdd", "freespace", "all")
Local $drives_activity_option = IniRead($TCUltraPack_ini, "hdd", "activity", "all")
Local $drives_display_option = IniRead($TCUltraPack_ini, "hdd", "display", "all")
Local $ram_option = IniRead($TCUltraPack_ini, "ram", "option", "1")
Local $cpu_option = IniRead($TCUltraPack_ini, "cpu", "option", "1")

If $drives_freespace_option = "all" Then $drives_freespace_option = "cdefghijklmnopqrstuvwxyz"
If $drives_activity_option = "all" Then $drives_activity_option = "cdefghijklmnopqrstuvwxyz"
If $drives_display_option = "all" Then $drives_display_option = "cdefghijklmnopqrstuvwxyz"

$drives_freespace_array = StringSplit($drives_freespace_option, "", 1)
$drives_activity_array = StringSplit($drives_activity_option, "", 1)
$drives_display_array = StringSplit($drives_display_option, "", 1)

Local $pid = Run(@ScriptDir & '\TOTALCMD64.EXE')
Sleep(100)

While WinExists("[CLASS:TTOTAL_CMD]")
Local $windows = WinList("[CLASS:TTOTAL_CMD]")
For $i = 1 To UBound($windows) - 1
Local $process_id = WinGetProcess($windows[$i][1])
If $process_id = $pid Then
Local $version = IniRead(@ScriptDir & "\version.ini", "Setup", "Version", "Default Value")
Local $new_title = "TC UltraPack X64 v" & $version
Local $drives_free_string = "", $drives_activity_string = "", $drives_display_string = "", $new_title_with_info = $new_title
For $j = 1 To UBound($drives_display_array) - 1
$drive_letter = $drives_display_array[$j]
If DriveStatus($drive_letter & ":\") = "READY" Then
$drives_display_string &= " | " & StringUpper($drive_letter)
If UBound($drives_activity_array) > 1 And $drives_activity_option <> "0" Then
If StringInStr($drives_activity_option, $drive_letter) > 0 Then
$drive_activity = GetDriveActivity($drive_letter)
$drives_display_string &= ":(" & $drive_activity & "%)"
EndIf
EndIf
If $drives_freespace_option <> "0" And $drives_freespace_option <> "all" Then
If StringInStr($drives_freespace_option, $drive_letter) > 0 Then
$free_space_percent = Round(DriveSpaceFree($drive_letter & ":\") / DriveSpaceTotal($drive_letter & ":\") * 100, 2)
$drives_display_string &= " (" & $free_space_percent & "%)"
EndIf
EndIf
EndIf
Next
If $drives_display_string <> "" Then
$new_title_with_info &= "  HDD's"
If $drives_activity_option <> "0" And $drives_activity_option <> "all" Then
$new_title_with_info &= " (Activity)"
EndIf
If $drives_freespace_option <> "0" And $drives_freespace_option <> "all" Then
$new_title_with_info &= " (Free Space)"
EndIf
$new_title_with_info &= " : " & StringTrimLeft($drives_display_string, 3)
EndIf
If $ram_option = "1" Then
$ram_free = Round(100 * GetFreeMemory() / GetTotalMemory(), 2)
$new_title_with_info &= " | RAM Free: (" & $ram_free & "%)"
EndIf
If $cpu_option = "1" Then
$cpu_usage = Round(GetCpuUsage(), 2)
$new_title_with_info &= " | CPU Used:( " & $cpu_usage & "%)"
EndIf
WinSetTitle($windows[$i][1], "", $new_title_with_info)
EndIf
Next
Sleep(100)
WEnd

 

Link to comment
Share on other sites

I've plugged in a few things and added display options. However, there is still a problem with displaying the HDD if the letters do not match between free spaces and the activities cannot be seen correctly Freespace C, D Activity E, F can be seen c Freespace Activity d Freespace Activity E F cannot be seen I have looked for various tried and tested solutions it changes but I don't understand if it's an array or string problem

Where is I wrong?

Thanks

#include <TCfunction.au3>

TrayIcon()

Local $TCUltraPack_ini = @ScriptDir & "\TCUltraPack.ini"

SetDefaultOptions()

Local $drives_freespace_option = IniRead($TCUltraPack_ini, "HDD", "Freespace", "all")
Local $drives_activity_option = IniRead($TCUltraPack_ini, "HDD", "Activity", "all")
Local $visualization_option = IniRead($TCUltraPack_ini, "HDD", "Visualization", "0")
Local $ram_option = IniRead($TCUltraPack_ini, "ram", "option", "1")
Local $cpu_option = IniRead($TCUltraPack_ini, "cpu", "option", "1")
Local $tray_option = IniRead($TCUltraPack_ini, "tray", "option", "1")
SetDefaultOptions()
If $drives_freespace_option = "all" Then
    $drives_freespace_option = "cdefghijklmnopqrstuvwxyz"
EndIf

If $drives_activity_option = "all" Then
    $drives_activity_option = "cdefghijklmnopqrstuvwxyz"
EndIf

$drives_freespace_array = StringSplit($drives_freespace_option, "", 1)
$drives_activity_array = StringSplit($drives_activity_option, "", 1)

$pid = Run(@ScriptDir & '\TOTALCMD64.EXE')
Sleep(100)

While True
    Local $windows = WinList("[CLASS:TTOTAL_CMD]")
    Local $found = False
    
    For $i = 1 To UBound($windows) - 1
        Local $process_id = WinGetProcess($windows[$i][1])
        
        If $process_id = $pid Then
            $found = True
            Local $version = IniRead(@ScriptDir & "\version.ini", "Setup", "Version", "Default Value")
            Local $new_title = "TC UltraPack X64 v" & $version
            Local $drives_display_string = "", $new_title_with_info = $new_title
            
            If $visualization_option = "0" Then
                For $j = 1 To UBound($drives_freespace_array) - 1
                    $drive_letter = $drives_freespace_array[$j]
                    
                    If DriveStatus($drive_letter & ":\") = "READY" Then
                        $free_space_percent = Round(DriveSpaceFree($drive_letter & ":\") / DriveSpaceTotal($drive_letter & ":\") * 100, 2)
                        $drive_activity = GetDriveActivity($drive_letter)
                        $drives_display_string &= " | " & StringUpper($drive_letter) & ":(" & $free_space_percent & "%)(" & $drive_activity & "%)"
                    EndIf
                Next
                
                If $drives_display_string <> "" Then
                    $new_title_with_info &= " - HDD's"
                    $new_title_with_info &= " (FreeSpace)(Activity): " & StringTrimLeft($drives_display_string, 3)
                EndIf
                
            ElseIf $visualization_option = "1" Then
                For $j = 1 To UBound($drives_freespace_array) - 1
                    $drive_letter = $drives_freespace_array[$j]
                    
                    If DriveStatus($drive_letter & ":\") = "READY" Then
                        $free_space_percent = Round(DriveSpaceFree($drive_letter & ":\") / DriveSpaceTotal($drive_letter & ":\") * 100, 2)
                        $drives_display_string &= " | " & StringUpper($drive_letter) & ":(" & $free_space_percent & "%)"
                    EndIf
                Next
                
                For $j = 1 To UBound($drives_activity_array) - 1
                    $drive_letter = $drives_activity_array[$j]
                    
                    If DriveStatus($drive_letter & ":\") = "READY" Then
                        $drive_activity = GetDriveActivity($drive_letter)
                        $drives_display_string &= " | " & StringUpper($drive_letter) & ":(" & $drive_activity & "%)"
                    EndIf
                Next
                
                If $drives_display_string <> "" Then
                    $new_title_with_info &= " - HDD's"
                    $new_title_with_info &= " (FreeSpace)(Activity): " & StringTrimLeft($drives_display_string, 3)
                EndIf
                
            ElseIf $visualization_option = "2" Then
                For $j = 1 To UBound($drives_freespace_array) - 1
                    $drive_letter = $drives_freespace_array[$j]
                    
                    If DriveStatus($drive_letter & ":\") = "READY" Then
                        $free_space_percent = Round(DriveSpaceFree($drive_letter & ":\") / DriveSpaceTotal($drive_letter & ":\") * 100, 2)
                        $drive_activity = GetDriveActivity($drive_letter)
                        $drives_display_string &= " | " & StringUpper($drive_letter) & ":(" & $drive_activity & "%)(" & $free_space_percent & "%)"
                    EndIf
                Next
                
                If $drives_display_string <> "" Then
                    $new_title_with_info &= " - HDD's"
                    $new_title_with_info &= " (Activity)(FreeSpace): " & StringTrimLeft($drives_display_string, 3)
                EndIf
                
            EndIf
            
            If $ram_option = "1" Then
                $ram_free = Round(100 * GetFreeMemory() / GetTotalMemory(), 2)
                $new_title_with_info &= " | RAM Free: (" & $ram_free & "%)"
            EndIf
            
            If $cpu_option = "1" Then
                $cpu_usage = Round(GetCpuUsage(), 2)
                $new_title_with_info &= " | CPU Used:( " & $cpu_usage & "%)"
            EndIf
            
            $original_title = WinGetTitle($windows[$i][1])
            $number_in_brackets = StringRegExp($original_title, "\[(\d+)\]", 1)
            
            If IsArray($number_in_brackets) Then
                $new_title_with_info = "[" & $number_in_brackets[0] & "] " & $new_title_with_info
            EndIf
            
            WinSetTitle($windows[$i][1], "", $new_title_with_info)
        EndIf
    Next
    
    Sleep(1000)
    If Not $found Then Exit
WEnd

tcfunction.au3

Func GetCpuUsage()
    Local $objWMI = ObjGet("winmgmts:\\.\root\cimv2")
    Local $cpuQuery = $objWMI.ExecQuery("Select * from Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
    Local $cpuUsage = 0
    For $cpu In $cpuQuery
        $cpuUsage = $cpu.PercentProcessorTime
    Next
    Return $cpuUsage
EndFunc


Func MemGetFreePhys()
Local $st_MemInfo = DllStructCreate("dword;dword;dword;dword;dword;dword")
Local $a_Return = DllCall("Kernel32.dll", "BOOL", "GlobalMemoryStatusEx", "struct*", $st_MemInfo)
If Not $a_Return[0] Then Return SetError(1, 0, 0)
Return DllStructGetData($st_MemInfo, 4)
EndFunc

Func GetTotalMemory()
    Local $memoryInfo = MemGetStats()
    Return $memoryInfo[1]
EndFunc

Func GetFreeMemory()
    Local $memoryInfo = MemGetStats()
    Return $memoryInfo[2]
EndFunc


Func GetDriveActivity($drive_letter)
Local $objWMI = ObjGet("winmgmts:\\.\root\cimv2")
Local $drive_activity = 0
If DriveStatus($drive_letter & ":\") = "READY" Then
$drive_activity_query = $objWMI.ExecQuery("SELECT PercentDiskTime FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk WHERE Name='" & $drive_letter & ":'")
For $drive In $drive_activity_query
$drive_activity = Round($drive.PercentDiskTime / 10)
If $drive_activity > 100 Then $drive_activity = 100
Next
EndIf
Return StringFormat("%02d", $drive_activity)
EndFunc


Func TrayIcon()
   Local $iniFile = "TCUltraPack.ini"
   Local $trayOption = IniRead($iniFile, "Tray", "Option", "")
      If $trayOption = 1 Then
      TraySetState()
   ElseIf $trayOption = 0 Then
      TraySetState(2)
EndIf
EndFunc

 

 

 

 

Edited by erik501
Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...