diff --git a/01-IntroProcesos.csproj b/01-IntroProcesos.csproj new file mode 100644 index 0000000..89ece7e --- /dev/null +++ b/01-IntroProcesos.csproj @@ -0,0 +1,83 @@ + + + + + Debug + AnyCPU + {AFE3B6BE-A35E-466E-AFFE-1BE73DE7FCAC} + WinExe + _01_IntroProcesos + 01-IntroProcesos + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/App.config b/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Form1.Designer.cs b/Form1.Designer.cs new file mode 100644 index 0000000..f39a5b0 --- /dev/null +++ b/Form1.Designer.cs @@ -0,0 +1,202 @@ +namespace _01_IntroProcesos +{ + partial class Form1 + { + /// + /// Variable del diseñador necesaria. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Limpiar los recursos que se estén usando. + /// + /// true si los recursos administrados se deben desechar; false en caso contrario. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Código generado por el Diseñador de Windows Forms + + /// + /// Método necesario para admitir el Diseñador. No se puede modificar + /// el contenido de este método con el editor de código. + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.button4 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.button6 = new System.Windows.Forms.Button(); + this.button7 = new System.Windows.Forms.Button(); + this.button8 = new System.Windows.Forms.Button(); + this.button9 = new System.Windows.Forms.Button(); + this.button10 = new System.Windows.Forms.Button(); + this.button11 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(23, 156); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(201, 54); + this.button1.TabIndex = 0; + this.button1.Text = "iniciar Proceso"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.Button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(23, 231); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(201, 52); + this.button2.TabIndex = 1; + this.button2.Text = "eliminar Proceso"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.Button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(255, 156); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(147, 54); + this.button3.TabIndex = 2; + this.button3.Text = "listar Procesos"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.Button3_Click); + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(451, 156); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(224, 21); + this.comboBox1.TabIndex = 3; + // + // button4 + // + this.button4.Location = new System.Drawing.Point(255, 231); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(147, 52); + this.button4.TabIndex = 4; + this.button4.Text = "listar Chrome"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.Button4_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(255, 304); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(147, 52); + this.button5.TabIndex = 5; + this.button5.Text = "matar Chrome"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.Button5_Click); + // + // button6 + // + this.button6.Location = new System.Drawing.Point(23, 12); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(201, 54); + this.button6.TabIndex = 6; + this.button6.Text = "inicio Proceso simple"; + this.button6.UseVisualStyleBackColor = true; + this.button6.Click += new System.EventHandler(this.button6_Click); + // + // button7 + // + this.button7.Location = new System.Drawing.Point(244, 12); + this.button7.Name = "button7"; + this.button7.Size = new System.Drawing.Size(201, 54); + this.button7.TabIndex = 7; + this.button7.Text = "inicio Proceso ProcessStartInfo"; + this.button7.UseVisualStyleBackColor = true; + this.button7.Click += new System.EventHandler(this.button7_Click); + // + // button8 + // + this.button8.Location = new System.Drawing.Point(463, 12); + this.button8.Name = "button8"; + this.button8.Size = new System.Drawing.Size(201, 54); + this.button8.TabIndex = 8; + this.button8.Text = "Propiedades"; + this.button8.UseVisualStyleBackColor = true; + this.button8.Click += new System.EventHandler(this.button8_Click); + // + // button9 + // + this.button9.Location = new System.Drawing.Point(23, 304); + this.button9.Name = "button9"; + this.button9.Size = new System.Drawing.Size(201, 52); + this.button9.TabIndex = 9; + this.button9.Text = "waitForExit()"; + this.button9.UseVisualStyleBackColor = true; + this.button9.Click += new System.EventHandler(this.button9_Click); + // + // button10 + // + this.button10.Location = new System.Drawing.Point(23, 78); + this.button10.Name = "button10"; + this.button10.Size = new System.Drawing.Size(201, 54); + this.button10.TabIndex = 10; + this.button10.Text = "Redirigir salida"; + this.button10.UseVisualStyleBackColor = true; + this.button10.Click += new System.EventHandler(this.button10_Click); + // + // button11 + // + this.button11.Location = new System.Drawing.Point(244, 78); + this.button11.Name = "button11"; + this.button11.Size = new System.Drawing.Size(201, 54); + this.button11.TabIndex = 11; + this.button11.Text = "Enviar texto a Notepad"; + this.button11.UseVisualStyleBackColor = true; + this.button11.Click += new System.EventHandler(this.button11_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button11); + this.Controls.Add(this.button10); + this.Controls.Add(this.button9); + this.Controls.Add(this.button8); + this.Controls.Add(this.button7); + this.Controls.Add(this.button6); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Button button6; + private System.Windows.Forms.Button button7; + private System.Windows.Forms.Button button8; + private System.Windows.Forms.Button button9; + private System.Windows.Forms.Button button10; + private System.Windows.Forms.Button button11; + } +} + diff --git a/Form1.cs b/Form1.cs new file mode 100644 index 0000000..db86e0a --- /dev/null +++ b/Form1.cs @@ -0,0 +1,132 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace _01_IntroProcesos { + public partial class Form1 : Form { + Process miProceso; + public Form1() { + InitializeComponent(); + } + + private void Button1_Click(object sender, EventArgs e) { + //referencia https://docs.microsoft.com/es-es/dotnet/api/system.diagnostics.process?view=netframework-4.8 + + miProceso = new Process(); + miProceso.StartInfo.FileName = "Notepad"; + //miProceso.StartInfo.FileName = @"C:\Program Files\LibreOffice\program\swriter.exe"; + //miProceso.StartInfo.FileName = @"C:\Program Files(x86)\Microsoft Office\Office16\WINWORD.exe"; + //miProceso.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; + miProceso.Start(); + + } + + private void Button2_Click(object sender, EventArgs e) { + miProceso.Kill(); + } + + private void Button3_Click(object sender, EventArgs e) { + Process[] misProcesos = Process.GetProcesses(); + this.comboBox1.Items.Clear(); + foreach (Process mp in misProcesos) { + this.comboBox1.Items.Add(mp.ProcessName); + } + } + + private void Button4_Click(object sender, EventArgs e) { + Process[] misProcesos = Process.GetProcessesByName("chrome"); + this.comboBox1.Items.Clear(); + foreach (Process mp in misProcesos) { + this.comboBox1.Items.Add(mp.ProcessName); + } + } + + private void Button5_Click(object sender, EventArgs e) { + Process[] misProcesos = Process.GetProcessesByName("Chrome"); + foreach (Process mp in misProcesos) { + mp.Kill(); + } + } + + private void button6_Click(object sender, EventArgs e) { + try { + Process.Start(@"C:\Windows\System32\notepad.exe"); + Process.Start("calc"); + Process.Start("MiDocumento.pdf"); + Process.Start("https:\\www.marcombo.com"); + Process.Start("C:\\"); + } + catch (Exception ex) { + Debug.WriteLine(ex.Message); + } + } + + private void button7_Click(object sender, EventArgs e) { + ProcessStartInfo psi = new ProcessStartInfo(); + psi.FileName = "ping"; + psi.CreateNoWindow = false; + psi.UseShellExecute = true; + psi.WindowStyle = ProcessWindowStyle.Maximized; + psi.Arguments = "www.marcombo.com" + " -n 10"; + try { + Process.Start(psi); + } + catch (Exception ex) { + Debug.WriteLine(ex.Message); + } + } + + private void button8_Click(object sender, EventArgs e) { + //iniciamos un proceso + miProceso = new Process(); + miProceso.StartInfo.FileName = "Notepad"; + miProceso.Start(); + + //consultamos alguna propiedad y alteramos alguna otra + Debug.WriteLine( miProceso.StartTime.ToString()); + miProceso.PriorityClass = ProcessPriorityClass.BelowNormal; + } + + private void button9_Click(object sender, EventArgs e) { + //se debe ejecutar previamente a la creación de un proceso + String nombre = miProceso.ProcessName; + Debug.WriteLine(miProceso.HasExited.ToString()); + miProceso.WaitForExit(); //método síncrono=>línea bloqueante + Debug.WriteLine(miProceso.HasExited.ToString()); + Debug.WriteLine(miProceso.ExitCode.ToString()); + Debug.WriteLine("El proceso " + nombre + "ha terminado"); + } + + private void button10_Click(object sender, EventArgs e) { + ProcessStartInfo psi = new ProcessStartInfo(); + psi.FileName = "cmd.exe"; + psi.Arguments = "/c dir"; + psi.UseShellExecute = false; + psi.CreateNoWindow = true; + psi.RedirectStandardOutput = true; + + Process p = Process.Start(psi); + StreamReader reader = p.StandardOutput; + + string datos = reader.ReadToEnd(); + Debug.WriteLine(datos); + } + + [DllImport("user32.dll", EntryPoint = "FindWindowEx")] + public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); + [DllImport("User32.dll")] + public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam); + + private void button11_Click(object sender, EventArgs e) { + Process[] processes = Process.GetProcessesByName("notepad"); + //Console.WriteLine(processes[0].MainWindowHandle.ToString()); + if (processes.Length == 0) return; + if (processes[0] != null) { + IntPtr child = FindWindowEx(processes[0].MainWindowHandle, new IntPtr(0), "Edit", null); + SendMessage(child, 0x000C, 0, "hola"); + } + } + } +} diff --git a/Form1.resx b/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..6302bde --- /dev/null +++ b/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace _01_IntroProcesos +{ + static class Program + { + /// + /// Punto de entrada principal para la aplicación. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..772d32f --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// La información general de un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie estos valores de atributo para modificar la información +// asociada con un ensamblado. +[assembly: AssemblyTitle("01-IntroProcesos")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("01-IntroProcesos")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles +// para los componentes COM. Si es necesario obtener acceso a un tipo en este ensamblado desde +// COM, establezca el atributo ComVisible en true en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM. +[assembly: Guid("afe3b6be-a35e-466e-affe-1be73de7fcac")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de compilación +// Revisión +// +// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión +// utilizando el carácter "*", como se muestra a continuación: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..9dea9df --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Este código fue generado por una herramienta. +// Versión de runtime: 4.0.30319.42000 +// +// Los cambios de este archivo pueden provocar un comportamiento inesperado y se perderán si +// el código se vuelve a generar. +// +//------------------------------------------------------------------------------ + +namespace _01_IntroProcesos.Properties +{ + + + /// + /// Clase de recurso fuertemente tipado para buscar cadenas traducidas, etc. + /// + // StronglyTypedResourceBuilder generó automáticamente esta clase + // a través de una herramienta como ResGen o Visual Studio. + // Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen + // con la opción /str o recompile su proyecto de VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Devuelve la instancia ResourceManager almacenada en caché utilizada por esta clase. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_01_IntroProcesos.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Invalida la propiedad CurrentUICulture del subproceso actual para todas las + /// búsquedas de recursos usando esta clase de recursos fuertemente tipados. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs new file mode 100644 index 0000000..af4e376 --- /dev/null +++ b/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace _01_IntroProcesos.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Properties/Settings.settings b/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs b/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs new file mode 100644 index 0000000..3871b18 --- /dev/null +++ b/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] diff --git a/obj/Debug/01-IntroProcesos.csproj.AssemblyReference.cache b/obj/Debug/01-IntroProcesos.csproj.AssemblyReference.cache new file mode 100644 index 0000000..825f721 Binary files /dev/null and b/obj/Debug/01-IntroProcesos.csproj.AssemblyReference.cache differ