HockeyFan Posted April 22, 2013 Share Posted April 22, 2013 (edited) Hello! Can someone offer some advice as to why this process is coming back as failed when it appears to be successful? This is a process that needs to run under a non-administrative user account. $sUserName = "XXXXX" $sPassword = "XXXXX" Global $FileCopyINF $FileCopyINF = RunAsWait($sUserName, @ComputerName, $sPassword, 0, FileCopy("C:\Windows\INF\usbstor.inf", "C:\Windows\INF\usbstor.inf.old", 1), @SystemDir, @SW_HIDE) ;test output MsgBox(0, "Test", "Returned value for $FileCopyINF: ", $FileCopyINF) If $FileCopyINF = 0 Then $CopyValueINF = "Failure" Else $CopyValueINF = "Success" EndIf MsgBox(0, "File Copy Results", 'Results of the File "Copy" process...' & @CRLF & @CRLF & " C:\Windows\INF\usbstor.inf................Rename to: usbstor.inf.old [" & $CopyValueINF & "]") Exit The test message output = 0 and the results message comes back as [Failure], but a copy of the file is created. Before: usbstor.inf After: usbstor.inf usbstor.inf.old I'm sure this is just a simple brain freeze on my end but I don't want to push forward without understanding the output. Thanks! Edited April 22, 2013 by HockeyFan Link to comment Share on other sites More sharing options...
Developers Jos Posted April 22, 2013 Developers Share Posted April 22, 2013 (edited) This is not how RunAsWait() works. It will only shell a program, not a function. It cannot perform another AutoIt3 function in this way with alleviated rights! This is an UDF I use that can do that: Func RunReqAdmin($Autoit3Commands, $prompt = 0) Local $temp_Script = _TempFile(@TempDir, "~", ".au3") Local $temp_check = _TempFile(@TempDir, "~", ".chk") FileWriteLine($temp_check, 'TempFile') FileWriteLine($temp_Script, '#NoTrayIcon') If Not IsAdmin() Then FileWriteLine($temp_Script, '#RequireAdmin') If $prompt = 1 Then MsgBox(262144, "Need Admin mode", "Admin mode is needed for this update. Answer the following prompts to allow the update.") EndIf FileWriteLine($temp_Script, $Autoit3Commands) FileWriteLine($temp_Script, "FileDelete('" & $temp_check & "')") If @Compiled Then RunWait('"' & @ScriptFullPath & '" /AutoIt3ExecuteScript "' & $temp_Script & '"') Else RunWait('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $temp_Script & '"') EndIf ; Wait for the script to finish While FileExists($temp_check) Sleep(50) WEnd FileDelete($temp_Script) EndFunc ;==>RunReqAdmin Edited April 22, 2013 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
HockeyFan Posted April 22, 2013 Author Share Posted April 22, 2013 This is not how RunAsWait() works. It will only shell a program, not a function. It cannot perform another AutoIt3 function in this way with alleviated rights! This is an UDF I use that can do that: Func RunReqAdmin($Autoit3Commands, $prompt = 0) Local $temp_Script = _TempFile(@TempDir, "~", ".au3") Local $temp_check = _TempFile(@TempDir, "~", ".chk") FileWriteLine($temp_check, 'TempFile') FileWriteLine($temp_Script, '#NoTrayIcon') If Not IsAdmin() Then FileWriteLine($temp_Script, '#RequireAdmin') If $prompt = 1 Then MsgBox(262144, "Need Admin mode", "Admin mode is needed for this update. Answer the following prompts to allow the update.") EndIf FileWriteLine($temp_Script, $Autoit3Commands) FileWriteLine($temp_Script, "FileDelete('" & $temp_check & "')") If @Compiled Then RunWait('"' & @ScriptFullPath & '" /AutoIt3ExecuteScript "' & $temp_Script & '"') Else RunWait('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $temp_Script & '"') EndIf ; Wait for the script to finish While FileExists($temp_check) Sleep(50) WEnd FileDelete($temp_Script) EndFunc ;==>RunReqAdmin Jos, That makes sense, though I wasn't sure when the script line passed the syntax checker. To be honest, I'm not sure I totally understand your Func. Wouldn't it be the same thing if I just called an external script in the RunAsWait command? What are you passing to the Func using the $Autoit3Commands parameter? Am I wrong that this Func still requires a non-admin user to provide elevated credintials to work? That's one of the things I was trying to get around and why I didn't use #RequireAdmin. My appologies for being a little confused...my normal S.O.P...but thanks for the reply and information. HockeyFan Link to comment Share on other sites More sharing options...
Developers Jos Posted April 22, 2013 Developers Share Posted April 22, 2013 All the UDF does is build a temp script in a tempfile adding #NoTrayIcon and #RequireAdmin on the first 2 lines. Then adding your function and running shelling itself with the tempfile as inputscript. The "/AutoIt3ExecuteScript" parameter will tell the Script EXE to execute the new input file and not the embedded script. Does that make sense? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
HockeyFan Posted April 22, 2013 Author Share Posted April 22, 2013 All the UDF does is build a temp script in a tempfile adding #NoTrayIcon and #RequireAdmin on the first 2 lines.Then adding your function and running shelling itself with the tempfile as inputscript.The "/AutoIt3ExecuteScript" parameter will tell the Script EXE to execute the new input file and not the embedded script.Does that make sense?Jos Jos,Sorry if I wasn't clear. I was confused about the $Autoit3Commands paramater in the Func name...Func RunReqAdmin($Autoit3Commands, $prompt = 0). What are you passing into the Func with that paramater? Thank you for the explaination though!!. I still will need the final outcome of my script to not propmt the user to provide elevated rights. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 23, 2013 Developers Share Posted April 23, 2013 This is an example from from SciTEConfig: RunReqAdmin("RegWrite('HKEY_CLASSES_ROOT\AutoIt3Script\Shell', '', 'REG_SZ', 'Run')") RunReqAdmin("RegWrite('HKEY_CLASSES_ROOT\AutoIt3ScriptBeta\Shell', '', 'REG_SZ', 'Run')") Just think in terms of a script to run in Admin mode. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
HockeyFan Posted April 23, 2013 Author Share Posted April 23, 2013 This is an example from from SciTEConfig: RunReqAdmin("RegWrite('HKEY_CLASSES_ROOT\AutoIt3Script\Shell', '', 'REG_SZ', 'Run')") RunReqAdmin("RegWrite('HKEY_CLASSES_ROOT\AutoIt3ScriptBeta\Shell', '', 'REG_SZ', 'Run')") Just think in terms of a script to run in Admin mode. Jos Thanks Jos, ...and thanks for you help with this. I appreciate it!! Learned something new today. 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