[WDX] Autorun Plugin: Run commands/set envvars on TC start

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
Fla$her
Power Member
Power Member
Posts: 2981
Joined: 2020-01-18, 04:03 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *Fla$her »

2funkymonk
I have good news. Among the many useful novelties (see history), Autorun implements the WMIQuery object, with which you can get data from a collection on request (example in the help), which is significantly faster for the second and subsequent elements than using GetWMIValue.
Both functions now have the ability to specify a namespace, get the items count, and select an item by index.
The functions I requested for fast and resource-saving receipt of various information for threading operations are also implemented.
Try an analog of the above example with localization of dynamically output data:

Code: Select all

LoadLibrary Plugins\Autorun_Tweaks.dll
LoadLibrary Plugins\Autorun_Sysinfo.dll
LoadLibrary Plugins\Autorun_Runtime.dll

###################################### HOTKEYS ######################################
# Ctrl+Shift+R — restart script
SetHotkeyAction /H:R /K:C /K:S RestartScript

# Shift+F11 — show/hide header with updated stats by starting and stopping the thread
SetHotkeyAction /H:F11 /K:S ToggleCaption
#####################################################################################

Global Units, sUnit, WS_CAPTION = 0x00C00000
If Not AUTORUN_RESTARTCOUNT Then SetEnv('Title', WinGetText())
If AUTORUN_TCLANG = 'eng' Then
   sUnit = ' kB/s'
Else
   Units = StrFormat('LU:%s,%s,%s,%s,%s', LngRead(1450, _
   COMMANDER_PATH & '\Language\' & IniRead('~/R', _
   COMMANDER_INI, 'Configuration', 'LanguageIni')), _
   LngRead(1451), LngRead(1452), LngRead(1453), LngRead(1449))
EndIf

If WinHasStyle(WS_CAPTION) Then RunThread AutoUpdateHeaderStats

Func ToggleCaption
   WinSetStyle(WS_CAPTION, 8)
   WinRedraw
   If WinHasStyle(WS_CAPTION) Then RunThread AutoUpdateHeaderStats
EndFunc

Func AutoUpdateHeaderStats
   Local RSpeed, NSpeed
   While 1
      If Not WinHasStyle(WS_CAPTION) Then Return
      GetNetSpeed RSpeed NSpeed
      WinSetText(Title & ' | ' & Date('d MMMM') & ' ' & Time() & ' | Free system drive space: ' & _
      SizeFormat(GetDriveSpace(SystemDrive, 2), 1, 'G', 2, '', Units) & ' | RAM: ' & GetMemstats() & _
      '% | CPU: ' & GetCPUUsage() & '% | Net in: ' & RSpeed & ' | Net out: ' & NSpeed)
      Sleep 1000
   Wend
EndFunc

Func GetNetSpeed(ByRef RSpeed, ByRef NSpeed)
   Static ITF_Id = GetNetInterface()
   If ITF_Id = -1 Then Return
   Static nPrevRecv = GetNetInterfaceInfo(ITF_Id, 'Recv'), nPrevSend = GetNetInterfaceInfo(ITF_Id, 'Sent')
   Local nRecv = GetNetInterfaceInfo(ITF_Id, 'Recv'), nSend = GetNetInterfaceInfo(ITF_Id, 'Sent')
   RSpeed = SizeFormat(nRecv - nPrevRecv, 0, '', 2, 0) & sUnit
   NSpeed = SizeFormat(nSend - nPrevSend, 0, '', 2, 0) & sUnit
   nPrevRecv = nRecv
   nPrevSend = nSend
EndFunc
Some useful information can be obtained by the GetCoreTempInfo function (CPUSpeed in MHz, for example), but it's missing in the example due to the need to use a third-party program.
With the script restart hotkey, you can test changes and additions without having to restart TC and apply cm_UnloadPlugins, which may cause a hang (not due to Autorun).
In this case, the AUTORUN_RESTARTCOUNT counter serves as an auxiliary variable for this. In the example, it is used for the Title environment variable.
funkymonk wrote: 2023-04-27, 10:18 UTC As long as this thread (and *only* this one) runs, TC crashes when cm_UnloadPlugins is called.
cm_UnloadPlugins should no longer cause TC crashes when threads are running. Check it out.

