Sign in to follow this  
Followers 0
acane

Check Disk Help

23 posts in this topic

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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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>

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites

@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>

Share this post


Link to post
Share on other sites

@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.

Share this post


Link to post
Share on other sites

#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

Share this post


Link to post
Share on other sites

Script is almost finished, help please!

Bump

Share this post


Link to post
Share on other sites

Looks like you are not testing for EOF after the FileReadLine() statement.

What do you suggest I do to fix it?

Thanks again!

Share this post


Link to post
Share on other sites

#12 ·  Posted (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 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 Gude
How 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

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 !!!

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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?


Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0