acane Posted May 17, 2011 Share Posted May 17, 2011 I'm trying to create an AutoIt script to open the run box, then start command prompt, start the check disk, and then press y when it prompts for it to start at next reboot. The problem I am running into is that I can't figure out what code to use to make the script recognize when the message pops up so it can't type y to allow for it. Here is what i have so far: Send("#r") Send ("{BACKSPACE}") Send ("cmd{ENTER}") Send ("chchkdsk c: /f{ENTER}") $fix=("Chkdsk cannot run because the volume is in use by another process.") If $fix Then Send ("y{ENTER}") EndIf When I run the script it does everything but then it gets to the message part and it just sits there. Any help would be appreciated. Thanks in advanced, Andrew Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 17, 2011 Share Posted May 17, 2011 See the Notepad Automation tutorial in the help file. That should get you going in the right direction. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
sleepydvdr Posted May 17, 2011 Share Posted May 17, 2011 You seem to be wanting to read the message from a DOS screen. I'm not sure how to do that. Perhaps an @error code may help. Your part of the code: "If $fix Then" must read the DOS screen then compare it to your variable. It would read something more like "If $errormessage = $fix Then". I do have one suggestion, however. Try this for starting the checkdisk (it would simplify the first 4 lines of your code): ShellExecute("Chkdsk") #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
BrewManNH Posted May 17, 2011 Share Posted May 17, 2011 You would use Run("chkdsk") instead of ShellExecute. While ShellExecute would run it, it's not meant for running executables, it's meant for running files with their associated program, such as a URL (ex. ShellExecute("http://www.google.com")) being run with the associated browser. Because you can't use ShellExecute to run a program under different credentials Run is more flexible. 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...
acane Posted May 17, 2011 Author Share Posted May 17, 2011 @somdcomputerguy: could you point me in the correct direction for that help file? @sleepydvdr: im going to try fiddling around with this script more tomorrow, can you explain what the @error command does and if i would have to create a new variable for the $errormessage thanks again, andrew Link to comment Share on other sites More sharing options...
sleepydvdr Posted May 17, 2011 Share Posted May 17, 2011 @sleepydvdr: im going to try fiddling around with this script more tomorrow, can you explain what the @error command does and if i would have to create a new variable for the $errormessage thanks again, andrew Some functions in AutoIt return an error code if something goes wrong. I didn't get any errors running your code, but I didn't go through the trouble of locking my hard drive to try to get one. I don't know if you would get an error code for the particular failure you have for your $fix. If you did, the code would look something like: Run("Chkdsk") ; Thanks BrewManNH, I learned something from you! If @error then Send ("y{ENTER}") EndIf #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 17, 2011 Share Posted May 17, 2011 @somdcomputerguy: could you point me in the correct direction for that help file?If you've installed AutoIt, the help file is in the directory you chose to install in. There's two online copies also, the links are in my sig. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
acane Posted May 24, 2011 Author Share Posted May 24, 2011 #requireadmin HotKeySet("{pgup}", "Terminate") Func Terminate( ) Exit EndFunc $cmd = "cmd.exe" Run($cmd) Send (" Chkdsk c: /f > c:\temp\chkdsk.txt{ENTER}") $hFileRead = FileOpen("c:\temp\chkdsk.txt", 0) If $hFileRead = -1 Then Exit EndIf While 1 $sLine = FileReadLine($hFileRead) If StringInStr($sLine, 'Chkdsk cannot run', 1) Then $active = WinActivate("C:\WINDOWS\system32\cmd.exe - chkdsk c: /f ", "") Send("y{ENTER}") Send("exit{ENTER}") EndIf WEnd FileClose($hFileRead) ControlSend("{pgup}" , "" , "" , 0) This is the script that i have created, it works for the most part but the script doesnt close once it is finished running. Can anybody give me some advice on how to have the script close the exe once its been ran? Thanks in advanced Link to comment Share on other sites More sharing options...
acane Posted May 27, 2011 Author Share Posted May 27, 2011 Script is almost finished, help please! Bump Link to comment Share on other sites More sharing options...
Developers Jos Posted May 27, 2011 Developers Share Posted May 27, 2011 Looks like you are not testing for EOF after the FileReadLine() statement. 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...
acane Posted May 31, 2011 Author Share Posted May 31, 2011 Looks like you are not testing for EOF after the FileReadLine() statement.What do you suggest I do to fix it?Thanks again! Link to comment Share on other sites More sharing options...
BrewManNH Posted May 31, 2011 Share Posted May 31, 2011 (edited) Change the While loop to this: While 1 $sLine = FileReadLine($hFileRead) If @error = - 1 then exitloop If StringInStr($sLine, 'Chkdsk cannot run', 1) Then $active = WinActivate("C:\WINDOWS\system32\cmd.exe - chkdsk c: /f ", "") Send("y{ENTER}") Send("exit{ENTER}") EndIf WEnd Now when it gets to the end of the file, the FileReadLine sets the @error macro and the error check will exit the loop at that point. Edited May 31, 2011 by BrewManNH 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...
acane Posted May 31, 2011 Author Share Posted May 31, 2011 Change the While loop to this: While 1 $sLine = FileReadLine($hFileRead) If @error = - 1 then exitloop If StringInStr($sLine, 'Chkdsk cannot run', 1) Then $active = WinActivate("C:\WINDOWS\system32\cmd.exe - chkdsk c: /f ", "") Send("y{ENTER}") Send("exit{ENTER}") EndIf WEnd The only problem that i have with this is that when i put it before the StringInStr line it closes it but it won't do the Send("y{ENTER}") part and if i put it after the StringInStr line then it doesn't close it Link to comment Share on other sites More sharing options...
BrewManNH Posted May 31, 2011 Share Posted May 31, 2011 Well, if you've read past the last line of the file, there's nothing to check against with StringInStr, so you want it to exit the loop at that point. An empty line would be the result, which means if you DON'T exit the loop at that point, it never will. 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...
roofninja Posted May 31, 2011 Share Posted May 31, 2011 I think that you are going at this the wrong way. If you are in CLI, then you will need to use StderrRead or StdoutRead to read the actions there, and StdinWrite to answer the message. That is my understanding of these commands. Reads from the STDERR stream of a previously run child process. StderrRead ( process_id[, peek = false[, binary = false]] ) Writes a number of characters to the STDIN stream of a previously run child process. StdinWrite ( process_id[, data] ) Reads from the STDOUT stream of a previously run child process. StdoutRead ( process_id[, peek = false[, binary = false]] ) RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!! Link to comment Share on other sites More sharing options...
acane Posted May 31, 2011 Author Share Posted May 31, 2011 I think that you are going at this the wrong way. If you are in CLI, then you will need to use StderrRead or StdoutRead to read the actions there, and StdinWrite to answer the message. That is my understanding of these commands. Reads from the STDERR stream of a previously run child process. StderrRead ( process_id[, peek = false[, binary = false]] ) Writes a number of characters to the STDIN stream of a previously run child process. StdinWrite ( process_id[, data] ) Reads from the STDOUT stream of a previously run child process. StdoutRead ( process_id[, peek = false[, binary = false]] ) So by using this method, would i have to still have the check disk write to the chkdsk.txt file or can it read it straight from the command prompt window? Link to comment Share on other sites More sharing options...
BrewManNH Posted June 1, 2011 Share Posted June 1, 2011 Look for a method someone else posted on how to do what you're looking to do with chkdsk. 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...
acane Posted June 1, 2011 Author Share Posted June 1, 2011 Look for a method someone else posted on how to do what you're looking to do with chkdsk. Thanks BrewMan, there was a script on there that accomplishes what i wanted to do. This is it for anybody else who might be wanting something similar. #include <Constants.au3> $PID = Run("chkdsk /f c:", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($PID) If @error Then ExitLoop If StringInStr($line, "(Y/N)") Then StdinWrite($PID, "Y" & @CRLF) StdinWrite($PID) ExitLoop EndIf WEnd Link to comment Share on other sites More sharing options...
acane Posted June 6, 2011 Author Share Posted June 6, 2011 Another question, the script in my previous post works only one time, then it creates a loop that opens up approximately 50 processes of the chkdsk.exe, can anybody point me in the correct direction as to stop the unnecessary openings on the program? Thanks in advanced again! Link to comment Share on other sites More sharing options...
JoHanatCent Posted June 8, 2011 Share Posted June 8, 2011 Another question, the script in my previous post works only one time, then it creates a loop that opens up approximately 50 processes of the chkdsk.exe, can anybody point me in the correct direction as to stop the unnecessary openings on the program?Thanks in advanced again!Mmmm .. interesting.Don't see why.Can you post maybe the whole script here? 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