Results 1 to 18 of 18

Thread: Use Run Task in Background

  1. #1

    Thread Starter
    Lively Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Kentucky
    Posts
    95

    Question Use Run Task in Background

    What I am trying to accomplish is similiar to the process.start("app.exe") command except this does not fill my needs. When you press windows + R on your keyboard running windows, you get the run windows task dialog, I need to use this tool to launch specific tasks. Some are applications, utilities, and directories. Strictly, only this tool will launch the task guarenteed.

    Right now, I have been using process.start("cmd.exe").
    But when I use process.start("documents"), the documents folder will not pop up, for example.
    So my code does not really work. Any suggestions? I'd like this to be accomplished in the background as well.

    Here is a few example of codes that I need to be able to run to test.
    cmd.exe
    msconfig
    msinfo32
    documents
    c:\
    wmimgmt.msc

    If these 6 tasks work, then the code will more than likely work for me
    Thank you!

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Use Run Task in Background

    process.start("documents") is not a valid directory. Where have you decided from that "directory" will open anything?

  3. #3

    Thread Starter
    Lively Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Kentucky
    Posts
    95

    Re: Use Run Task in Background

    Quote Originally Posted by ident View Post
    process.start("documents") is not a valid directory. Where have you decided from that "directory" will open anything?


    Right, I understand your argument. If you click windows + R on the keyboard, you will have the “run task” dialog pop up, from there, documents IS a valid entry. By typing documents and hitting enter, the application will open file explorer to the documents folder. I know documents is not an actual directory and that is why process.start will not work for this. I need some sort of “engine” to use in order to process my commands through the “run task” tool.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Use Run Task in Background

    If you want to open a file or folder then specify the path. You can get the path for various special folders, including the user's Documents folder, using Environment.GetFolderPath or My.Computer.FileSystem.SpecialDirectories.

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Use Run Task in Background

    Well did you ever give any hint of that in any previous post above?

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Use Run Task in Background

    Quote Originally Posted by jmcilhinney View Post
    If you want to open a file or folder then specify the path. You can get the path for various special folders, including the user's Documents folder, using Environment.GetFolderPath or My.Computer.FileSystem.SpecialDirectories.
    The OPs previous thread has issues depending on what CPU. I personally do not think anything that was said has been taken into account.

  7. #7
    Addicted Member
    Join Date
    Jan 2013
    Posts
    144

    Re: Use Run Task in Background

    Hi kshadow22,

    I'm not sure I'm getting what you want to accomplish here exactly. Do you want to offer your users a tool that simulates the Windows Run tool? If that is what you want then you can do it something like this:

    Just add a textbox and put this in the KeyDown even handler:
    Code:
            If e.KeyCode = Keys.Enter Then
                Dim UserCmd As String = LCase(TextBox1.Text)
                Select Case UserCmd
                    Case "cmd"
                        Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\cmd.exe")
                    Case "msconfig"
                        Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msconfig.exe")
                    Case "msinfo32"
                        Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msinfo32.exe")
                    Case "documents"
                        Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
                    Case "c:\"
                        Process.Start("C:\")
                    Case "wmimgmt.msc"
                        Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\wmimgmt.msc")
                End Select
            End If
    You can add as many commands you want.

    Hope that helps.

  8. #8

    Thread Starter
    Lively Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Kentucky
    Posts
    95

    Re: Use Run Task in Background

    Quote Originally Posted by cPubis View Post
    Hi kshadow22,

    I'm not sure I'm getting what you want to accomplish here exactly. Do you want to offer your users a tool that simulates the Windows Run tool? If that is what you want then you can do it something like this:

    Just add a textbox and put this in the KeyDown even handler:
    Code:
            If e.KeyCode = Keys.Enter Then
                Dim UserCmd As String = LCase(TextBox1.Text)
                Select Case UserCmd
                    Case "cmd"
                        Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\cmd.exe")
                    Case "msconfig"
                        Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msconfig.exe")
                    Case "msinfo32"
                        Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msinfo32.exe")
                    Case "documents"
                        Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
                    Case "c:\"
                        Process.Start("C:\")
                    Case "wmimgmt.msc"
                        Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\wmimgmt.msc")
                End Select
            End If
    You can add as many commands you want.

    Hope that helps.

    Yes, that is what I am trying to accomplish, thank you. Sorry for being even more difficult, but is there a more simple way of doing this? More specifically, is there a way I can use this tool in the background and input data and execute it? I have over 100 plus commands that I have for a user to select from. Thank you for your time and help.

  9. #9
    Addicted Member
    Join Date
    Jan 2013
    Posts
    144

    Re: Use Run Task in Background

    Quote Originally Posted by kshadow22 View Post
    is there a way I can use this tool in the background and input data and execute it?
    Please explain, what do you mean by "use this tool in the background"? If you mean making it work without any GUI then how could your users input the data then?

  10. #10

    Thread Starter
    Lively Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Kentucky
    Posts
    95

    Re: Use Run Task in Background

    Quote Originally Posted by cPubis View Post
    Please explain, what do you mean by "use this tool in the background"? If you mean making it work without any GUI then how could your users input the data then?
    I have a listbox with items in which they can select which work in the run task command. My plan is that when they select the command, it automatically processes the command through the run task dialog in the background. When using the run task tool, you need to know the command in order to execute it. What I am trying to accomplisih is a tool that is like the same, except you don't need to remember all of the commands because the listbox has nearly all the common ones you should need for any event. Thank you for your reply

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Use Run Task in Background

    There are several ways to do that, probably the easiest is to use the same kind of Select Case shown in post #7, just get the UserCmd value from the ListBox item instead of a textbox.

  12. #12
    Addicted Member
    Join Date
    Jan 2013
    Posts
    144

    Re: Use Run Task in Background

    It's almost the same, just put the code I gave you in the SelectedIndexChanged of the ListBox and you're fine. Something like this: (change the listbox items names to your actual names)

    Code:
    Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
            Dim UserCmd As String = ListBox1.Text
            Select Case UserCmd
                Case "Command Prompt"
                    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\cmd.exe")
                Case "System Configuration"
                    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msconfig.exe")
                Case "System Information"
                    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msinfo32.exe")
                Case "Documents"
                    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
                Case "Drive C:\"
                    Process.Start("C:\")
                Case "Management Console"
                    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\wmimgmt.msc")
            End Select
        End Sub
    Now your user just need to click "System Configuration" item and msconfig will run.

    Hope that helps

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Use Run Task in Background

    Quote Originally Posted by cPubis View Post
    It's almost the same, just put the code I gave you in the SelectedIndexChanged of the ListBox and you're fine.
    That's really not a good idea. I know that it addresses the OP's request but the request is bad. What if the user has already selected the first item in the list and they want to selected the last item using the keyboard? A developer should never assume that the mouse will always be used for something that the keyboard can be used for too. In that case, your code would execute every single command when the user only wants the last one.

  14. #14
    Addicted Member
    Join Date
    Jan 2013
    Posts
    144

    Re: Use Run Task in Background

    Quote Originally Posted by jmcilhinney View Post
    A developer should never assume that the mouse will always be used for something that the keyboard can be used for too.
    I agree, but as you said it was the OP's request.

    Now kshadow22, in case you didn't figure out how to avoid this, here you go:

    Code:
    Public Class Form1
    
        Private Sub ListBox1_DoubleClick(sender As Object, e As System.EventArgs) Handles ListBox1.DoubleClick
            RunTool()
        End Sub
    
        Private Sub ListBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles ListBox1.KeyDown
            If e.KeyCode = Keys.Enter Then
                RunTool()
            End If
        End Sub
    
        Private Sub RunTool()
            Dim UserCmd As String = ListBox1.Text
            Select Case UserCmd
                Case "Command Prompt"
                    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\cmd.exe")
                Case "System Configration"
                    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msconfig.exe")
                Case "System Information"
                    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\msinfo32.exe")
                Case "Documents"
                    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
                Case "Drive C:\"
                    Process.Start("C:\")
                Case "Managment Console"
                    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\wmimgmt.msc")
            End Select
        End Sub
    End Class
    Now you can select the item and press Enter or just double click the item.

    Hope that helps.

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Use Run Task in Background

    Quote Originally Posted by cPubis View Post
    I agree, but as you said it was the OP's request.
    I would suggest we should point out to the OP the shortcomings of their request even if we provide a solution. It would be far from ideal if they just accepted that solution, implemented it, deployed it and then had users complaining that it didn't work.

  16. #16
    Addicted Member
    Join Date
    Jan 2013
    Posts
    144

    Re: Use Run Task in Background

    Quote Originally Posted by jmcilhinney View Post
    I would suggest we should point out to the OP the shortcomings of their request even if we provide a solution. It would be far from ideal if they just accepted that solution, implemented it, deployed it and then had users complaining that it didn't work.
    I unreservedly agree with that.

  17. #17
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Use Run Task in Background

    Quote Originally Posted by cPubis View Post
    I unreservedly agree with that.
    That said, you should be teaching the OP how to correctly build paths.

  18. #18
    Addicted Member
    Join Date
    Jan 2013
    Posts
    144

    Re: Use Run Task in Background

    Quote Originally Posted by ident View Post
    That said, you should be teaching the OP how to correctly build paths.
    In this very thread, jmc preceded me to that, and he did it professionally as usual. Repeating what he said was unnecessary. If you looked at my first reply to the OP you will see that it's just a practical example of what jmc said in his first reply to the OP.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width