Download Autorun 2.2.13 beta
Last edited by Fla$her on 2024-08-25, 14:53 UTC, edited 1 time in total.
Overquoting is evil! 👎
User avatar
funkymonk
Senior Member
Senior Member
Posts: 491
Joined: 2013-12-04, 09:56 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *funkymonk »

Hi Fla$her

Thank you for the update. I have checked the history and it seems there is more interesting news.
Actually, I have very briefly tried some new features since you have updated the English documentation in 2.2.12 beta.

Unfortunately, I'm a bit busy these days but I can offer to give some feedback on the changes once I have updated my autorun script in the next days.
I can't promise a quick response, but I'll take care of it. I hope that helps somehow.

In any case, the new versions look very promising!

Thank you very much!
Fla$her
Power Member
Power Member
Posts: 2981
Joined: 2020-01-18, 04:03 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *Fla$her »

2funkymonk
You're welcome.
I have checked the history and it seems there is more interesting news.
I don't know how much more interesting the others are (уou can share), but I have answered your latest requests first of all. In the proposed script, you can already see some of these useful novelties.
With the new version, the plugin is in addition able to duplicate almost all the functionality of TCFS2 (and even a bit more).
Actually, I have very briefly tried some new features since you have updated the English documentation in 2.2.12 beta.
I'm just a co-participant. CHM is updated by Loopback.
but I can offer to give some feedback on the changes once I have updated my autorun script in the next days.
I don't mind. But first of all, I would like you to test what we discussed — the proposed script with SysInfo functions and some tests with WMIQuery. Preferably with GetUptime.
In any case, the new versions look very promising!
I agree. :)
Overquoting is evil! 👎
User avatar
funkymonk
Senior Member
Senior Member
Posts: 491
Joined: 2013-12-04, 09:56 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *funkymonk »

A quick question about WMIQuery and GetValue (as the documentation is still incomplete).

Does GetValue support arrays of some type as return value?

In the following code, GetValue('Caption') works as expected since the result is a string.
However, for GetValue('IPAddress') and GetValue('DefaultIPGateway') an array of ip addresses should be returned.

Code: Select all

Func getAllIPAddresses
  Outstr = ""
  wq = WMIQuery()
  wq.Query('SELECT * FROM Win32_NetworkAdapterConfiguration')
  
  While (wq.Next())
    ip1 = wq.GetValue('IPAddress')
    ip2 = wq.GetValue('IPAddress[0]')
    ip3 = List(wq.GetValue('IPAddress'))
    gw  = wq.GetValue('DefaultIPGateway')
    cap = wq.GetValue('Caption')
    Outstr = Outstr & wq.Index & ': ' & ip1 & ' / ' & ip2 & ' / ' & ip3[0] & ' / ' & gw & ' / ' & cap & auCRLF
  Wend
  
  MsgBox(Outstr)
EndFunc
I have briefly tried to use List objects, indexed access, and some other typical syntax (not all shown above) but I cannot get the individual array elements (i.e., ip addresses).

This is the output: https://ibb.co/c3Wc5rX

Since the documentation is not yet complete and I don't want to "try and error" things that are *maybe* not yet implemented:
How to access such arrays?

Hopefully I didn't overlook something in a rush.
User avatar
funkymonk
Senior Member
Senior Member
Posts: 491
Joined: 2013-12-04, 09:56 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *funkymonk »

Another thing:
- fixed TC crash when unloading a plugin using the cm_UnloadPlugins command when using RunThread
cm_UnloadPlugins should no longer cause TC crashes when threads are running. Check it out.
This seems to to be fixed in general. In fact, it appears that the threads are simply stopped before unloading autorun. That's ok.

However, in combination with "Pragma AutorunBlockUnload", I would expect the threads to continue. But apparently they don't.
Since autorun itself blocks unloading and continues running, why should the threads be stopped?
Fla$her
Power Member
Power Member
Posts: 2981
Joined: 2020-01-18, 04:03 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *Fla$her »

2funkymonk
Does GetValue support arrays of some type as return value?
Not yet.
Since the documentation is not yet complete and I don't want to "try and error" things that are *maybe* not yet implemented:
How to access such arrays?
In fact, the WMIQuery documentation (excluding examples) is complete. Working with the resulting arrays in values was not actualized, although it came to mind earlier. It will be considered.

