Sign in to follow this  
Followers 0
ReDFlaG

chkdsk and gui

10 posts in this topic

#1 ·  Posted (edited)

hello,

i'm coding a GUI for the chkdsk.exe utility.

i'm launching the dos tools in an hidden windows and grab the stdout in a var.

the issue is that sometimes chkdsk ask (y/n) (in case it has to reboot to do it stuff). how can i send it y or n?

$foo = Run(@SystemDir &'\chkdsk.exe ' &$numpart& ' /F', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
  $line = StdoutRead($foo)
  If @error Then ExitLoop
  If StringInStr($line,"(O/N)",0) Then
     $temp=MsgBox(1+48,"chkdsk","Chkdsk need to unmount the volume, do you want it to check the volume at the next reboot?")
     If $temp = 1  Then
     ?????

i started thinking about a StdinWrite($foo,"o" & @CR) but it's not the solution.

Can someone help?

thanks

Edited by ReDFlaG

Share this post


Link to post
Share on other sites



hello,

i'm coding a GUI for the chkdsk.exe utility.

i'm launching the dos tools in an hidden windows and grab the stdout in a var.

the issue is that sometimes chkdsk ask (y/n) (in case it has to reboot to do it stuff). how can i send it y or n?

$foo = Run(@SystemDir &'\chkdsk.exe ' &$numpart& ' /F', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$line = StdoutRead($foo)
If @error Then ExitLoop
If StringInStr($line,"(O/N)",0) Then
 $temp=MsgBox(1+48,"chkdsk","Chkdsk need to unmount the volume, do you want it to check the volume at the next reboot?")
 If $temp = 1  Then
 ?????

i started thinking about a StdinWrite($foo,"o" & @CR) but it's not the solution.

Can someone help?

thanks

Write the chkdsk data to a file, read the file and find the line with the [Y/N]

i.e. CHKDSK.EXE > TMP.TXT

Might be a better way with Autoit but this way should work just the same.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$foo = Run(@SystemDir & '\chkdsk.exe ' & $numpart & ' /F', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
$line = StdoutRead ($foo)
If @error Then ExitLoop
If StringInStr($line, "(O/N)", 0) Then
    $temp = MsgBox(1 + 48, "chkdsk", "Chkdsk need to unmount the volume, do you want it to check the volume at the next reboot?")
    If $temp = 1 Then
        Sleep(1000)
        $a = "chkdsk.exe"
        ControlSend($a, "", "", "Y"); if you wanna sent "Y"
        ControlSend($a, "", "", "N"); if you wanna sent "N"

Should work :)!

Edited by aceloc

[quote name='AceLoc']I gots new sunglasses there cool.[/quote]

Share this post


Link to post
Share on other sites

Thanks for your help, but it's not working. :P

The autoit help file says "ControlSend is only unreliable for command prompts as that works differently to normal windows (seems to check physical states rather than accepting the keystroke messages). For normal windows ControlSend should be way more reliable than a normal Send "

Annother idea? :)

Share this post


Link to post
Share on other sites

Thanks for your help, but it's not working. :D

The autoit help file says "ControlSend is only unreliable for command prompts as that works differently to normal windows (seems to check physical states rather than accepting the keystroke messages). For normal windows ControlSend should be way more reliable than a normal Send "

Annother idea? :)

$a = "chkdsk.exe"
        ControlSend($a, "", "", "Y"); if you wanna sent "Y"
        ControlSend($a, "", "", "N"); if you wanna sent "N"

the problem there is that the Control ID is still empty.. you need to look that for yourself.

(i dont know sure if ddos got a Control ID though.) it works like this:

ControlSend("title", "text", "control ID", "Whatever-you-wanna-sent")

Goodlucky :D:P


[quote name='AceLoc']I gots new sunglasses there cool.[/quote]

Share this post


Link to post
Share on other sites

Thanks for your help, but it's not working. :P

The autoit help file says "ControlSend is only unreliable for command prompts as that works differently to normal windows (seems to check physical states rather than accepting the keystroke messages). For normal windows ControlSend should be way more reliable than a normal Send "

Annother idea? :)

You can try it in a different approch...

1) Msgbox

2) Create an answer file

3) run command line chkdsk.exe $volume $switches < Answer.file

4) delete answer file

Example:

$temp = MsgBox(1 + 48, "chkdsk", "Chkdsk may need to unmount the volume, do you want it to check the volume at the next reboot?")
If $temp = 1 Then FileWriteLine(@TempDir & '\Answer.txt', 'y')
If $temp = 2 Then FileWriteLine(@TempDir & '\Answer.txt', 'n')

$numpart = 'c:'
RunWait(@ComSpec & ' /c chkdsk.exe ' & $numpart & ' /F < ' & @TempDir & '\Answer.txt', '', @SW_HIDE)
FileDelete(@TempDir & '\Answer.txt')

Hope this help you or least give an idea...


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

thanks again :)

i will try those solutions.

a small question: when you right click on a drive and choose propreties, then tools, you can do a "check now". it's fully graphical, and it ask if you want to reboot or not.

i'm not seeing any "chkdsk.exe" process into the task manager list, so i was wondering how does windows proceed to check the disk in that case.

some one has an hint?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

This works for me

#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

Not quite sure what you mean, so I will just ramble some babble at you.

The OS can not check the disk with the /f switch if its in use. So if you have a D: drive you can do a chkdsk without rebooting. But if you were to open a folder on D: drive then try to do chkdsk /f d: it would prompt you to do it on the next reboot like C: drive cause its in use. You will not see chkdsk in the process list waiting to check C: drive, it flags the drive as dirty. Whe the OS boots up it will check any disks with that flag set.

Edited by creeping

Share this post


Link to post
Share on other sites

thanks a lot to all of you, it's working perfectly. :lmao:

Share this post


Link to post
Share on other sites

thanks a lot to all of you, it's working perfectly. :)

Can you post you final code for this?

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