How to make a cmd 'runnable as administrator' under windows 7?

5

1

I have written as small .cmd file to be executed as an administrator. I am trying to set its options as 'Run as Administrator' but the check box is not accessible.

Run As Administrator

Why? How to solve this issue? I am administrator on my PC (Windows 7).

Jérôme Verstrynge

Posted 2011-09-21T18:34:12.587

Reputation: 267

Answers

3

Create a Shortcut to the .CMD you want to launch (Right-click-->Create Shortcut, or drag-drop with Alt pressed)

Go into the shortcut's Properties-->Shortcut Tab-->Advanced-->Check-mark Run as Administrator

Then launch with the Shortcut instead.

Ƭᴇcʜιᴇ007

Posted 2011-09-21T18:34:12.587

Reputation: 103 763

Thanks. It did the trick. For the records: I had to create a 'set location=C:/Users/etc...' variable in my .cmd and use it with each command to make it work. – Jérôme Verstrynge – 2011-09-21T19:47:41.890

Glad it worked. Have you considered setting the environment variable permanently instead? Check out SetX, and/or this question: how to set path environment variable amongst others, for some info on that. :)

– Ƭᴇcʜιᴇ007 – 2011-09-21T20:02:17.117

The thing is that I may need to modify it in the future and it is only used in the .cmd. It's not really necessary to make it global (in my case). – Jérôme Verstrynge – 2011-09-21T20:27:19.033

2

runas might come to some use for you

Sandeep Bansal

Posted 2011-09-21T18:34:12.587

Reputation: 6 168

Keep in mind runas only elevates commands if you use the builtin Admin account's credentials and you have autoapproval mode on. Otherwise this will fail due to UAC. – surfasb – 2011-09-21T21:35:50.287