Some notes:
  1. Instead of Outstr = "", it's better to write Local Outstr.
  2. In the help example, the WMIQuery() constructor is declared globally for a reason, since it doesn't require repeated calls, therefore it is incorrect to write it to the function.
  3. You don't need to put wq.Next() in parentheses.
Since autorun itself blocks unloading and continues running, why should the threads be stopped?
Perhaps it was not taken into account. I'll find out.
Overquoting is evil! 👎
User avatar
funkymonk
Senior Member
Senior Member
Posts: 491
Joined: 2013-12-04, 09:56 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *funkymonk »

@Fla$her

Thank you for the quick response.

Regarding WMIQuery / GetValue: it would be great to have array support (or some other way to process such arrays)...
BTW: GetWMIValue should be improved in the same regard:
SomeVAR = GetWMIValue('Caption', 'SELECT * FROM Win32_NetworkAdapterConfiguration', '', someNumber) --> ok
SomeVAR = GetWMIValue('IPAddress', 'SELECT * FROM Win32_NetworkAdapterConfiguration', '', someNumber) --> error, as described above

Regarding your notes: right. I need to tidy up anyways...

Regarding Threads / AutorunBlockUnload: Let's see what can be found out...
Fla$her
Power Member
Power Member
Posts: 2981
Joined: 2020-01-18, 04:03 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *Fla$her »

2funkymonk
The thread problem seems to have arisen from this:

Code: Select all

* starting and stopping script moved from DllMain to ContentSetDefaultParams and ContentPluginUnloading functions
So far, everything is under consideration.

In the meantime, we have one unresolved issue:
Fla$her wrote: 2024-08-21, 14:49 UTC But first of all, I would like you to test what we discussed — the proposed script with SysInfo functions
I hope you won't ignore it.
Overquoting is evil! 👎
User avatar
funkymonk
Senior Member
Senior Member
Posts: 491
Joined: 2013-12-04, 09:56 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *funkymonk »

Hi FLa$her

I have tested the code from https://www.ghisler.ch/board/viewtopic.php?t=32427&start=120#p458832.
The script and the new functions (including functionality related to RestartScript) seem to work in general. However, I have found some issues so far:
  1. Not a problem with autorun but with the script: According to help_en.chm, LngRead requires a filename upon the first call. Thus, I had to change the script as follows to work:

    Code: Select all

    If AUTORUN_TCLANG = 'eng' Then
       sUnit = ' kB/s'
    Else
       sUnit = ' ' & LngRead(1657, "*"&AUTORUN_TCLANG)
       Units = StrFormat('LU:%s,%s,%s,%s,%s', LngRead(1450), LngRead(1451), LngRead(1452), LngRead(1453), LngRead(1449))
       ERROR = 0
       MsgBox(Units)
    EndIf
    
  2. It seems that Time() returns UTC+0 time independent from the system time zone. help_en.chm has no information about using time zones.

    I will do more testing soon.
Meanwhile, I have already changed parts of my own autorun script. The new functions I have used so far seem to work as expected.
I'm not yet done with my changes/tests but I will certainly post issues once I find them.

So far, I just want to report some missing English documentation for

Code: Select all

2.2.13 beta
+ Runtime: ClipGet, ClipPut
+ Runtime: WinGetPos, WinSetPos, WinSetState, index 7 was added to WinGetState
+ API: SetVar function can set variables in local scope
+ /ELEVATE switch in ShellExec for forced privilege escalation
And: In autorun.lng, the [DEU] section is outdated/incomplete/buggy. Is there already a more recent German translation?
Fla$her
Power Member
Power Member
Posts: 2981
Joined: 2020-01-18, 04:03 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *Fla$her »

2funkymonk
Thanks for the tests! Is the rest of the title displayed correctly? Do the hotkeys work?
1. I just forgot to insert one line. Sorry. Fixed the code. Your option is not always suitable, because there may be different versions of <lang>.lng in the same folder.
2. It's strange that I didn't notice it myself before. We'll figure it out.
funkymonk wrote: 2024-08-23, 20:07 UTC So far, I just want to report some missing English documentation for

