dcsimg
Results 1 to 6 of 6

Thread: SendKeys.Send mess with me

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    3

    SendKeys.Send mess with me

    Hi!

    I want my code to open cmd and then change to an other hard drive. But instead bends lots of cmd come up.

    I don't know what the problem is, but here is the code.

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Startcmd As String = "C:\Windows\System32\cmd.exe"
            Process.Start(Startcmd)
            SendKeys.Send("H:" & "{ENTER}")
            Timer1.Enabled = True
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            SendKeys.Send("cd Program" & "{ENTER}")
            Timer1.Enabled = False
        End Sub
    End Class
    So i try to go frist to my D drive and then in to Program.

    Have you any clue what the problem is? Thanks for your answer.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: SendKeys.Send mess with me

    Process.Start is stating the process up and then continuing on with your code. The reason you are getting multiple CMD windows is that the command window is not yet open when you try and send the send keys, so it is sending an {Enter} to your app, which is firing your button click again.

    You basically have a timing issue here. Since cmd.exe doesn't have a graphical interface, you can't use WaitForInputIdle, so you will either have to put the drive change into your timer or rethink your approach.

    My first question is, why do you need to start a cmd.exe? Many times people do this so they can redirect output of a program to a file using piping, when you can actually redirect the standard output of a command line app to a stream and then write that to a file or a textbox.

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    3

    Re: SendKeys.Send mess with me

    Thanks for that, it help a lot.

    I have not think about that, because I'm pretty new in Visual Basic. But you tell me that I can do this "Process" without cmd? Have Visual Basic some function so you can do the same as with cmd?

    Sorry for my bad english, I hope you understand a little what I'm trying to say.

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: SendKeys.Send mess with me

    What are you trying to do?

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    3

    Re: SendKeys.Send mess with me

    A script that searches my folder. And then copy those file that I want.

  6. #6
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: SendKeys.Send mess with me

    You can do that through code:

    Code:
            For Each f In System.IO.Directory.GetFiles("C:\Temp")
    
                If IO.Path.GetFileName(f) = "fileyouarelookingfor.mp3" Then
                    MessageBox.Show("found the file")
                    IO.File.Copy(f, "C:\NewDirectory\" & IO.Path.GetFileName(f))
                End If
    
    
            Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width