Jump to content

batch file to AutoIT


lexicon
 Share

Recommended Posts

Greetings friends.

I some how made a program using windows batch file it took me 2 days (I'm really worse in programming)

Scenario:

We do have 30 Windows laptop and we have standardized the power settings should be same in all computers. All Computers don't have admin rights and are not in domain, so No GPO.

So the one manual option would be to go to each 30 computer give the user admin rights create powerplan set it and again revoke the admin privilege. Normal users were not able to change the powerplan because they don't have write access to certain registry keys. For that i created a batch file ran setacl.exe as Administrator to change the HKLM key's settings.

createad power profile using "powercfg /create", to my dilemma the power plan is created for Administrator and not for the restricted user because i did "runas /u:administrator myscript.bat"

Finally I managed to do it with again running the program as non admin user.

below is the batch file lines

First.bat

echo %username%
runas /u:administrator cmd /k  %CD%/setaclreg.bat"
pause
@echo Don't Press Enter Now come back later after the other script finishes
@echo Ran as %username%
pause
POWERCFG /CREATE MyXP
POWERCFG /CHANGE MyXP /monitor-timeout-ac 10
POWERCFG /CHANGE MyXP /monitor-timeout-dc 10
POWERCFG /CHANGE MyXP /disk-timeout-ac 0
POWERCFG /CHANGE MyXP /disk-timeout-dc 0
POWERCFG /CHANGE MyXP /standby-timeout-ac 20
POWERCFG /CHANGE MyXP /standby-timeout-dc 20
POWERCFG /CHANGE MyXP /hibernate-timeout-ac 0
POWERCFG /CHANGE MyXP /hibernate-timeout-dc 0
POWERCFG /CHANGE MyXP /processor-throttle-ac ADAPTIVE
POWERCFG /CHANGE MyXP /processor-throttle-dc ADAPTIVE
POWERCFG /SETACTIVE MyXP 
pause
POWERCFG /QUERY
pause
runas /u:administrator  %CD%/resetaclreg.bat
pause

Second.bat

@echo running the program as %username%
pause
SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace "n:users;p:full" 
SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\GlobalPowerPolicy" -ot reg -actn ace -ace "n:users;p:full" 
SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies" -ot reg -actn ace -ace "n:users;p:full" 
pause
exit

Third.bat

echo %username%
SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace "n:users;p:read" 
SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\GlobalPowerPolicy" -ot reg -actn ace -ace "n:users;p:read" 
SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies" -ot reg -actn ace -ace "n:users;p:read" 
pause
del %CD%\one.bat resetaclreg.bat SetACL.exe setaclreg.bat one.bat
pause

This is working very bad.
I would like if you guys with many years of programming help me out make it a AutoIT executable.

Many Thanks

lexi

Link to comment
Share on other sites

 

Not sure if helpful but have you tried this?

;Domain admin information
Local $sUserName = "Account"
Local $sPassword = "Password"

$CMD= 'Your CMD command here'
RunAs($sUsername, @ComputerName, $sPassword, 0,@ComSpec & " /c " & $CMD @SystemDir, @SW_Show)

Thankyou friend.

your script says $CMD= 'your command here'

but i have so many commands in my three batch file how to integrate that in autoit script

thanks

Link to comment
Share on other sites

Thankyou friend.

your script says $CMD= 'your command here'

but i have so many commands in my three batch file how to integrate that in autoit script

thanks

 

have a look >here

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Thanks for the link friend.

Local $sUserName = "Administrator"
Local $sPassword = "mypassword"

$CMD= RunWait( @COMSPEC & " /c C:&&cd \Tools&&dir>D:\temp\multi.txt&&D:\temp\multi.txt", "", @SW_SHOW )
RunAs($sUsername, @ComputerName, $sPassword, 0, $CMD,@SystemDir, @SW_Show)

This code is working great. But i didn't liked the idea of having password inside my script.

Can we use multiple DOS commands with ShellExecute() In which isAdmin() Does a perfect job. (prompts for windows itself password dialogue)

Thanks

Link to comment
Share on other sites

Hello friends after looking around in this forum to set/change registry permission with script

i opted for going with SetACL.exe

running SetACL.exe with so many parameters is generating errors i can't figure it out where to put double quotes, where to put single quotes, where to put &.

I would be indebted if you guys to spot and correct my syntax errors

This one works perfect since it's sweet and short.

$command=RunWait(@ComSpec &" /k dir")
RunWait($command)

But when i try the below mentioned code. It throws me error

RunWait($command)
$command=Runwait(@ComSpec &" /k &" "SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace  "n:users;p:full")

This is the actual command that i would like to invoke with AutoIt

SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace "n:users;p:full"

I'm totally lost with those "whitespaces" "doublequotes" "hypens" "semicolons" "colons" .
I also looked at the post from Universalist '?do=embed' frameborder='0' data-embedContent>>

but couldn't match to work with my error.

Thanks

lexi

Link to comment
Share on other sites

  • Moderators

Try this:

Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace  "n:users;p:full"')

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Okay some how i have managed to do all my batch script to AutoIt Script

for some reason the script is not running as admin user.
I very sure that the username and passwords are correct.

Local $Username="Administrator"
Local $Password="v3ryS3cr37"

$setreg1= Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace  "n:users;p:full"')
$setreg2= Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\GlobalPowerPolicy" -ot reg -actn ace -ace "n:users;p:full"')
$setreg3= Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies" -ot reg -actn ace -ace "n:users;p:full"')


Runas($Username,@ComputerName,$Password,0,$setreg1,@SW_Show)
Runas($Username,@ComputerName,$Password,0,$setreg2,@SW_Show)
Runas($Username,@ComputerName,$Password,0,$setreg3,@SW_Show)



Runwait (@ComSpec & ' /c POWERCFG /CREATE infWinXP',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /monitor-timeout-ac 10',@SW_HIDE)
Runwait (@ComSpec & ' POWERCFG /CHANGE infWinXP /monitor-timeout-dc 10',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /disk-timeout-ac 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /disk-timeout-dc 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /standby-timeout-ac 20',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /standby-timeout-dc 20',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /hibernate-timeout-ac 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /hibernate-timeout-dc 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /processor-throttle-ac ADAPTIVE',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /processor-throttle-dc ADAPTIVE',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /SETACTIVE infWinXP',@SW_HIDE)
Runwait (@ComSpec & ' /c powercfg /list',@SW_SHOW)


$resetreg1= Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace  "n:users;p:read"')
$resetreg2=Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\GlobalPowerPolicy" -ot reg -actn ace -ace "n:users;p:read"')
$resetreg3=Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies" -ot reg -actn ace -ace "n:users;p:read"')

Runas($Username,@ComputerName,$Password,0,$resetreg1,@SW_Show)
Runas($Username,@ComputerName,$Password,0,$resetreg2,@SW_Show)
Runas($Username,@ComputerName,$Password,0,$resetreg3,@SW_Show)

Please do not laugh at my programming skill.
I'm not used to of using loops and making program short and smart.
I am very new to programming.
Thanks :)
Edited by lexicon
Link to comment
Share on other sites

$setreg1= Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace  "n:users;p:full"')

I think you should get rid of the RunWait on all those commands ...

$setreg1= @ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace  "n:users;p:full"'

And then use RunAsWait instead of RunAs

EDIT: I think you also need to specifiy #requireAdmin at the start of your file.

Read here to understand : '?do=embed' frameborder='0' data-embedContent>>

Edited by Inverted
Link to comment
Share on other sites

Thanks Universalist , but..... after i do as per your suggestion neither it's throwing an error nor working.

#RequireAdmin

Local $Username="Administrator"
Local $Password="1p@ssw0rd-2"

# line without () as per your suggestion
$setreg1=@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace  "n:users;p:full"'
#line with () because the above one didn't worked.
$setreg1=(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace  "n:users;p:full"')
RunAsWait($Username,@ComputerName,$Password,0,$setreg1,@SW_Show)

The output windows looks as below

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Program Files\AutoIt3\Examples\tester432.au3" /UserParams    
+>15:11:51 Starting AutoIt3Wrapper v.2.1.4.0 SciTE v.3.3.7.0 ;  Keyboard:00000409  OS:WIN_XP/Service Pack 3  CPU:X64 OS:X86    Environment(Language:0409  Keyboard:00000409  OS:WIN_XP/Service Pack 3  CPU:X64 OS:X86)
>Running AU3Check (3.3.10.2)  from:C:\Program Files\AutoIt3
+>15:11:51 AU3Check ended.rc:0
>Running:(3.3.10.2):C:\Program Files\AutoIt3\autoit3.exe "C:\Program Files\AutoIt3\Examples\tester432.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
+>15:11:51 AutoIt3.exe ended.rc:0
>Exit code: 0    Time: 0.690

Thanks

Edited by lexicon
Link to comment
Share on other sites

One solution  is to run your commands normally:

Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace  "n:users;p:full"')
Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\GlobalPowerPolicy" -ot reg -actn ace -ace "n:users;p:full"')
Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies" -ot reg -actn ace -ace "n:users;p:full"')

Runwait (@ComSpec & ' /c POWERCFG /CREATE infWinXP',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /monitor-timeout-ac 10',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /monitor-timeout-dc 10',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /disk-timeout-ac 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /disk-timeout-dc 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /standby-timeout-ac 20',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /standby-timeout-dc 20',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /hibernate-timeout-ac 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /hibernate-timeout-dc 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /processor-throttle-ac ADAPTIVE',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /processor-throttle-dc ADAPTIVE',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /SETACTIVE infWinXP',@SW_HIDE)
Runwait (@ComSpec & ' /c powercfg /list',@SW_SHOW)

Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace  "n:users;p:read"')
Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\GlobalPowerPolicy" -ot reg -actn ace -ace "n:users;p:read"')
Runwait(@ComSpec & ' /k SetACL.exe -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies" -ot reg -actn ace -ace "n:users;p:read"')

But after you compile the exe use right-click -> "Run As Administrator" to make sure it has admin privileges.

Edited by Inverted
Link to comment
Share on other sites

Yes that's indeed a good idea. But this is the problem

Runwait (@ComSpec & ' /c POWERCFG /CREATE infWinXP',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /monitor-timeout-ac 10',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /monitor-timeout-dc 10',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /disk-timeout-ac 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /disk-timeout-dc 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /standby-timeout-ac 20',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /standby-timeout-dc 20',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /hibernate-timeout-ac 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /hibernate-timeout-dc 0',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /processor-throttle-ac ADAPTIVE',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /CHANGE infWinXP /processor-throttle-dc ADAPTIVE',@SW_HIDE)
Runwait (@ComSpec & ' /c POWERCFG /SETACTIVE infWinXP',@SW_HIDE)
Runwait (@ComSpec & ' /c powercfg /list',@SW_SHOW)

Once i run the .exe doing runas admin user then the profiles are created for user admin and not for the current user. :-(

The other way around will to be create 3 autoit executables files with code you suggested.

and Run FirstScript to change the registry permission so that users are allowed to add their own profiles

Secondly Run the Second Script as normal logged in user to Create Power Profiles.

Thirdly , Run the Last Script to reset the registry permission back to Normal. So that users are not allowed to change the power profiles.

I think i should go with this lame way as my programming skill can't make the script work better than it.

Thanks

lexicon

Link to comment
Share on other sites

Yes, really tricky situation it might not be easy :(

Now creating 3 executable to click and run 3 times.

1) To Set The Registry Permission (So that Normal Users can Change)

2) To Set / Create Standard Power profile with normal user.

3) To Set back the original Registry permission.

I guess 1 & 2 Can be combined using KODA GUI. (Cheers)

Thanks everyone for your time and effort. I learned many things.

lexicon

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...