Sign in to follow this  
Followers 0
CharlieTango

Batch not running with RunAsSet

6 posts in this topic

Hi all!

I am trying to run a simple batch file to create a new Power Scheme and set it as active. The batch file contains the following lines:

REM power.bat

@echo off

POWERCFG /CREATE NPSCheme

POWERCFG /CHANGE NPSCheme /monitor-timeout-ac 5

POWERCFG /CHANGE NPSCheme /disk-timeout-ac 10

POWERCFG /CHANGE NPSCheme /standby-timeout-ac 0

POWERCFG /CHANGE NPSCheme /hibernate-timeout-ac 0

POWERCFG /CHANGE NPSCheme /processor-throttle-ac ADAPTIVE

POWERCFG /SETACTIVE NPSCheme

Regular users in my domain DO NOT have permission to change these settings; hence, I need to run this batch as an Administrator. Now, the weird thing is that when I execute it like this:

Run("V:\power.bat", "", @SW_HIDE)

It runs and does exactly what the batch file is all about, but only when the user that logs on is an administrator.

Now, when I add the RunAsSet sentence at the top of my script (as shown below), I constantly get a message "A scheme with that name already exists..."...and of course, it doesn't exist (no matter what user you are logged on as). I run it again without the RunAsSet, and the batch sets the new power scheme; I delete it, run it again adding RunAsSet and there goes the message again...

RunAsSet ("Admin", "Domain", "pass") ;The credentials supplied here in my script are 100% correct

Run("V:\power.bat", "", @SW_HIDE)

Am I skipping something? What am I doing wrong?

Any ideas or help will be greately appreciated!

Thanks in advance.

ps: I am using WindowsXP SP2 and Auoit v3.2.10.0.

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

Power configuration is incredibly Sad in XP, in that it observes per-user customization, but you have to be an Administrator to change all the available features. I think the only setting that's observed cross-profile is hibernation.

The settings are saved per-user in the user's system registry file. When you're using RunAsSet POWERCFG is running against the settings in that administrator user's registry, and thus the profile already exists. The administrator-only restriction is imposed on you only if you use the Win32 API functions to manage the settings.

There's a tool with C++ source code available from an EPA project that works around the API and directly modifies the binary data in the registry, let me see if I can find a link to it...

Here go: EZ GPO.

[Edit: Added link, clarified cause of error, had incorrectly attributed project to DoE.]

Edited by DaveF

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

Hello DaveF!

And thanks for your quick reply. I had already taken a look at ez_gpo; but I thought I could easily do it with powercfg.exe. Anyway, the thing is that the new Power Scheme DOES NOT exist in any PC ...no administrator has ever logged on in any of those workstations; hence, the new power scheme doesn't exist at all (I 100% possitive about that).

I still find it a weird behavior...

Thanks again for your reply

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Don't know... If you're going to pursue it any further you should update to the current release of AutoIt. There are some changes under the hood in the way that run-as functionality is achieved, so it's possible that this is something that wouldn't be an issue with the new version.

[Edit: typo]

Edited by DaveF

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

Will do; I will upgrade and check out the behavior of the new RunAs() function, I will post results back...

Thanks for your help!

Share this post


Link to post
Share on other sites

Upgraded to new Autoit3 and changed to:

RunASwAIT("Administrator","DOM","passwd","V:\power.bat", "", @SW_MAXIMIZE)

Still get the same error : "A Scheme with that name already exists"....

Weird bahavior...the scheme has never been created!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0