Answered by:
Create GUI for command line tool

Question
-
I am trying to create a gui/wrapper for the command line tool DISM.exe
I would like the user to be able to select a directory then press an 'ok' button that will send the directory to the DISM tool so it can run.
EX.
User selects directory from GUI -> Directory is sent to command line tool -> Command is processed with user submited data.
DISM.exe /e [UserSubmittedDirectoryHere]
Here is current code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Window1 : Form { public Window1() { InitializeComponent(); } private void Window1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { } } }
Friday, August 14, 2009 12:44 AM
Answers
-
>>I would like to split the task into two buttons:
>>Button 1 will select the path and enter it into a Text box displaying the Directory
>>Button 2 will run the Process.Start command
Something like this :
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
textBox1.Text = fbd.SelectedPath;
}
}private void button2_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(textBox1.Text))
{
Process.Start("DISM.exe", "/e " + textBox1.Text);
}
}
But seriously, get a good book on C#. You are asking some extremely basic stuff here.
http://blog.voidnish.comSaturday, August 15, 2009 5:59 PM
All replies
-
You can launch the executable with System.Diagnostics.Process.Start . You also can, optionally, reroute the process standard output back to your application, so you can display it in the GUI. This would work by creating an instance of a ProcessStartInfo class, and setting the RedirectStandardOutput property, then starting the process with that info.
This would go in your button click event handler.
Reed Copsey, Jr. - http://reedcopsey.comFriday, August 14, 2009 1:04 AM -
Sorry im really new to C# could you give me a code example?
I cant seem to make a Directory selection box.Friday, August 14, 2009 1:11 AM -
Sorry im really new to C# could you give me a code example?
I cant seem to make a Directory selection box.
See http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.aspx
http://blog.voidnish.comFriday, August 14, 2009 1:29 AM -
I need a more in depth answer the links provided do not help to understand how to use these functions.
Lets solve this one step at a time.
How do i give the user a box where they can select a directory? How do i implement folderbrowserdialog?Friday, August 14, 2009 6:56 AM -
I need a more in depth answer the links provided do not help to understand how to use these functions.
Lets solve this one step at a time.
How do i give the user a box where they can select a directory? How do i implement folderbrowserdialog?
Matthew,
There is sample code in the link I gave you. In particular, look at the folderMenuItem_Click method (scroll down a bit).
http://blog.voidnish.comFriday, August 14, 2009 12:19 PM -
Try this:
FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { System.Diagnostics.Process.Start("DISM.exe", "/e " + fbd.SelectedPath); }
Ciaran- Proposed as answer by CiaranODonnell Friday, August 14, 2009 2:28 PM
- Unproposed as answer by Matthew.003 Saturday, August 15, 2009 2:50 PM
Friday, August 14, 2009 2:28 PM -
Here's the completed code required to do this:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Window1 : Form { public Window1() { InitializeComponent(); } private void Window1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { // This lets the user pick a folder FolderBrowserDialog dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { // This starts DISM.exe with the arguments you specified... Process.Start("DISM.exe", "/e " + fbd.SelectedPath); } } } }
Reed Copsey, Jr. - http://reedcopsey.comFriday, August 14, 2009 6:28 PM -
Here's the completed code required to do this:
I would like to split the task into two buttons:
using System;
using System.Collections.Generic
using System.ComponentModel;
using System.Data; using System.Diagnostics;
using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Window1 : Form {
public Window1() {
InitializeComponent(); } private void Window1_Load(object sender, EventArgs e) { }
private void button1_Click(object sender, EventArgs e) {
// This lets the user pick a folder FolderBrowserDialog dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { // This starts DISM.exe with the arguments you specified... Process.Start("DISM.exe" "/e " + fbd.SelectedPath);
}
}
}}
Reed Copsey, Jr. - http://reedcopsey.com
Button 1 will select the path and enter it into a Text box displaying the Directory
Button 2 will run the Process.Start command- Edited by Matthew.003 Saturday, August 15, 2009 4:33 PM clarification
- Edited by Harry Zhu Friday, August 21, 2009 7:00 AM format
Friday, August 14, 2009 10:14 PM -
>>I would like to split the task into two buttons:
>>Button 1 will select the path and enter it into a Text box displaying the Directory
>>Button 2 will run the Process.Start command
Something like this :
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
textBox1.Text = fbd.SelectedPath;
}
}private void button2_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(textBox1.Text))
{
Process.Start("DISM.exe", "/e " + textBox1.Text);
}
}
But seriously, get a good book on C#. You are asking some extremely basic stuff here.
http://blog.voidnish.comSaturday, August 15, 2009 5:59 PM