Implemented %COMMANDER_SESSIONNAME% //was: "TC creates '%SESSIONNAME%' itself if not defined."

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
cpp64
Junior Member
Junior Member
Posts: 83
Joined: 2023-05-12, 16:03 UTC

Implemented %COMMANDER_SESSIONNAME% //was: "TC creates '%SESSIONNAME%' itself if not defined."

Post by *cpp64 »

Moved from bug reports to suggestions
ghisler(Author) wrote: 2023-06-01, 09:33 UTC I have added %COMMANDER_SESSIONNAME% now! .... (see below for more)




wincmd.ini
------------------------------
[Colors]
RedirectSection=%COMMANDER_INI%\..\Colors_%SESSIONNAME%.ini
------------------------------


When in admin, SESSIONNAME is not defined.

Then TC creates 'Colors_%SESSIONNAME%.ini' itself instaed of 'Colors_.ini'.


When editng 'Colors_%SESSIONNAME%.ini' not in admin and executed from TC,

Notepad can edit 'Colors_%SESSIONNAME%.ini' itself.

However, gvim edits 'Colors_Console.ini' instead of 'Colors_%SESSIONNAME%.ini'.

Also it generates a problem in cmd.

cmd expands the variable of pathname.


TC already has the ability that distinguish Admin Right. ( ^ in the titlebar )

Is it possible to add another TC variable like COMMANDER_SESSIONNAME (not empty) ?

in admin - COMMANDER_SESSIONNAME=admin
not in admin - COMMANDER_SESSIONNAME=user

or bool state.

It will be very useful when using it instead of SESSIONNAME.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48097
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 11.00b4] [RedirectSection] TC creates '%SESSIONNAME%' itself if 'SESSIONNAME' is not defined.

Post by *ghisler(Author) »

It's not a bug: When a variable doesn't exist, TC assumes that the user tried to use the actual string.
Is it possible to add another TC variable like COMMANDER_SESSIONNAME (not empty) ?
in admin - COMMANDER_SESSIONNAME=admin
not in admin - COMMANDER_SESSIONNAME=user
Interesting idea, would others find this useful too?
Author of Total Commander
https://www.ghisler.com
cpp64
Junior Member
Junior Member
Posts: 83
Joined: 2023-05-12, 16:03 UTC

Re: [TC 11.00b4] [RedirectSection] TC creates '%SESSIONNAME%' itself if 'SESSIONNAME' is not defined.

Post by *cpp64 »

ghisler(Author) wrote: 2023-05-25, 10:44 UTC Interesting idea, would others find this useful too?
// changing TC colors when in admin.
https://www.ghisler.ch/board/viewtopic.php?t=79128

In the post above, HolgerK has used SESSIONNAME with RedirectSection for more than 10 years.

I can execute TC as an admin with loading another wincmd.in using *.lnk, CreateProcess() with MANIFESTUAC, ShellExecute in *.vbs with TC "/i" option.

But my method has to use "/i" option.

I like his idea.

His idea is so brilliant.

But SESSIONNAME itself is not proper because it is not defiend (= empty) when in admin.

And this leads to an improper situation.

When editing Colors_%SESSIONNAME%.txt not in admin, Colors_Console.txt is edited, not "Colors_%SESSIONNAME%.txt" itself.

"%...%" means a Environment Variable, and should not be used in pathname.

This can cause malfunctions, especially in cmd when editing, reading and deleting from other apps.
Last edited by cpp64 on 2023-05-25, 16:45 UTC, edited 2 times in total.
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: [TC 11.00b4] [RedirectSection] TC creates '%SESSIONNAME%' itself if 'SESSIONNAME' is not defined.

Post by *Stefan2 »

cpp64 wrote: 2023-05-25, 13:31 UTC
"%...%" means a Environment Variable, and should not be used in pathname.
This is a perfect valid sign for an file name.
User can and will use that, for.example "Project ABCD 40%done_OutOf80%need.txt"


But a new EnvVar like %COMMANDER_Elevation%,
with return values of USER and ADMIN,
could be used to choose a situation depending task.

Like
MyCmd:
"colors_%COMMANDER_Elevation%.ini"
LOAD:
"colors_ADMIN.ini"
OR:
"colors_USER.ini"
depending if TC runs as admin or not.




 
cpp64
Junior Member
Junior Member
Posts: 83
Joined: 2023-05-12, 16:03 UTC

Re: [TC 11.00b4] [RedirectSection] TC creates '%SESSIONNAME%' itself if 'SESSIONNAME' is not defined.

Post by *cpp64 »

2Stefan2
Stefan2 wrote: 2023-05-25, 14:47 UTC This is a perfect valid sign for an file name.
User can and will use that, for.example "Project ABCD 40%done_OutOf80%need.txt"
You're right.

I forgot that % is well used in common situations.

But I think "%ENVIRONMENT_VARIABLE%" registered in system should not be used easily in pathname.

Because "%ENVIRONMENT_VARIABLE%" has values and can be replaced.

