gcue Posted May 11, 2015 Posted May 11, 2015 hello.i am trying to run FileFindFirstFile and FileFIndNextFile with RunAs either I am doing it wrong or there may be some limitations that I am not aware of.. the return values certainly do not look right - i get numbers instead of filenames. thanks in advance!expandcollapse popup#RequireAdmin #include <array.au3> $msg_normal = 0 $msg_error = 0 $tools_dir = "\\server\pdir\subdir" $ad_username = "uTest" $ad_password = "pTest" $sCmd = ' /AutoIt3ExecuteLine "FileExists(''' & $tools_dir & ''')"' $iReturn = RunAs($ad_username, @LogonDomain, $ad_password, 0, @AutoItExe & $sCmd) debug($iReturn) If Not FileExists($tools_dir) Then MsgBox($msg_error, "Check for Updates", $tools_dir & " is not accessible.") Exit EndIf $search_path = $tools_dir & "\script*.exe" ;~ $sCmd = ' /AutoIt3ExecuteLine "FileFindFirstFile(''' & $search_path & ''')"' $sCmd = '"' & @AutoItExe & '" /AutoIt3ExecuteLine ' & '"FileFindFirstFile(""' & $search_path & '"", "", Null)"' $remote_prod_search = RunAs($ad_username, @LogonDomain, $ad_password, 0, @AutoItExe & $sCmd);, @ScriptDir, "runas") debug($remote_prod_search) If $remote_prod_search = -1 Then FileClose($remote_prod_search) MsgBox($msg_error, "Check for Updates", "Script install file cannot be found in " & $tools_dir & ".") Exit EndIf While 1 $tCmd = ' /AutoIt3ExecuteLine "FileFindNextFile(''' & $remote_prod_search & ''')"' $file = RunAs($ad_username, @LogonDomain, $ad_password, 0, @AutoItExe & $tCmd);, @ScriptDir, "runas") If @error Then ExitLoop debug($file) $remote_prod_file = StringTrimRight($file, 4) WEnd FileClose($remote_prod_search) Debug($remote_prod_file) Func Debug($variable1 = "", $variable2 = "", $variable3 = "") If IsArray($variable1) Then _ArrayDisplay($variable1) Else If $variable2 <> "" Then $variable1 &= @CRLF & $variable2 EndIf If $variable3 <> "" Then $variable1 &= @CRLF & $variable3 EndIf ClipPut($variable1) MsgBox($msg_normal, "Debug", $variable1) EndIf EndFunc ;==>Debugexample adopted from:
BrewManNH Posted May 14, 2015 Posted May 14, 2015 You can't do this the way you want to. RunAs returns a PID, not a search handle to the files. What you're trying to do is impossible this way.The best you could do is to create a separate script and use RunAs to run that one. 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
gcue Posted May 14, 2015 Author Posted May 14, 2015 yea i was trying to avoid that.. o wellthank you very much!
AdamUL Posted May 14, 2015 Posted May 14, 2015 You could try re-execution of your script. This will run the whole script as a different user. This will require re-writing your script a bit. Here is a snippet that will help with the re-execution. Global $sUser = "USERNAME" Global $sPassword = "PASSWORD" Global $sDomain = "AD" Global $iLogOnFlag = 0 Global $sParameters = "" ;Run as a different user. If @UserName <> $sUser Then $sParameters = "" If Not @Compiled Then $sParameters = ' "' & @ScriptFullPath & '"' EndIf If RunAs($sUser, $sDomain, $sPassword, $iLogOnFlag, @AutoItExe & $sParameters) Then Exit Else Exit MsgBox(16 + 262144, "ERROR!", "Unable to run as " & $sUser & ".") EndIf EndIf ;Put rest of the script here.Adam
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