Briandr Posted December 4, 2014 Share Posted December 4, 2014 (edited) I have a process that auto logs on as admin and then executes a series of scripts. These scripts are task sequence scripts called by a Dell Kace K2000 imaging process. This has to do with powercfg (forum regulars / monitors will have seen my posts on this). The gotcha is one script in particular only half works when run through Kace. The part that half works is it is able to successfully import the power scheme. Setting it as a default does not work.Is there any way I can change this so it looks like I am highlighting the file and clicking "Run as Admininstrator". There should be a easy way to do this right? Help would be much appreciated. #include <Constants.au3> FileInstall("PowerPlanNever.pow", @WindowsDir & "\", 1) $ImportPowerPlan = "POWERCFG -import C:\Windows\PowerPlanNever.pow 3b5e563e-124a-46ac-a21e-c436de915f80" $SetActivePowerPlan = "POWERCFG -setactive 3b5e563e-124a-46ac-a21e-c436de915f80" Run(@ComSpec & " /c " & $ImportPowerPlan, "", @SW_HIDE) Run(@ComSpec & " /c " & $SetActivePowerPlan, "", @SW_HIDE) Edited December 4, 2014 by Briandr Link to comment Share on other sites More sharing options...
BrewManNH Posted December 4, 2014 Share Posted December 4, 2014 Use RunAs instead of Run. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Briandr Posted December 4, 2014 Author Share Posted December 4, 2014 Thanks. What about #RequireAdmin? Needed or not needed? Link to comment Share on other sites More sharing options...
BrewManNH Posted December 4, 2014 Share Posted December 4, 2014 If you want the whole script to be run as an Administrator you would use that, if you want to launch a program that's separate from your script you would use RunAs. #RequireAdmin needs the user running the script to be an administrator, RunAs needs you to put the administrator's username and password into the script, or the user running the script would need to have these credentials to put them in. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Briandr Posted December 8, 2014 Author Share Posted December 8, 2014 Hi, I added #RequireAdmin to the top of the script and the logged on user was admin and the second run command failed to execute. Any ideas before changing over to RunAs? Thanks. Link to comment Share on other sites More sharing options...
BrewManNH Posted December 8, 2014 Share Posted December 8, 2014 Try using RunWait on the first run command instead of Run. The second one may fail because the first one hasn't finished yet. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Briandr Posted December 8, 2014 Author Share Posted December 8, 2014 Thanks. I am trying to enable logging as I'd like to see what is going on. I looked at AutoIT created by someone else and am trying to incorporate this, but it is not working. Can someone see what might be wrong with this? It seems to be looking for a function. So perhaps this code needs to be slimmed down or something that is missing needs to be added. RequireAdmin #include <Constants.au3> $ImportPowerPlan = "POWERCFG -import C:\Windows\PowerPlanNever.pow 3b5e563e-124a-46ac-a21e-c436de915f80" $SetActivePowerPlan = "POWERCFG -setactive 3b5e563e-124a-46ac-a21e-c436de915f80" $LogDirectory = @WindowsDir & "\Dell\KACE" $ModuleName = @ScriptName $ModuleName = StringSplit($ModuleName, ".") $ModuleName = $ModuleName[1] $Log = $LogDirectory & "\" & $ModuleName & ".log" $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $StrComputer = "localhost" If Not FileExists($LogDirectory) Then DirCreate($LogDirectory) ;Creates path if does not exist If FileExists($Log) Then FileDelete($Log) _FileWriteLog($Log, $ModuleName & " module called.") ;Importing the Power Plan Never _FileWriteLog($Log, "Importing Power Plan Never") FileInstall("PowerPlanNever.pow", @WindowsDir & "\", 1) $ImportPowerPlan = "POWERCFG -import C:\Windows\PowerPlanNever.pow 3b5e563e-124a-46ac-a21e-c436de915f80" $Retval = RunWait(@ScriptDir & @ComSpec & " /c " & $ImportPowerPlan, "", @SW_HIDE & @ScriptDir) _FileWriteLog($Log, "Power Plan Never has been imported. Return Value = " & $retval) ;Setting the Power Plan Never as the active one _FileWriteLog($Log, "Setting Power Plan Never as the Active one") $SetActivePowerPlan = "POWERCFG -setactive 3b5e563e-124a-46ac-a21e-c436de915f80" $Retval = RunWait(@ScriptDir & @ComSpec & " /c " & $SetActivePowerPlan, "", @SW_HIDE & @ScriptDir) _FileWriteLog($Log, "Power Plan Never has been set as the Active one. Return Value = " & $retval) Thanks. Link to comment Share on other sites More sharing options...
BrewManNH Posted December 8, 2014 Share Posted December 8, 2014 Add #include <File.au3> to your script to use _FileWriteLog, If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Briandr Posted December 8, 2014 Author Share Posted December 8, 2014 Thanks! The RunWait did work. I ma still trying to get my logging file working. I have tried different ways to get the install to work with no luck. - $Retval = RunWait(@ScriptDir & @ComSpec & " /c " & $SetActivePowerPlan, "", @SW_HIDE & @ScriptDir) - $Retval = RunWait(@ComSpec & @ScriptDir & " /c " & $SetActivePowerPlan, "", @SW_HIDE) I am hopeful its just I got the syntax incorrect. This would be a huge help going forward as I could template for other little scripts I do. Thanks again guys! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now