Current directory is wrong when "Run as different user.

This forum contains bug reports from previous beta tests - the issue has remained unresolved, either because it couldn't be reproduced, or couldn't be prevented/fixed

Moderators: Stefan2, white, sheep, Hacker

Post Reply
TWiStErRob
Junior Member
Junior Member
Posts: 14
Joined: 2005-04-04, 13:41 UTC
Location: Hungary
Contact:

Current directory is wrong when "Run as different user.

Post by *TWiStErRob » 2010-04-24, 15:37 UTC

When I start a program under a different account from TC, the current directory is set to C:\Windows\system32.
I used Windows 7 TC755b3, maybe the same is true for Windows Vista. I think this is an old bug.

Repro:

1. Create a .bat file with the following content:

Code: Select all

@echo off
cd
pause
2. Run it from TC (via Enter), the output is:

Code: Select all

X:\Path\to\batch\file
Press any key to continue . . .
3. Run it from TC
3.a Shift+Long right Click on the batch file (shift needed to show "Run as different user...")
3.b Click on Run as different user...
3.c Enter username of a not logged in user (if you don't know any, create a password protected one); it needs to have password!
3.d The output what you will see:

Code: Select all

C:\Windows\system32
Press any key to continue . . .
4. Run it from Explorer
4.a Open the folder containing the batch file
4.b Shift+Right click the batch file
4.c Click on Run as different user...
4.d Enter the same user name as above
4.e The output now will be the same as in 2.


Note: On Windows XP TC755b1 did not show "Run as user..." in context menu (tried with any magic key combos), but explorer did with a single right click.

User avatar
MVV
Power Member
Power Member
Posts: 8284
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2010-04-24, 16:35 UTC

I thought that it is a Windows bug, but Explorer really passes right path.

I think that it is because TC passes 0 as working directory while calling program. When I call ShellExecute with verb "runas" and pass 0 as working directory (i.e. current dir), Windows resets path to System32 dir, but when I pass as working dir path returned by GetCurrentDirectory - all work fine. It seems that inside of user control mechanism System32 folder is current, and if we don't pass special path, it will be used as default.

TWiStErRob
Junior Member
Junior Member
Posts: 14
Joined: 2005-04-04, 13:41 UTC
Location: Hungary
Contact:

Post by *TWiStErRob » 2010-04-24, 17:01 UTC

So this means you will change a NULL to GetCurrentDirectory()? And this will be fixed?

User avatar
MVV
Power Member
Power Member
Posts: 8284
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2010-04-24, 17:13 UTC

You may check my initial version of Sudo.exe tool here and updated one (that calls GetCurrentDirectory and passes returned path instead of NULL) here and try to start elevated process using both versions. Test batch file launched from updated Sudo shows right path. :)

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 37485
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2010-04-25, 14:21 UTC

Indeed I was assuming that 0 would pass current dir, but apparently it doesn't. I will change it.
Author of Total Commander
http://www.ghisler.com

User avatar
MVV
Power Member
Power Member
Posts: 8284
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2010-05-12, 07:22 UTC

According to history.txt this should be fixed in TC 7.55 RC1.

I confirm than for cm_OpenAsUser it now works fine.

But I can't confirm fix for Windows 7 elevation system. If I choose 'Run As' in context menu and start above mentioned BAT file elevated, console tells that current folder is C:\Windows\System32.

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 37485
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2010-05-12, 08:48 UTC

sorry, I had tested this only on Windows XP. It seems that Windows 7 uses two separate verbs for 'Run as':
1. runas: This is used for elevation now (run as admin). TC passes the current directory to the start function when it sees that verb.
2. runasuser: This verb does what runas did on XP. Currently this verb is unsupported, I will support it in the next beta.
Author of Total Commander
http://www.ghisler.com

User avatar
MVV
Power Member
Power Member
Posts: 8284
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV » 2010-05-12, 09:39 UTC

BTW I'm using 'Run As Admin' (which replaces 'Run As' in Windows 7) from context menu to start elevated program, not under another account. So, when I use 'Run As Admin', Windows doesn't ask me for user login/password, it just asks for elevation. And in this case TC doesn't pass right working dir.

BTW it seems that Windows itself doesn't support passing paths to elevated (not started under another account) applications, my Sudo.exe also can't make this batch working (and when I start just EXE from Sudo, path anyway is C:\Windows).

BTW2, under my Windows 7 I can't make "runasuser" verb working, just nothing happens when I call ShellExecuteEx with it (and I can't find any info about such verb).

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 37485
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2010-05-12, 10:25 UTC

Indeed it seems that Windows 7 is ignoring the current directory when using "Run as Admin". :(

The "runasuser" verb is used in IContextMenu->InvokeCommand when I choose "Run as different user" from the menu. The "runas" verb causes elevation.
Author of Total Commander
http://www.ghisler.com

Post Reply