2.2.13 beta
+ Runtime: ClipGet, ClipPut
+ Runtime: WinGetPos, WinSetPos, WinSetState, index 7 was added to WinGetState
+ API: SetVar function can set variables in local scope
+ /ELEVATE switch in ShellExec for forced privilege escalation
Good. We will update the help later. I crossed out the unnecessary ones.
There are many things that have not yet been completed. This will be finalized in betas.
funkymonk wrote: 2024-08-23, 20:07 UTC I'm not yet done with my changes/tests but I will certainly post issues once I find them.
Good. Thanks for the help!
funkymonk wrote: 2024-08-23, 20:07 UTC And: In autorun.lng, the [DEU] section is outdated/incomplete/buggy. Is there already a more recent German translation?
I know about it. We will try to add to the next version.
Overquoting is evil! 👎
User avatar
funkymonk
Senior Member
Senior Member
Posts: 491
Joined: 2013-12-04, 09:56 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *funkymonk »

Another thing or suggestion:

It is about configuring/saving the position of the "copy in background" windows.
I have posted this TC suggestion some time ago, but there is currently no native support in TC: https://www.ghisler.ch/board/viewtopic.php?t=81869

At the moment, the "copy in background" windows are placed behind the TC main window. Starting from the top left corner, every new window gets placed next to the previous one. This is ok in general, but in a multi-monitor environment I would like to have these windows on another screen.

Can the ModifyDialogs plugin help with that?
There is some special windows defined for use with AddDialog (e.g., DIALOG_COPYMOVE) but nothing seems to relate to the "copy in background" windows.
It would be great if the "copy in background" window positions could be saved. Of course, since these windows pile up next to each other, there is no single position.
But: Would it be possible to define a screen number for these windows or the position of the first of these windows?

I have thought about scripting something but couldn't fine the time yet.
User avatar
funkymonk
Senior Member
Senior Member
Posts: 491
Joined: 2013-12-04, 09:56 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *funkymonk »

Fla$her wrote: 2024-08-25, 15:13 UTC Thanks for the tests! Is the rest of the title displayed correctly? Do the hotkeys work?
Looks good so far. I have played around with the hotkeys and mouse actions and could not find any problem for now.
Fla$her wrote: 2024-08-25, 15:13 UTC Your option is not always suitable, because there may be different versions of <lang>.lng in the same folder.
Sure. It was just a quick fix.
Fla$her
Power Member
Power Member
Posts: 2981
Joined: 2020-01-18, 04:03 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *Fla$her »

funkymonk wrote: 2024-08-25, 16:03 UTC Another thing or suggestion:
This has been discussed for a long time ago, but no solution has been found due to the inability to identify such windows.
funkymonk wrote: 2024-08-25, 16:05 UTC Looks good so far. I have played around with the hotkeys and mouse actions and could not find any problem for now.
Umm. There are no mouse actions in my code.
Overquoting is evil! 👎
User avatar
funkymonk
Senior Member
Senior Member
Posts: 491
Joined: 2013-12-04, 09:56 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *funkymonk »

Fla$her wrote: 2024-08-25, 16:20 UTC
funkymonk wrote: 2024-08-25, 16:03 UTC Another thing or suggestion:
This has been discussed for a long time ago, but no solution has been found due to the inability to identify such windows.
Ok. I thought so. This exact problem (window identification) is exactly the reason why I haven't invested more time so far.
Fla$her wrote: 2024-08-25, 16:20 UTC
funkymonk wrote: 2024-08-25, 16:05 UTC Looks good so far. I have played around with the hotkeys and mouse actions and could not find any problem for now.
Umm. There are no mouse actions in my code.
Not in your code. But in mine.
Fla$her
Power Member
Power Member
Posts: 2981
Joined: 2020-01-18, 04:03 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC start

Post by *Fla$her »

funkymonk wrote: 2024-08-25, 18:05 UTC Not in your code. But in mine.
I haven't asked you about how the SetHotkeyAction or ControlSetMouseAction commands work. Some keys have their own difficulties.
I'm just interested in how my code works in the ### HOTKEYS ### part.
Overquoting is evil! 👎
Post Reply