Get administrative right in windows command line
Solution 1
Create a shortcut to such batch script and then
- in context menu click Properties
- under Shortcut click Advanced button
- select Run as administrator
Solution 2
As you mentioned in your comments using runas
as the same user will not elevate you. There is no method I know of built in to windows that will elevate an already running command prompt.
In the past I have used 3rd party tools like Elevate.exe
which will do the job for you, you just use it like you would use runas
, just add the elevate
program to your PATH
variable and you can just do
elevate route add -p 20.20.188.0 mask 255.255.255.0 192.168.122.254
Related videos on Youtube
рüффп
More than 20 years experience in IT consulting in different business and using different technologies. My main IT interest are: Docker and containers Cloud technos Security Spring framework Open source projects in general (Apache, Spring) Programming languages (Java, go, python, C++, C) I have many other interests like biology and nature, birdwatching, photography, diy, home electronics.
Updated on September 18, 2022Comments
-
рüффп over 1 year
I am not trying to do cheeky things, but my need is just to have two scripts for adding or removing IP routes using the following command in batch scripts:
Add route:
@echo off route add -p 20.20.188.0 mask 255.255.255.0 192.168.122.254 exit
delete route:
@echo off route delete 20.20.188.0 exit
My question is that now I cannot get it run just by double-click on the batch file. I always have to right click and choose:
Run as Administrator
option even my user is in the Administrator group.Is there any way to introduce a command like
sudo
in Linux or anything else that can make me happy by just double-clicking on the file.UPDATE:
I tried the
runas
solution here but as the answer state:Note, however, that this is not exactly like sudo - you can't use it to elevate yourself, just run something as a different user. If you're already have administrative rights, a runas to your account will give you the same access as the regular command (unless, of course, you runas a different administrator account, which will grant those administrator's rights to the new shell).
It is not a solution for my problem.
-
and31415 about 10 yearsBasically you want to force those batch files to run with administrator rights, isn't it?
-
Ƭᴇcʜιᴇ007 about 10 years
-
рüффп about 10 yearsYes exaclty; I saw some post with runas option but it does not look to be helpful.
-
Jon Carl about 10 yearsAn answer for this can be found here: stackoverflow.com/questions/1894967/…
-
Ƭᴇcʜιᴇ007 about 10 yearsCtrl+Shift+Double-click
-
Ƭᴇcʜιᴇ007 about 10 years@ruffp There is more than one answer on those questions, and I'm not sure why you wouldn't find the posts regarding RunAs 'helpful', but hey, there they are. :)
-
рüффп about 10 yearsThe duplicate link does not answer my question: If you're already have administrative rights, a runas to your account will give you the same access as the regular command (unless, of course, you runas a different administrator account, which will grant those administrator's rights to the new shell).
-
рüффп about 10 years@techie007 I already tried these answer and none are working for me. the link provided by JonCarl is interesting as well but it does not work for me.
-
Ƭᴇcʜιᴇ007 about 10 yearsNone of those answers work for you in any way? What "doesn't work" about them?
-
рüффп about 10 years@techie007 in fact the solution pointed by JonCarl seems to work but it is just a bit slower. anyway I think the solution provided by laika is the best one as no third party or (slow) system call.
-
-
рüффп about 10 yearsAh it is funny to see the "run as administrator" is grayed out on the batch file but another option exist on the shortcut (and the same option is still greyed out on the shortcut). Thanlks anyway it is the simplest way I will use.
-
рüффп over 7 yearsInteresting to see alternative, but I'd prefer laika's answer as there's no third party software to install.