Page 1 of 1 [ 5 posts ] 

YellowBanana
Veteran
Veteran

User avatar

Joined: 14 Feb 2011
Age: 51
Gender: Female
Posts: 1,032
Location: mostly, in my head.

14 May 2012, 10:23 am

Looking for someone who knows about autohotkey and batch files to help me out with something.

I want to run a batch file in an autohotkey script - no problem doing that at all. Simple as a run command.

But the problem is that the command in the batch file requires to be run as administrator (usually I would right click on the file and choose run as administrator, and then click yes to the UAC prompt). If it doesn't run as administrator, the batch file runs but doesn't do anything.

I don't really need autohotkey to run as administrator (I have found instructions for that) as I won't be sending any keystrokes to the batch file ... i just want the batch file to run as administrator.

Any suggestions? I have a feeling I haven't explained this very well as I am very tired so please ask for clarification.


_________________
Female. Dx ASD in 2011 @ Age 38. Also Dx BPD


HalibutSandwich
Snowy Owl
Snowy Owl

User avatar

Joined: 1 Oct 2011
Gender: Male
Posts: 139
Location: On the hairy end.

21 May 2012, 12:58 am

What OS?

Not exactly sure what you're trying to do, but AHK has a RunAs command that will make all following Run commands start with the credentials you enter with RunAs. Other than that there's workarounds such as creating a shortcut to the batch file and setting the shortcut to Run as Administrator (not in the compatability tab but click the 'Advanced' button and set it in there).


_________________
There's something inside me'n'I know it's good...
But understanding, it's misunderstood. - D.A.D.


Douglas
Emu Egg
Emu Egg

User avatar

Joined: 20 May 2012
Age: 35
Gender: Male
Posts: 2

21 May 2012, 1:37 pm

I registered just to help you out with this. I work in an enterprise environment as helpdesk. We use a lot of runas commands.

We work with windows, so I assume you're using windows.

What you want to do is create a new batch file that points at your other batch file, it will contain the following line

runas /u:username script.bat

where you replace username with the name of your admin account and script.bat with the name of your script, it will then run that script as the user you define.



HalibutSandwich
Snowy Owl
Snowy Owl

User avatar

Joined: 1 Oct 2011
Gender: Male
Posts: 139
Location: On the hairy end.

21 May 2012, 3:04 pm

Douglas wrote:
runas /u:username script.bat

I got the impression he didn't want to type in a password every time. He could use the /savecred option depending on OS. But that can be a bit of a security risk.


_________________
There's something inside me'n'I know it's good...
But understanding, it's misunderstood. - D.A.D.


Soliloquist
Velociraptor
Velociraptor

User avatar

Joined: 13 Oct 2011
Age: 56
Gender: Male
Posts: 467

21 May 2012, 3:20 pm

I use the following javascript code to elevate my batch files.

Save as Elevate.js, then call it thus:

elevate NameOfBatchFile

Code:

// elevate.js -- runs target command line elevated
if (WScript.Arguments.Length >= 1) {
    Application = WScript.Arguments(0);
    Arguments = "";
    for (Index = 1; Index < WScript.Arguments.Length; Index += 1) {
        if (Index > 1) {
            Arguments += " ";
        }
        Arguments += WScript.Arguments(Index);
    }
    new ActiveXObject("Shell.Application").ShellExecute(Application, Arguments, "", "runas");
} else {
    WScript.Echo("Usage:");
    WScript.Echo("elevate Application Arguments");
}