Opening Command Prompt & PowerShell as Administrator in 2 ways

Discussion, questions and support.
Post Reply
Message
Author
Forez
Posts: 533
Joined: 30.01.2016, 12:05
Location: In front of a PC monitor

Opening Command Prompt & PowerShell as Administrator in 2 ways

#1 Post by Forez » 22.02.2021, 00:53

I am having problems with both the CMD and PowerShell - trying to run them as Administrator. I want them to open in 2 ways: in the root folder of drive C [i.e. >>c:\<<] and in the current location [i.e. that Panel which happens to be active when I click the icon on the toolbar]

My >>Define favorite toolbars<< settings are as follow



Command Prompt

Code: Select all

Program or folder:
C:\Windows\system32\cmd.exe

Start folder:
[EMPTY]

Parameter:
/K "cd /d C:\"

[SELECTED OPTIONS]
Enclose each selected item with "
With "Run as" dialog
Maximized
This opens CMD as Administrator in

Code: Select all

C:\
So it is working as intended. But also want a second version



And so I changed it to

Code: Select all

Start folder:
%ActivDir%

Parameter:
/K
but it opens CMD in

Code: Select all

C:\Windows\System32


I also tried

Code: Select all

Start folder:
[EMPTY]

Parameter:
%ActivDir%
but the result was the same






PowerShell

Code: Select all

Program or folder:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

Start folder:
[EMPTY]

Parameter:
Start-Process PowerShell -Verb runAs

[SELECTED OPTIONS]
Enclose each selected item with "
With "Run as" dialog
Maximized
This opens PowerShell as Administrator but in

Code: Select all

C:\Windows\System32


If I change

Code: Select all

Parameter:
-NoExit -Command "& {cd c:\}"
then it will open in

Code: Select all

C:\
but not as Administrator



And if I combine those two into one

Code: Select all

Parameter:
Start-Process PowerShell -Verb runAs -NoExit -Command "& {cd c:\}"
then I can see the PowerShell window opening as Administrator but before it can reveal its location it closes itself. Thus it is simply broken. So how do I correctly combine them; or workaround this?



I tried upgrading the first setup with

Code: Select all

Start folder:
%ActivDir%

and also

Start folder:
C:\
but it simply does not work, as the PowerShell open in

Code: Select all

C:\Windows\System32



I am using FreeCommander XE 2020 Build 840 32-bit public on Windows 10 Enterprise 20H2 19042.746

Forez
Posts: 533
Joined: 30.01.2016, 12:05
Location: In front of a PC monitor

Re: Opening Command Prompt & PowerShell as Administrator in 2 ways

#2 Post by Forez » 22.02.2021, 01:16

Forez wrote: 22.02.2021, 00:53 [...]
Command Prompt
[...]
I have just found this

https://freecommander.com/forum/viewtop ... 587#p35587

so this one I got - I am able to run CMD in both ways




But the trick of adding >>"cd /d %ActivDir%"<< to the and of >>Parameter:<< apparently does not work for PowerShell as

Code: Select all

Parameter:
Start-Process PowerShell -Verb runAs "cd /d %ActivDir%"
nor

Code: Select all

Parameter:
Start-Process PowerShell -Verb runAs "'cd /d %ActivDir%'"
work all the way through - they both in the end close the PowerShell window

Karol
Posts: 811
Joined: 19.08.2007, 12:05

Re: Opening Command Prompt & PowerShell as Administrator in 2 ways

#3 Post by Karol » 22.02.2021, 10:45

Open PowerShell in current folder (favorite tool button ):

Name: PowerShell
Program: powershell.exe
Parameter: -noexit -command "cd %ActivDir%"
Option "Enclose each selected item with " - UNCHECKED

For Admin call: 'With "Run as" dialog' option must be checked

Forez
Posts: 533
Joined: 30.01.2016, 12:05
Location: In front of a PC monitor

Re: Opening Command Prompt & PowerShell as Administrator in 2 ways

#4 Post by Forez » 22.02.2021, 20:33

Karol wrote: 22.02.2021, 10:45 Open PowerShell in current folder (favorite tool button ):

Name: PowerShell
Program: powershell.exe
Parameter: -noexit -command "cd %ActivDir%"
Option "Enclose each selected item with " - UNCHECKED

For Admin call: 'With "Run as" dialog' option must be checked
It just does not work - not for paths that have a pause within them

I tried

Code: Select all

"cd %ActivDir%"
"'cd %ActivDir%'"
"'cd /d %ActivDir%'"
"'cd /d %ActivDir%"
and adding / removing the >>Enclose each selected item with<< option and also evoking either merely >>powershell.exe<< or specifically

Code: Select all

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
but all I got was PowerShell with errors opened in

Code: Select all

C:\Windows\system32>
or working PowerShell without errors but still not in the active directory only sometimes with the path active in FC shown above the prompt line



Of course I probably have missed some of the combination



Can someone else please check their settings for this; i.e. PowerShell opening from Favorite icon with the path taken from the active Panel?

Karol
Posts: 811
Joined: 19.08.2007, 12:05

Re: Opening Command Prompt & PowerShell as Administrator in 2 ways

#5 Post by Karol » 22.02.2021, 21:57

Works fine here with:

Code: Select all

Parameter:  -noexit -command "cd '%ActivDir%'"

Forez
Posts: 533
Joined: 30.01.2016, 12:05
Location: In front of a PC monitor

Re: Opening Command Prompt & PowerShell as Administrator in 2 ways

#6 Post by Forez » 23.02.2021, 17:23

Karol wrote: 22.02.2021, 21:57 Works fine here with:

Code: Select all

Parameter:  -noexit -command "cd '%ActivDir%'"
It seems that running multiple times CMD and / or PowerShell and messing around with them can cause some critical errors in my Windows 10


After reluctantly setting up a Favorite toolbar icon once more from scratch with these settings I was surprised that it worked - and how it worked. Because even after closing of the PowerShell window I had no access to my drives- i.e. trying to move access any file or folder or trying to save any opened file resulted with a pop-up windows saying that I need an Administrator permission

After a reset this Matrix did not occur again. But if I take into consideration the previous behavior [the now working settings did not work yesterday] - my statement from the very top of this post seems to be valid




All in all thank you; the PowerShell now runs as I want

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests