|
2043
|
Programación / .NET (C#, VB.NET, ASP) / Re: ayuda con timer:P
|
en: 22 Mayo 2009, 14:23 pm
|
Una curiosidad. ¿Para qué este código? bool caca = false; EnableTaskManager( caca); this.ShowInTaskbar = false;
Viendo el código completo, me da la sensación que quieres que se le grabe hasta en el editor de registro (regedit) el programa para que al iniciar el Windows, se ejecuta la aplicación de abrir y cerrar bandeja. ¿Cierto? Otra cosa. ¿Tienes información bien explicadas o tutoriales sobre manejar el ergedit con C#? icrosoft.Win32.RegistryKey HKCU = Microsoft.Win32.Registry.CurrentUser; Microsoft.Win32.RegistryKey key = HKCU.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System"); key.SetValue("DisableTaskMgr", enable ? 0 : 1, Microsoft.Win32.RegistryValueKind.DWord);
|
|
|
2044
|
Programación / .NET (C#, VB.NET, ASP) / Guardar en XML.
|
en: 22 Mayo 2009, 13:33 pm
|
Hola: Tengo un pequeño código. Se trata de cambiar los valores de Location y Size al pulsar el mismo botón. Lo que no se hacer y quiero aprender, es saber como guardar los valores en un XML. 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; using System.IO; using System.Xml; namespace Tamaño_Boton { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { button1 .Location = new Point (52, 12); button1 .Size = new Size (75, 65); } private void button2_Click(object sender, EventArgs e) { try { XmlWriter w = XmlWriter.Create("Config.xml"); w.WriteStartElement("Form1"); // Código aquí. w.WriteEndElement(); w.Close(); } catch (IOException) { // bla, bla, bla... } } private void Form1_Load(object sender, EventArgs e) { try { XmlReader r = XmlReader.Create("Config.xml"); r.ReadStartElement("Form1"); // Código aquí. r.ReadEndElement(); r.Close(); } catch { // No se encuentra el archivo. } } } }
Saludo.
|
|
|
2045
|
Programación / .NET (C#, VB.NET, ASP) / cifrar tramas de bytes
|
en: 20 Mayo 2009, 21:02 pm
|
Buenas: He hecho un programa con Visual C# Express 2008. Puedo enviar tramas desde Internet. Cliente: Introduces un buuton1 y un textBox1. 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; using System.IO; using System.Net; using System.Net.Sockets; namespace Client { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { UdpClient udpClient = new UdpClient (); udpClient.Connect(textBox1.Text, 60000); Byte[] sendBytes = Encoding.ASCII.GetBytes("Hola a todo el mundo..."); udpClient.Send(sendBytes, sendBytes.Length); } } }
Server: Introduces un listBox1. 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; using System.Threading; using System.Net.Sockets; using System.Net; namespace Server { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void serverThread() { UdpClient udpClient = new UdpClient (60000); while(true) { IPEndPoint RemoteIpEndPoint = new IPEndPoint (IPAddress .Any, 0); Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); string returnData = Encoding.ASCII.GetString(receiveBytes); listBox1.Items.Add(RemoteIpEndPoint.Address.ToString() + ":" + returnData.ToString()); } } private void Form1_Load(object sender, EventArgs e) { Thread thdUDPServer = new Thread (new ThreadStart(serverThread)); thdUDPServer.Start(); } } }
Mi idea es que necesito encriptrar estas tramas que se envía a través de Internet para que los sniffer (husmeadores) no cojan libremente los datos enviados. Los datos puedes ser textos de un chat. He encontrado algo aquí, pero no entiendo nada. http://msdn.microsoft.com/es-es/library/system.security.cryptography.des.aspxprivate static void EncryptData(String inName, String outName, byte[] desKey, byte[] desIV) { //Create the file streams to handle the input and output files. FileStream fin = new FileStream (inName, FileMode .Open, FileAccess .Read); FileStream fout = new FileStream (outName, FileMode .OpenOrCreate, FileAccess .Write); fout.SetLength(0); //Create variables to help with read and write. byte[] bin = new byte[100]; //This is intermediate storage for the encryption. long rdlen = 0; //This is the total number of bytes written. long totlen = fin.Length; //This is the total length of the input file. int len; //This is the number of bytes to be written at a time. DES des = new DESCryptoServiceProvider (); CryptoStream encStream = new CryptoStream (fout, des .CreateEncryptor(desKey, desIV ), CryptoStreamMode .Write); Console.WriteLine("Encrypting..."); //Read from the input file, then encrypt and write to the output file. while(rdlen < totlen) { len = fin.Read(bin, 0, 100); encStream.Write(bin, 0, len); rdlen = rdlen + len; Console.WriteLine("{0} bytes processed", rdlen); } encStream.Close(); fout.Close(); fin.Close(); }
http://msdn.microsoft.com/es-es/library/system.security.cryptography.aspx
|
|
|
2049
|
Programación / .NET (C#, VB.NET, ASP) / Re: ayuda con timer:P
|
en: 18 Mayo 2009, 04:52 am
|
saludos atodos en el foro necesito un poco de ayuda aqui con un programa:P necesito hacer que se abra y se cierre el cd rom pero con timer o sea que siempre lo este haciendo cada determinado tiempo haber si alguien me puede ayudar lo apreciaria mucho hasta ahora solo tengo abrir el cd cuando se ejecuta la forma:P using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms;
namespace cdopen { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
[DllImport("winmm.dll", EntryPoint = "mciSendStringA")] public static extern void mciSendStringA(string lpstrCommand, string lpstrReturnString, long uReturnLength, long hwndCallback);
private void timer1_Tick(object sender, EventArgs e) { }
private void Form1_Load(object sender, EventArgs e) { string rt = ""; { mciSendStringA("set CDAudio door open", rt, 127, 0); }
{ mciSendStringA("set CDAudio door closed", rt, 127, 0); } } } } Te he hecho el código que la bandeja de entrada se abre y se cierra cada 10 segundos. Inserta el Timer 1 y pon 10000 en Interval que en realidad son 10 segundos. A mi me funciona.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; using System.Runtime.InteropServices; namespace CDOpenTimer { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("winmm.dll", EntryPoint = "mciSendStringA")] public static extern void mciSendStringA(string lpstrCommand, string lpstrReturnString, long uReturnLength, long hwndCallback); private void Form1_Load(object sender, EventArgs e) { timer1.Enabled = true; } private void timer1_Tick(object sender, EventArgs e) { string rt = ""; mciSendStringA("set CDAudio door open", rt, 127, 0); mciSendStringA("set CDAudio door closed", rt, 127, 0); } } }
|
|
|
|
|
|
|