Jump to content

MHz

MVPs
  • Posts

    5,552
  • Joined

  • Last visited

  • Days Won

    3

MHz last won the day on September 17 2013

MHz had the most liked content!

1 Follower

About MHz

  • Birthday 08/27/1965

Profile Information

  • Member Title
    Just simple
  • Location
    Australia
  • WWW
    http://users.tpg.com.au/mpheath/
  • Interests
    Using Autoit3 and using AutoIt3...

Recent Profile Visitors

1,670 profile views

MHz's Achievements

  1. I am curious, how do you get out of that While loop? I see no break out of loop. The solution seems to me is to check @error from StdOutRead() in which to break out of the loop and then progress with exitloop.
  2. Your result is different to mine. This is what I copy from the msgbox. --------------------------- --------------------------- The output string is: "This is the var: Banana " --------------------------- OK --------------------------- I am testing with the AutoIt code I posted above and using this file named test.cmd. @echo off set /p "var=Input Var: " echo This is the var: %var% I cannot explain why you have output of the volume information. I am currently using Windows 7 x64 with AutoIt 3.3.10.2. AutoIt script is being run uncompiled from Scite. Repeatedly testing I get the same output. I am confused.
  3. GeorgeR, My observation still stands. Upon running the script as you have stated and I can confirm, as user, the drives do show including the network drives. Running runas gives me a UAC prompt. I go humm, click OK. I see drives but no network drives show. The admin me cannot access/see the user me drives. You may find documentation (MSDN) about scripts needing to map their own network drives if runas/elevation is being used to change the user. In your case, you are George but not the same George (yeah, sounds insane). i.e. you are using a different token as in different permissions. I would expect it to work with UAC off though perhaps water has a point with it being an OS issue.
  4. This line actually needs a variable named %var % to get the value (note the whitespace). Environmental variable can be almost any character including spaces as you have a space. Using StdinWrite is a PITA as you may need to keep looping until StdinWrite is needed and then get out at the right time. Usually Stdoutread will not error until the StdIn stream is closed. This seems to work though have doubt I have done well with this example. The constants gave me issues with my version of AutoIt so they went bye bye. Example() Func Example() Local $sOutput = "" ; Store the output of StdoutRead to a variable. Local $iPID = Run("cmd /q /c test.cmd", "", @SW_SHOW, 3) ; Get the initial data output here. Do Sleep(10) $sOutput &= StdoutRead($iPID) ; Read the Stdout stream of the PID returned by Run. Until @extended ; Clear the output here. $sOutput = '' ; Send the input. StdinWrite($iPID, "Banana" & @CRLF) ; Close the input stream so StdoutRead sets error. StdInWrite($iPID) ; Get the rest of the data. Do Sleep(10) $sOutput &= StdoutRead($iPID) Until @error ; Show the result. MsgBox(0, "", "The output string is: " & @CRLF & '"' & $sOutput & '"') EndFunc ;==>Example
  5. Seems strange. When you double start the au3 file, you are the user George. When you runas George, you are most probably using the admin token of George and cannot see the user George network drives. Perhaps a side effect of UAC. Just an observation. Unless you are admin initially and runas is just churning you into a simple (limited) user.
  6. A script controls its own mapping of drives. i.e, Script Tom runs script and sees drives as Tom as seeing mapped network drives of Tom. Script Tom runs as other user does not see mapped network drives. Admin allocated network drives not seen ... and on it goes. Based on permissions. Admin does not see user mapped drives.
  7. Nice code Jon. Out of interest of sharing, I did this quite some time back about a query about the Disk Cleanup Tool (DCT) and never got to share. Link to a HTA file based on Microsoft documentation (not mine, just my altered DCT for dummies). I use Disk Cleanup Tool for my log off script script event so it has|is been useful. It (DCT) can be programmed. Examples are CMD as PS. arrrgh fails setting workingdir with [] in the path to the script. Regards to old friends.
  8. When an adlib registered function is called, the main code ceases running (paused) until the adlib function returns. If you want to repeat your main code, then think of a loop. You then can use ContinueLoop and Exitloop to control the flow. Recalling functions within functions is going to most likely cause issues. While 1 ; code to repeat here WEnd A registered adlib function is best to be independent from the main code. Calling the main function from an adlib function is trying to interrupt with the flow of the main code and is going to cause issues. It is usually good for the adlib function to assist with events rather then trying to dominate the flow of the main code based on the events. If Send is going to be the main method of interaction, then consider using SendKeepActive as the Sent keys will become less error prone to fail due to unexpected reasons. I have done in the past some tests with SendKeepActive and it seems to make the windows like magnetic to the sent keys with keeping activation. SendKeepActive works surprising well and deserves more attention then what it currently gets. I have probably broken more then I fixed as the code being automation based. It is more of a hack rather then a clean rewrite. Automation is quite testing yet alone my guessing with code changes to make a ideal script of your code. So, this is more of a guide rather then a final solution. Guaranteed to work? No. I consider that it could be improved. HotKeySet("{ESC}", "Terminate") Opt('SendKeyDelay', 500) ; This slows down all Sent keys sl all those Sleeps are not needed. ; Want to main code going, use a loop. While 1 If SendKeepActive("[CLASS:XLMAIN]") Then ;This step activates Excel, strikethrough, arrow down, copy Send("^5") Send("{DOWN}") Send("^c") If SendKeepActive("[CLASS:MRWF]") Then ;This step acivates my target program, pastes what was copied, then enters text. zerobal("[CLASS:MRWF]") ;But at this point, it might hit an error, so I need it to stop the main function and go down to this adlib, which it does, but main seems to keep running as well If @error Then ContinueLoop Sleep(300) ; + delay = 800 Send("!v") agency("[CLASS:MRWF]") ;if the previous chokepoint was passed, there's the possibility of another error here, so I need adlib to handle it and main to stop and restart after adlib handled it. If @error Then ContinueLoop Send("text goes here") Send("{ENTER}") agency("[CLASS:MRWF]") If @error Then ContinueLoop Send("Y") Send("{ENTER}") agency("[CLASS:MRWF]") If @error Then ContinueLoop EndIf EndIf WEnd Func Terminate() Exit EndFunc Func agency($resume_title = '') Local $flag_error ; if an event occurs, this will be set to true so that error is set at the end of the function. If WinActivate("Yes/No Confirmation") Then Send("Y") $flag_error = True ;This is the end of a successful run, I just need it to start over, but it gets hinky because the main kept running so its like main is running twice at once. EndIf If WinExists("Error") And SendKeepActive("Error") Then Send("{ENTER}") Send("{F10}") Send("{F11}") Send("Y") $flag_error = True ;if it hit this error, I need it to handle it with these steps, but on the next run of main, it gets hinky. EndIf If Not ($resume_title == '') Then SendKeepActive($resume_title) If $flag_error Then SetError(1) EndFunc Func zerobal($resume_title = '') Local $flag_error If WinExists("Error") And SendKeepActive("Error") Then Send("{ENTER}") Send("{F10}") $flag_error = True ;Same deal down here if it hit this error EndIf If Not ($resume_title == '') Then SendKeepActive($resume_title) If $flag_error Then SetError(1) EndFunc I used an Opt() to cause a send keys delay so as to get rid of most of those Sleeps. Edit: Update zerobal function with a SendKeepActive call.
  9. I just noticed an issue of destroying a CtrlID on a review. In your loop, this case. Case $newitem $newitem = FileSaveDialog("Choose file...", @TempDir, "All (*.*)") Saving the result to $newitem is not advised as it is already used for the id of a created menu item in the gui. Something for you to fix.
  10. Use /q to turn off echo. $var needs to outside the string to use its value. Local $var = FileSelectFolder("autoit script", "") If Not @error Then RunWait('"' & @ComSpec & '" /q /c title autoitscript & attrib -h -r -s /s /d "' & $var & '\*.*"') EndIf
  11. You have a 2nd GUIGetMsg() which is having an effect on the flow of the loop. Comment that out and it works much better. I changed the conditions in the loop to use Switch..EndSwitch as some have recommended so it will work better hopefully. FileOpenDialog changes the working directory so passing @WorkingDir as a parameter to _FillLists() seems more suited then passing the selected files path and replacing Openfile.txt to get the same result. More could be improved though I do not want to change too much which may confuse you. Some use of arrays could help to shrink the code down but I am not sure of your current experience level for changing any of that. See if this helps. $_FF_COM_TRACE = True #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> ;#include <FF.au3> #include <staticConstants.au3> #include <IE.au3> #include <String.au3> #include <Excel.au3> #include <FileConstants.au3> #include <IE.au3> #include <String.au3> #include <GUIConstantsEx.au3> #include "GUIExtender.au3" #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $oIE ;, BitOR($WS_BORDER, $WS_VSCROLL) ;_FFStart( "https://www.google.nl" ) ;WinSetState ( "Google - Mozilla Firefox", "", @SW_MINIMIZE ) ;~ _GUIExtender_Init($Form1_1_1_1) FileWrite(@ScriptDir & "\Openfile.txt", "text") For $i = 1 To 13 FileDelete(@ScriptDir & "\list" & $i & ".txt") FileWrite(@ScriptDir & "\list" & $i & ".txt", "text " & $i) Next Global $iIndex = 0 #Region ### START Koda GUI section ### Form= $Form1_1_1_1 = GUICreate("program", 814, 713, 697, 101) $Button1 = GUICtrlCreateButton("Next", 208, 0, 41, 25) $List1 = GUICtrlCreateList("", 0, 64, 145, 358) GUICtrlSetData(-1, "") $List2 = GUICtrlCreateList("", 144, 64, 65, 358) GUICtrlSetData(-1, "") $List3 = GUICtrlCreateList("", 208, 64, 65, 358) GUICtrlSetData(-1, "") $List4 = GUICtrlCreateList("", 344, 64, 153, 358) GUICtrlSetData(-1, "") $List5 = GUICtrlCreateList("", 496, 64, 65, 358) GUICtrlSetData(-1, "") $List6 = GUICtrlCreateList("", 560, 64, 121, 230) GUICtrlSetData(-1, "") $List7 = GUICtrlCreateList("", 680, 64, 65, 230) GUICtrlSetData(-1, "") $List8 = GUICtrlCreateList("", 744, 64, 65, 230) GUICtrlSetData(-1, "") $List9 = GUICtrlCreateList("", 272, 64, 65, 358) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) Local $helpmenu, $infoitem, $exititem, $recentfilesmenu Local $viewmenu, $viewstatusitem Local $statuslabel, $msg, $file $filemenu = GUICtrlCreateMenu("&File") $fileitem = GUICtrlCreateMenuItem("Open", $filemenu) GUICtrlSetState(-1, $GUI_DEFBUTTON) $newitem = GUICtrlCreateMenuItem("new", $filemenu) $helpmenu = GUICtrlCreateMenu("?") GUICtrlCreateMenuItem("Save", $filemenu) GUICtrlSetState(-1, $GUI_DISABLE) $infoitem = GUICtrlCreateMenuItem("Info", $helpmenu) $exititem = GUICtrlCreateMenuItem("Exit", $filemenu) $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu, 1) GUICtrlCreateMenuItem("", $filemenu, 2) ; create a separator line $viewmenu = GUICtrlCreateMenu("View", -1, 1) ; is created before "?" menu $viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu) $message4 = GUICtrlCreateMenuItem("message", $filemenu) GUICtrlSetState(-1, $GUI_FOCUS) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 $msg = GUIGetMsg() Switch $msg Case $fileitem ConsoleWrite("Hit" & @CRLF) ; Find Openfile.txt to get change the working directory to where it exists. $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)", 1, "Openfile.txt") If Not @error Then GUICtrlCreateMenuItem($file, $recentfilesmenu) ; FileOpenDialog changes the working directory to the selected files location. This is what you want? _FillLists(@WorkingDir) EndIf Case $newitem $newitem = FileSaveDialog("Choose file...", @TempDir, "All (*.*)") Case $viewstatusitem If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED) GUICtrlSetState($statuslabel, $GUI_HIDE) Else GUICtrlSetState($viewstatusitem, $GUI_CHECKED) GUICtrlSetState($statuslabel, $GUI_SHOW) EndIf Case $GUI_EVENT_CLOSE, $exititem ExitLoop Case $infoitem MsgBox($MB_SYSTEMMODAL, "Info", "Only a test...") Case $Button1 _pluseen($Button1) EndSwitch WEnd GUIDelete() #EndRegion ### END Koda GUI section ### Func _FillLists($file) ; The next 2 lines seem to be obsolete. ;~ Local $newfile = StringReplace($file, "Openfile.txt", "") ;~ $1newfile = ($newfile & ("lists\list")) ; $file will be the working directory path changed with previous use of FileOpenDialog Local $1newfile = $file & '\list' Global $iIndex = 0, $sListData1 = ($1newfile & ("1.txt")) Global $sListFile1 = ($1newfile & ("1.txt")) Global $iIndex = 0, $sListData2 = ($1newfile & ("2.txt")) Global $sListFile2 = ($1newfile & ("2.txt")) Global $iIndex = 0, $sListData3 = ($1newfile & ("3.txt")) Global $sListFile3 = ($1newfile & ("3.txt")) Global $iIndex = 0, $sListData4 = ($1newfile & ("4.txt")) Global $sListFile4 = ($1newfile & ("4.txt")) Global $iIndex = 0, $sListData5 = ($1newfile & ("5.txt")) Global $sListFile5 = ($1newfile & ("5.txt")) Global $iIndex = 0, $sListData6 = ($1newfile & ("6.txt")) Global $sListFile6 = ($1newfile & ("6.txt")) Global $iIndex = 0, $sListData7 = ($1newfile & ("7.txt")) Global $sListFile7 = ($1newfile & ("7.txt")) Global $iIndex = 0, $sListData8 = ($1newfile & ("8.txt")) Global $sListFile8 = ($1newfile & ("8.txt")) Global $iIndex = 0, $sListData9 = ($1newfile & ("9.txt")) Global $sListFile9 = ($1newfile & ("9.txt")) Global $iIndex = 0, $sListData10 = ($1newfile & ("10.txt")) Global $sListFile10 = ($1newfile & ("10.txt")) Global $iIndex = 0, $sListData11 = ($1newfile & ("11.txt")) Global $sListFile11 = ($1newfile & ("11.txt")) Global $iIndex = 0, $sListData12 = ($1newfile & ("12.txt")) Global $sListFile12 = ($1newfile & ("12.txt")) Global $iIndex = 0, $sListData13 = ($1newfile & ("13.txt")) Global $sListFile13 = ($1newfile & ("13.txt")) ; Read saved file if it exists-------- If FileExists($sListFile1) Then $sListData1 = FileRead($sListFile1) Else MsgBox($MB_SYSTEMMODAL, "Error", $sListFile1 & " does not exist") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf ; Load data read from the file GUICtrlSetData($List1, $sListData1) _GUICtrlListBox_SetCurSel($List1, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile2) Then $sListData2 = FileRead($sListFile2) EndIf ; Load data read from the file GUICtrlSetData($List2, $sListData2) _GUICtrlListBox_SetCurSel($List2, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile3) Then $sListData3 = FileRead($sListFile3) EndIf ; Load data read from the file GUICtrlSetData($List3, $sListData3) _GUICtrlListBox_SetCurSel($List3, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile4) Then $sListData4 = FileRead($sListFile4) EndIf ; Load data read from the file GUICtrlSetData($List4, $sListData4) _GUICtrlListBox_SetCurSel($List4, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile5) Then $sListData5 = FileRead($sListFile5) EndIf ; Load data read from the file GUICtrlSetData($List5, $sListData5) _GUICtrlListBox_SetCurSel($List5, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile6) Then $sListData6 = FileRead($sListFile6) EndIf ; Load data read from the file GUICtrlSetData($List6, $sListData6) _GUICtrlListBox_SetCurSel($List6, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile7) Then $sListData7 = FileRead($sListFile7) EndIf ; Load data read from the file GUICtrlSetData($List7, $sListData7) _GUICtrlListBox_SetCurSel($List7, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile8) Then $sListData8 = FileRead($sListFile8) EndIf ; Load data read from the file GUICtrlSetData($List8, $sListData8) _GUICtrlListBox_SetCurSel($List8, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile9) Then $sListData9 = FileRead($sListFile9) EndIf ; Load data read from the file GUICtrlSetData($List9, $sListData9) _GUICtrlListBox_SetCurSel($List9, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile10) Then $sListData10 = FileRead($sListFile10) EndIf EndFunc Func _pluseen($Button1) $iIndex += 1 _GUICtrlListBox_SetCurSel($List1, $iIndex) _GUICtrlListBox_SetCurSel($List4, $iIndex) EndFunc ;
  12. In this case, your command starts with a double quote and you have more then 1 pair of quotes. CMD will strip the outer double quotes under this condition. A not so good example as I know wordpad will not redirect anything, though, it shows the behavior with the quotes: Run('cmd /k "%ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt"') See above how the command starts with a double quote and that more then 1 pair of double quotes exist in the command as "test file.txt" has whitespace in it. CMD will see this and will strip the outer double quotes. So the command run is like this where %programfiles% is not expanded yet but imagine it has expanded with the whitespace in the files path showing: %ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt It may generate an error such as: 'C:\Program' is not recognized as an internal or external command, operable program or batch file. which is breaking at the 1st instance of whitespace in the command. The command has inadequate quoting due to the behavior of CMD. If you look at CMD /? to see the reason for this behavior, you may see this. If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters: 1. If all of the following conditions are met, then quote character on the command line are preserved: - no /S switch - exactly two quote characters - no special characters between the two quote characters, where special is one of: &<>()@^| - there are one or more whitespace characters between the two quote characters - the string between the two quote characters is the name of an executable file. 2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character. The explanation of above is that the command uses /k. In condition 1, exactly two quote characters has not been met with the command. So condition 2 applies, thus it mentions about stripping quotes as being the 1st character and the last character. To counter this behavior, you insert additional quotes that can be stripped so the original command is left intact. So with this information mentioned, the command is changed to: Run('cmd /k ""%ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt""') Now the outer quotes will be stripped and the command processed will be this: "%ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt" and so no error should happen. At this point, you should probably be feeling better knowing how to resolve the behavior. A pair of backslashs i.e. separating segments of a path is interpreted the same as a single backslash by CMD i.e. . This is because within a path is meaningless as no path segment exists between the backslashs. Example of many backslashs: Run('cmd /k ""%ProgramFiles%\\\\\\\\\\Windows NT\Accessories\wordpad.exe" > "test file.txt""') All of those repetitive backslashs will be interpreted as 1 i.e. = . Probably not. My reference was to recognize your OS by your reference to "Documents and Settings". So long as you quote well, then issues hopefully will not happen.
  13. Ahh, quoting issues on Windows 2000/XP. Your commands with double quotes around $ffmpeg (as it contains whitespace) would be like this: $ffmpeg = @ScriptDir & "\bin\ffmpeg.exe" $ffmpegRecorder = '"' & $ffmpeg & '" -re -rtbufsize 100000k -i - -c:v "copy" -c:a "copy" -f "flv" testing447777.flv' MsgBox(0, 'View $ffmpegRecorder', $ffmpegRecorder) $ffmpegRecorder = '"C:\Documents and Settings\Desktop\appTesttig\bin\ffmpeg.exe" -re -rtbufsize 100000k -i - -c:v "copy" -c:a "copy" -f "flv" testing447777.flv' MsgBox(0, 'View $ffmpegRecorder', $ffmpegRecorder) ; Use single quote to wrap double quotes or the reverse usage or just double up the quotes. $var = '"' & "'" & '""' & "''" & """" & '''' MsgBox(0, 'View $var', $var)
  14. yamdi.exe is one file so if you have it in the working directory or %path% then it should be OK to access it by just its filename. Same can be said for the static build of ffmpeg.exe. Both files mention should have no other file dependencies. The working directory parameter of Run() that you show in red is the working directory that cmd will inherit. So if the command prompt window showed the prompt initially, it would be like C:temptest>. Thus, the commands of ffmpeg or yamdi look for the filenames in C:temptest. If the filenames are not found in the current working directory as being C:temptest in this case, then the paths in the %path% variable will be searched. If you are unsure that i.e. ffmpeg.exe is in path then try entering where ffmpeg.exe into a command prompt and see if it echos the path of where it exists. You can use absolute paths for yamdi.exe or ffmpeg.exe if you want. I am not sure how you want the paths to work (relative or absolute) so cannot give a precise answer.
  15. I use the static builds of FFMPEG so dependencies hopefully are not an issue. No issues so far for me to report. I just updated FFMPEG and I am still getting failure piping to YAMDI. I downloaded ffmpeg-20141110-git-064a237-win32-static.7z from this page. I have a custom folder that is permanently assigned to %path% of where I put all the files like ffmpeg.exe so it is easy to maintain. Testing with variations of like: Run('cmd /k ffmpeg -i "movie 1.flv" -c:v copy -c:a copy -f flv pipe:1 | yamdi -i - -o "movie 2.flv" -t nul.flv', 'c:\temp\test') of where "movie 1.flv" exists in the working directory of "c:temptest". Since a temp file seems to be needed if you stdin to YAMDI, then perhaps piping has little advantage compared to doing the task with separate 2 commands. All these tools may not follow a template so knowing how to use each one sometimes takes some skill with some luck. So 2 commands like below. It does not use copy parameters so does a convert with defaults. You may need to adjust the filenames and working directory for testing. Run('cmd /k "ffmpeg -i "movie 1.flv" -f flv "tmp.flv" && yamdi -i "tmp.flv" -o "movie 2.flv" && del "tmp.flv""', 'c:\temp\test') So the sequence is that FFMPEG converts "movie 1.flv" to tmp.flv. YAMDI reads tmp.flv and saves to "movie 2.flv" and then tmp.flv is deleted.
×
×
  • Create New...