Running chkdsk from my code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VGltIEh1bnRlcg==?=

    #1

    Running chkdsk from my code

    I am trying to run check disk on the c: (ntfs) on my computer via some code.
    I can launch the shell and give it the command to do the disk checking but it
    requires that I enter a "y" after some dialog in the cmd prompt comes up.
    Does anyone have a way to make this work?

    Thanks
  • =?Utf-8?B?aXdkdTE1?=

    #2
    RE: Running chkdsk from my code

    why not just use Process.Start(" chkdsk.exe") and pass in the parameters you
    want?
    --
    -iwdu15

    Comment

    • =?Utf-8?B?VGltIEh1bnRlcg==?=

      #3
      RE: Running chkdsk from my code

      because when you do that, it doesn't run the check disk. Do you think I
      would have to mark the disk as "dirty"?

      "iwdu15" wrote:
      why not just use Process.Start(" chkdsk.exe") and pass in the parameters you
      want?
      --
      -iwdu15

      Comment

      • =?Utf-8?B?aXdkdTE1?=

        #4
        RE: Running chkdsk from my code

        System.Diagnost ics.Process.Sta rt("chkdsk.exe" , "C:").WaitForEx it();

        worked for me just fine....how did it "not work"?
        --
        -iwdu15

        Comment

        • =?Utf-8?B?VGltIEh1bnRlcg==?=

          #5
          RE: Running chkdsk from my code

          because when I use the /f opition it still prompts for a yes or no answer.

          "iwdu15" wrote:
          System.Diagnost ics.Process.Sta rt("chkdsk.exe" , "C:").WaitForEx it();
          >
          worked for me just fine....how did it "not work"?
          --
          -iwdu15

          Comment

          • rowe_newsgroups

            #6
            Re: Running chkdsk from my code

            On Jun 19, 11:44 am, Tim Hunter <TimHun...@disc ussions.microso ft.com>
            wrote:
            because when I use the /f opition it still prompts for a yes or no answer.
            >
            "iwdu15" wrote:
            System.Diagnost ics.Process.Sta rt("chkdsk.exe" , "C:").WaitForEx it();
            >
            worked for me just fine....how did it "not work"?
            --
            -iwdu15
            Untested Console Project - let me know how it works:

            Imports System.Diagnost ics

            Module Module1

            Sub Main()
            Dim info As New ProcessStartInf o()
            info.FileName = "cmd.exe"
            info.UseShellEx ecute = False
            info.RedirectSt andardInput = True
            Using p As New Process()
            p.StartInfo = info
            p.Start()
            p.StandardInput .WriteLine("chk dsk c: /f")
            p.StandardInput .WriteLine("y")
            p.Close()
            End Using
            End Sub

            End Module

            Thanks,

            Seth Rowe

            Comment

            • =?Utf-8?B?VGltIEh1bnRlcg==?=

              #7
              Re: Running chkdsk from my code

              That progie below didn't work either. Any other thoughts out there?

              "rowe_newsgroup s" wrote:
              On Jun 19, 11:44 am, Tim Hunter <TimHun...@disc ussions.microso ft.com>
              wrote:
              because when I use the /f opition it still prompts for a yes or no answer.

              "iwdu15" wrote:
              System.Diagnost ics.Process.Sta rt("chkdsk.exe" , "C:").WaitForEx it();
              worked for me just fine....how did it "not work"?
              --
              -iwdu15
              >
              Untested Console Project - let me know how it works:
              >
              Imports System.Diagnost ics
              >
              Module Module1
              >
              Sub Main()
              Dim info As New ProcessStartInf o()
              info.FileName = "cmd.exe"
              info.UseShellEx ecute = False
              info.RedirectSt andardInput = True
              Using p As New Process()
              p.StartInfo = info
              p.Start()
              p.StandardInput .WriteLine("chk dsk c: /f")
              p.StandardInput .WriteLine("y")
              p.Close()
              End Using
              End Sub
              >
              End Module
              >
              Thanks,
              >
              Seth Rowe
              >
              >

              Comment

              • rowe_newsgroups

                #8
                Re: Running chkdsk from my code

                On Jun 19, 3:33 pm, Tim Hunter <TimHun...@disc ussions.microso ft.com>
                wrote:
                That progie below didn't work either. Any other thoughts out there?
                >
                >
                >
                "rowe_newsgroup s" wrote:
                On Jun 19, 11:44 am, Tim Hunter <TimHun...@disc ussions.microso ft.com>
                wrote:
                because when I use the /f opition it still prompts for a yes or no answer.
                >
                "iwdu15" wrote:
                System.Diagnost ics.Process.Sta rt("chkdsk.exe" , "C:").WaitForEx it();
                >
                worked for me just fine....how did it "not work"?
                --
                -iwdu15
                >
                Untested Console Project - let me know how it works:
                >
                Imports System.Diagnost ics
                >
                Module Module1
                >
                Sub Main()
                Dim info As New ProcessStartInf o()
                info.FileName = "cmd.exe"
                info.UseShellEx ecute = False
                info.RedirectSt andardInput = True
                Using p As New Process()
                p.StartInfo = info
                p.Start()
                p.StandardInput .WriteLine("chk dsk c: /f")
                p.StandardInput .WriteLine("y")
                p.Close()
                End Using
                End Sub
                >
                End Module
                >
                Thanks,
                >
                Seth Rowe- Hide quoted text -
                >
                - Show quoted text -
                What went wrong?

                I'm guessing it might be how quickly the "y" is written, try adding
                System.Threadin g.Thread.Sleep( 1000) before you send the "y" to the
                command prompt.

                Thanks,

                Seth Rowe

                Comment

                • Mudhead

                  #9
                  Re: Running chkdsk from my code

                  Dim proc As New Process
                  proc = Process.Start(" chkdsk.exe", "C /f")
                  Thread.Sleep(20 00) ' ----Give it some time
                  SendKeys.Send(" N~") '--Send N and Enter



                  "Tim Hunter" <TimHunter@disc ussions.microso ft.comwrote in message
                  news:665CCB47-F6BD-4FA1-A4BB-EAC2BC1AA7B1@mi crosoft.com...
                  That progie below didn't work either. Any other thoughts out there?
                  >
                  "rowe_newsgroup s" wrote:
                  >
                  >On Jun 19, 11:44 am, Tim Hunter <TimHun...@disc ussions.microso ft.com>
                  >wrote:
                  because when I use the /f opition it still prompts for a yes or no
                  answer.
                  >
                  "iwdu15" wrote:
                  System.Diagnost ics.Process.Sta rt("chkdsk.exe" , "C:").WaitForEx it();
                  >
                  worked for me just fine....how did it "not work"?
                  --
                  -iwdu15
                  >>
                  >Untested Console Project - let me know how it works:
                  >>
                  >Imports System.Diagnost ics
                  >>
                  >Module Module1
                  >>
                  > Sub Main()
                  > Dim info As New ProcessStartInf o()
                  > info.FileName = "cmd.exe"
                  > info.UseShellEx ecute = False
                  > info.RedirectSt andardInput = True
                  > Using p As New Process()
                  > p.StartInfo = info
                  > p.Start()
                  > p.StandardInput .WriteLine("chk dsk c: /f")
                  > p.StandardInput .WriteLine("y")
                  > p.Close()
                  > End Using
                  > End Sub
                  >>
                  >End Module
                  >>
                  >Thanks,
                  >>
                  >Seth Rowe
                  >>
                  >>

                  Comment

                  • Mudhead

                    #10
                    Re: Running chkdsk from my code

                    Use this if you want to suppress the command window:

                    Dim WithEvents proc As New Process

                    Private Sub RunChkdsk()
                    proc.StartInfo. FileName = "chkdsk.exe "
                    proc.StartInfo. Arguments = "C /f"
                    proc.StartInfo. UseShellExecute = False
                    proc.StartInfo. RedirectStandar dInput = True
                    proc.StartInfo. RedirectStandar dOutput = True
                    proc.StartInfo. CreateNoWindow = True
                    proc.EnableRais ingEvents = True
                    proc.Start()
                    proc.StandardIn put.WriteLine(" Y")
                    End Sub

                    Private Sub proc_Exited(ByV al sender As Object, ByVal e As System.EventArg s)
                    Handles proc.Exited
                    Dim fs As StreamReader = proc.StandardOu tput
                    Debug.WriteLine (fs.ReadToEnd)
                    fs.Close()
                    proc.Close()
                    End Sub



                    "Mudhead" <nowhere@here.c omwrote in message
                    news:eFw4zDrsHH A.5008@TK2MSFTN GP03.phx.gbl...
                    Dim proc As New Process
                    proc = Process.Start(" chkdsk.exe", "C /f")
                    Thread.Sleep(20 00) ' ----Give it some time
                    SendKeys.Send(" N~") '--Send N and Enter
                    >
                    >
                    >
                    "Tim Hunter" <TimHunter@disc ussions.microso ft.comwrote in message
                    news:665CCB47-F6BD-4FA1-A4BB-EAC2BC1AA7B1@mi crosoft.com...
                    >That progie below didn't work either. Any other thoughts out there?
                    >>
                    >"rowe_newsgrou ps" wrote:
                    >>
                    >>On Jun 19, 11:44 am, Tim Hunter <TimHun...@disc ussions.microso ft.com>
                    >>wrote:
                    >because when I use the /f opition it still prompts for a yes or no
                    >answer.
                    >>
                    >"iwdu15" wrote:
                    >System.Diagnos tics.Process.St art("chkdsk.exe ", "C:").WaitForEx it();
                    >>
                    >worked for me just fine....how did it "not work"?
                    >--
                    >-iwdu15
                    >>>
                    >>Untested Console Project - let me know how it works:
                    >>>
                    >>Imports System.Diagnost ics
                    >>>
                    >>Module Module1
                    >>>
                    >> Sub Main()
                    >> Dim info As New ProcessStartInf o()
                    >> info.FileName = "cmd.exe"
                    >> info.UseShellEx ecute = False
                    >> info.RedirectSt andardInput = True
                    >> Using p As New Process()
                    >> p.StartInfo = info
                    >> p.Start()
                    >> p.StandardInput .WriteLine("chk dsk c: /f")
                    >> p.StandardInput .WriteLine("y")
                    >> p.Close()
                    >> End Using
                    >> End Sub
                    >>>
                    >>End Module
                    >>>
                    >>Thanks,
                    >>>
                    >>Seth Rowe
                    >>>
                    >>>
                    >
                    >

                    Comment

                    • =?Utf-8?B?VGltIEh1bnRlcg==?=

                      #11
                      Re: Running chkdsk from my code

                      I found 2 answers to this the first is :

                      Shell("cmd /c echo Y | chkdsk c: /f/r", AppWinStyle.Nor malFocus, True)

                      the /c is what makes this work and

                      Shell("fsutil dirty set c:", AppWinStyle.Nor malFocus, True)
                      Sleep(100)
                      My.Computer.Reg istry.SetValue( "HKEY_LOCAL_MAC HINE\SYSTEM\CUR RENTCONTROLSET\ CONTROL\Session Manager", "BootExecut e", "autocheck autochk /r \??\C:")

                      Thanks for the help on this though.

                      "rowe_newsgroup s" wrote:
                      On Jun 19, 3:33 pm, Tim Hunter <TimHun...@disc ussions.microso ft.com>
                      wrote:
                      That progie below didn't work either. Any other thoughts out there?



                      "rowe_newsgroup s" wrote:
                      On Jun 19, 11:44 am, Tim Hunter <TimHun...@disc ussions.microso ft.com>
                      wrote:
                      because when I use the /f opition it still prompts for a yes or no answer.
                      "iwdu15" wrote:
                      System.Diagnost ics.Process.Sta rt("chkdsk.exe" , "C:").WaitForEx it();
                      worked for me just fine....how did it "not work"?
                      --
                      -iwdu15
                      Untested Console Project - let me know how it works:
                      Imports System.Diagnost ics
                      Module Module1
                      Sub Main()
                      Dim info As New ProcessStartInf o()
                      info.FileName = "cmd.exe"
                      info.UseShellEx ecute = False
                      info.RedirectSt andardInput = True
                      Using p As New Process()
                      p.StartInfo = info
                      p.Start()
                      p.StandardInput .WriteLine("chk dsk c: /f")
                      p.StandardInput .WriteLine("y")
                      p.Close()
                      End Using
                      End Sub
                      End Module
                      Thanks,
                      Seth Rowe- Hide quoted text -
                      - Show quoted text -
                      >
                      What went wrong?
                      >
                      I'm guessing it might be how quickly the "y" is written, try adding
                      System.Threadin g.Thread.Sleep( 1000) before you send the "y" to the
                      command prompt.
                      >
                      Thanks,
                      >
                      Seth Rowe
                      >
                      >

                      Comment

                      Working...