It can cause malfuntions.
User avatar
Dalai
Power Member
Power Member
Posts: 9402
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: [TC 11.00b4] [RedirectSection] TC creates '%SESSIONNAME%' itself if 'SESSIONNAME' is not defined.

Post by *Dalai »

2cpp64
It's not just the user that might do this. There is software which uses literal system variables in its path names. IIRC VMware uses a variable - don't remember which one, but it might have been %AppData% or something similar - for its virtual applications.

The suggestion sounds useful, though I don't know what to do if UAC is disabled, i.e. when two different accounts are used for user and admin respectively. Or what to do if TC is executed with different rights entirely like as SYSTEM or even TrustedInstaller (which is possible and it's good that it is!).

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
cpp64
Junior Member
Junior Member
Posts: 83
Joined: 2023-05-12, 16:03 UTC

Re: [TC 11.00b4] [RedirectSection] TC creates '%SESSIONNAME%' itself if 'SESSIONNAME' is not defined.

Post by *cpp64 »

2Dalai
Dalai wrote: 2023-05-25, 17:30 UTC The suggestion sounds useful, though I don't know what to do if UAC is disabled, i.e. when two different accounts are used for user and admin respectively. Or what to do if TC is executed with different rights entirely like as SYSTEM or even TrustedInstaller (which is possible and it's good that it is!).
COMMANDER_SESSIONNAME is jsut an alternative to SESSIONNAME.

As long as SESSIONNAME exists, There is no difference at all from using the SESSIONNAME.

But this removes the side effects of using SESSIONNAME.

It's better than nothing.

The reason using the SESSIONNAME in Colors section is "I am not a normal user when in admin by color, so be careful using TC when I am not a normal user".

In my opinion, there is no need to identify the Administrator, SYSTEM and Trustedinstaller.

I think the boolean status of "USER and ADMIN(Administrator, SYSTEM and Trustedinstaller)" is enough.
Last edited by cpp64 on 2023-06-01, 17:08 UTC, edited 1 time in total.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48097
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 11.00b4] [RedirectSection] TC creates '%SESSIONNAME%' itself if 'SESSIONNAME' is not defined.

Post by *ghisler(Author) »

I have added %COMMANDER_SESSIONNAME% now! I only set it on Windows NT-based systems (Windows NT, XP, Vista, 7, 8, 10, 11) because Windows 95/98/ME have a limited size environment.

It reflects the result of the function IsUserAnAdmin() on Windows XP and newer.
On older systems than XP, I call this code:
http://vbnet.mvps.org/code/network/isadministrator.htm
(I have already used both functions for years to signal in the title bar that TC is running as an admin)
Author of Total Commander
https://www.ghisler.com
cpp64
Junior Member
Junior Member
Posts: 83
Joined: 2023-05-12, 16:03 UTC

Re: [TC 11.00b4] [RedirectSection] TC creates '%SESSIONNAME%' itself if 'SESSIONNAME' is not defined.

Post by *cpp64 »

2ghisler
ghisler(Author) wrote: 2023-06-01, 09:33 UTC I have added %COMMANDER_SESSIONNAME% now! I only set it on Windows NT-based systems (Windows NT, XP, Vista, 7, 8, 10, 11) because Windows 95/98/ME have a limited size environment.

It reflects the result of the function IsUserAnAdmin() on Windows XP and newer.
On older systems than XP, I call this code:
http://vbnet.mvps.org/code/network/isadministrator.htm
(I have already used both functions for years to signal in the title bar that TC is running as an admin)
It works well.
Thank you. ghisler!

When cmd.exe is executed from Windows Terminal at taskbar icon, I found that the %SESSIONNAME% is not defined also when in normal user.

This means that if you run TC from a Windows terminal on a taskbar icon as a normal user, TC will use the ^%SESSIONNAME^% ini-file defined in "RedirectSection=..." in [Colors] section, not Console ini-file.

It means that using %SESSIONNAME% is not recommended for TC.

So I searched for an alternative to %SESSIONNAME% for cmd-AutoRun in registry

The result is IsUserAnAdmin().

But the IsUserAnAdmin() can be altered or unavailable later and it is jsut a wrapper of CheckTokenMembership().

Therefore, it is recommended to use CheckTokenMembership() rather than IsUserAnAdmin().

The links about IsUserAnAdmin() and CheckTokenMembership() are listed below.

// IsUserAnAdmin()
https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-isuseranadmin

IsUserAnAdmin is available for use in the operating systems specified in the Requirements section.
It may be altered or unavailable in subsequent versions.

This function is a wrapper for CheckTokenMembership.
It is recommended to call that function directly to determine Administrator group status rather than calling IsUserAnAdmin.

// CheckTokenMembership()
https://learn.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-checktokenmembership
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48097
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 11.00b4] [RedirectSection] TC creates '%SESSIONNAME%' itself if 'SESSIONNAME' is not defined.

Post by *ghisler(Author) »

Have you checked the code I'm using when IsUserAnAdmin() is unavailable? It uses GetTokenInformation and LookupAccountSid to check whether the user is a member of the administrators group.
Author of Total Commander
https://www.ghisler.com
Post Reply