-
Nov 9th, 2018, 06:34 PM
#1
Thread Starter
Lively Member
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!
-
Nov 9th, 2018, 07:43 PM
#2
Re: Use Run Task in Background
process.start("documents") is not a valid directory. Where have you decided from that "directory" will open anything?
-
Nov 9th, 2018, 08:09 PM
#3
Thread Starter
Lively Member
Re: Use Run Task in Background
Originally Posted by ident
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.
-
Nov 9th, 2018, 09:06 PM
#4
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.
-
Nov 9th, 2018, 09:07 PM
#5
Re: Use Run Task in Background
Well did you ever give any hint of that in any previous post above?
-
Nov 9th, 2018, 09:09 PM
#6
Re: Use Run Task in Background
Originally Posted by jmcilhinney
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.
-
Nov 9th, 2018, 09:17 PM
#7
Addicted Member
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.
-
Nov 10th, 2018, 09:27 AM
#8
Thread Starter
Lively Member
Re: Use Run Task in Background
Originally Posted by cPubis
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.
-
Nov 10th, 2018, 09:44 AM
#9
Addicted Member
Re: Use Run Task in Background
Originally Posted by kshadow22
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?
-
Nov 10th, 2018, 11:49 AM
#10
Thread Starter
Lively Member
Re: Use Run Task in Background
Originally Posted by cPubis
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
-
Nov 10th, 2018, 12:13 PM
#11
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.
-
Nov 10th, 2018, 12:15 PM
#12
Addicted Member
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
-
Nov 10th, 2018, 09:02 PM
#13
Re: Use Run Task in Background
Originally Posted by cPubis
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.
-
Nov 10th, 2018, 10:02 PM
#14
Addicted Member
Re: Use Run Task in Background
Originally Posted by jmcilhinney
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.
-
Nov 10th, 2018, 10:40 PM
#15
Re: Use Run Task in Background
Originally Posted by cPubis
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.
-
Nov 10th, 2018, 10:45 PM
#16
Addicted Member
Re: Use Run Task in Background
Originally Posted by jmcilhinney
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.
-
Nov 11th, 2018, 03:41 PM
#17
Re: Use Run Task in Background
Originally Posted by cPubis
I unreservedly agree with that.
That said, you should be teaching the OP how to correctly build paths.
-
Nov 11th, 2018, 09:24 PM
#18
Addicted Member
Re: Use Run Task in Background
Originally Posted by ident
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|