1

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.

рüффп
  • 744
  • 6
  • 13
  • 26
  • Basically you want to force those batch files to run with administrator rights, isn't it? – and31415 Feb 19 '14 at 17:45
  • possible duplicate of [On Windows 7, is there a command prompt line that can start cmd as an administrator?](http://superuser.com/questions/74564/on-windows-7-is-there-a-command-prompt-line-that-can-start-cmd-as-an-administra), [Is there any 'sudo' command for Windows?](http://superuser.com/questions/42537/is-there-any-sudo-command-for-windows) – Ƭᴇcʜιᴇ007 Feb 19 '14 at 17:47
  • Yes exaclty; I saw some post with runas option but it does not look to be helpful. – рüффп Feb 19 '14 at 17:48
  • An answer for this can be found here: http://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file – joncarl Feb 19 '14 at 17:48
  • Ctrl+Shift+Double-click – Ƭᴇcʜιᴇ007 Feb 19 '14 at 17:49
  • 1
    @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. :) – Ƭᴇcʜιᴇ007 Feb 19 '14 at 17:52
  • The 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). – рüффп Feb 19 '14 at 17:53
  • @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. – рüффп Feb 19 '14 at 17:56
  • 2
    _None_ of those answers work for you in any way? What "doesn't work" about them? – Ƭᴇcʜιᴇ007 Feb 19 '14 at 17:58
  • @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. – рüффп Feb 19 '14 at 20:09

3 Answers3

2

Create a shortcut to such batch script and then

  • in context menu click Properties
  • under Shortcut click Advanced button
  • select Run as administrator
laika
  • 1,721
  • 3
  • 12
  • 25
  • Ah 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. – рüффп Feb 19 '14 at 19:56
1

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
Scott Chamberlain
  • 30,694
  • 7
  • 96
  • 109
  • Interesting to see alternative, but I'd prefer laika's answer as there's no third party software to install. – рüффп Dec 24 '16 at 09:27
0

I use "eldo" and "eldoGUI" for this purpose (running batch files elevated). They are available here, although I have absolutely no idea who created them in the first place.

Call eldoGUI like this:

Z:\eldoGUI.exe Z:\Backup-Music.cmd

This will produce the usual UAC prompt and proceed to run the command.

Daniel B
  • 60,360
  • 9
  • 122
  • 163