davesipos Posted July 1, 2014 Share Posted July 1, 2014 I need to append to an .ini file with two lines of text, however need to open/save the file using elevated credentials. Was using the following syntax which I've read that you cannot use RunAs with FileOpen/FileWrite, are there any alternatives? $file = RunAs("administrator", @ComputerName, $AdminPW, 4, FileOpen("C:Program FilesApplicationClientBinconfig.ini", 1)) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Else RunAs("administrator", @ComputerName, $AdminPW, 4, FileWrite($file, "[Plugins]")) RunAs("administrator", @ComputerName, $AdminPW, 4, FileWrite($file, "" & @CRLF)) ; The CRLF at the end is a line break RunAs("administrator", @ComputerName, $AdminPW, 4, FileWrite($file, "AcrobatPlugin.NichePlugin.dll=1")) RunAs("administrator", @ComputerName, $AdminPW, 4, FileWrite($file, "" & @CRLF)) ; The CRLF at the end is a line break Link to comment Share on other sites More sharing options...
JohnOne Posted July 1, 2014 Share Posted July 1, 2014 Is it on your own admin account? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
davesipos Posted July 2, 2014 Author Share Posted July 2, 2014 Script will need to run as the local admin account on remote PC's. Link to comment Share on other sites More sharing options...
JohnOne Posted July 2, 2014 Share Posted July 2, 2014 I believe people here use script pexec for that. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jguinch Posted July 2, 2014 Share Posted July 2, 2014 A solution can be to RunAs the script itself with an admin account, so everything will be run with admin rights For example : _RunAsAdmin("Administrator", "P@$$w0rd!") If @error Then Exit MsgBox(16, "Error", "Unable to run the script with the specified admin account.") MsgBox(0, "", "Now, this program is running with """ & @UserName & """ account") ; The rest of the script will run in the admin account Func _RunAsAdmin($sUsername, $sPassword) If IsAdmin() Then Return 1 RunAs($sUsername, @ComputerName, $sPassword, 0, @AutoItExe & " " & $CmdLineRaw, @WorkingDir) If @error Then Return SetError(1, 0, 0) Exit EndFunc Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF 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