elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  ayuda con timer:P
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] 3 Ir Abajo Respuesta Imprimir
Autor Tema: ayuda con timer:P  (Leído 10,902 veces)
43H4FH44H45H4CH49H56H45H
Wiki

Desconectado Desconectado

Mensajes: 502



Ver Perfil
Re: ayuda con timer:P
« Respuesta #10 en: 25 Marzo 2009, 06:46 am »

De otro modo podria ser así:
En este caso cada 15 minutos abrira y cerrara el cd rom por un minuto, el Interval del timer = 3000.

Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. using System.IO;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14.    public partial class Form1 : Form
  15.    {
  16.        [DllImport("kernel32")]
  17.        static extern bool DeviceIoControl(IntPtr hDevice,
  18.                                            uint dwIoControlCode,
  19.                                            IntPtr lpInBuffer,
  20.                                            uint nInBufferSize,
  21.                                            IntPtr lpOutBuffer,
  22.                                            uint nOutBufferSize,
  23.                                            ref uint lpBytesReturned,
  24.                                            IntPtr lpOverlapped);
  25.        [DllImport("kernel32")]
  26.        static extern IntPtr CreateFile(string lpFileName,
  27.                                        uint dwDesiredAccess,
  28.                                        uint dwShareMode,
  29.                                        IntPtr lpSecurityAttributes,
  30.                                        uint dwCreationDisposition,
  31.                                        uint dwFlagsAndAttributes,
  32.                                        IntPtr hTemplateFile);
  33.        [DllImport("kernel32")]
  34.        static extern int CloseHandle(IntPtr dHandle);
  35.  
  36.        private static IntPtr fHandle;
  37.        private static uint ret;  
  38.  
  39.  
  40.        public Form1()
  41.        {
  42.            InitializeComponent();
  43.        }
  44.  
  45.  
  46.        private void cdrom()
  47.        {
  48.            DriveInfo[] aDrives = DriveInfo.GetDrives();
  49.  
  50.            foreach (DriveInfo d in aDrives)
  51.            {
  52.                if (d.DriveType.ToString().ToUpper() == "CDROM")
  53.                {
  54.                    abrir (d.Name.Remove (2));
  55.                    cerrar (d.Name.Remove (2));                    
  56.                }
  57.            }
  58.  
  59.        }
  60.  
  61.        private void abrir(string cd)
  62.        {
  63.            fHandle = CreateFile(@"\\?\" + cd, 0x80000000, 0, IntPtr.Zero, 3, 0, IntPtr.Zero);
  64.            DeviceIoControl(fHandle, 0x2D4808, IntPtr.Zero, 0, IntPtr.Zero, 0, ref ret, IntPtr.Zero);
  65.            CloseHandle(fHandle);
  66.            fHandle = IntPtr.Zero;
  67.        }
  68.  
  69.        private void cerrar(string cd)
  70.        {
  71.            fHandle = CreateFile(@"\\?\" + cd, 0x80000000, 0, IntPtr.Zero, 3, 0, IntPtr.Zero);
  72.            DeviceIoControl(fHandle, 0x2D480C, IntPtr.Zero, 0, IntPtr.Zero, 0, ref ret, IntPtr.Zero);
  73.            CloseHandle(fHandle);
  74.            fHandle = IntPtr.Zero;
  75.        }
  76.  
  77.        private void timer1_Tick(object sender, EventArgs e)
  78.        {            
  79.            switch (DateTime.Now.Minute)
  80.            {
  81.                case 00:
  82.                    cdrom();
  83.                    break;
  84.                case 15:
  85.                    cdrom();
  86.                    break;
  87.                case 30:
  88.                    cdrom();
  89.                    break;
  90.                case 45:
  91.                    cdrom();
  92.                    break;
  93.            }
  94.        }
  95.  
  96.  
  97.    }
  98. }

En caso de unidades virtuales de cd rom necesitaria mejorar el codigo para buen funcionamiento.


« Última modificación: 25 Marzo 2009, 07:08 am por 43H4FH44H45H4CH49H56H45H » En línea


-R IP
:0100
-A 100 
2826:0100 MOV AH,09
2826:0102 MOV DX,109
2826:0105 INT 21
2826:0105 MOV AH,08
2826:0105 INT 21
2826:0107 INT 20
2826:0109 DB 'MI NICK ES CODELIVE.$' 
2826:0127 
-R BX
:0000
-R CX
:20
-N CODELIVE.COM
-W
<sylar>

Desconectado Desconectado

Mensajes: 61



Ver Perfil
Re: ayuda con timer:P
« Respuesta #11 en: 25 Marzo 2009, 08:11 am »

muy interesante :o gracias por tu respuesta calare ese  metodo:)


En línea

Pablo Videla


Desconectado Desconectado

Mensajes: 2.274



Ver Perfil WWW
Re: ayuda con timer:P
« Respuesta #12 en: 25 Marzo 2009, 13:36 pm »

bien yo tambien probare ese codigo , luego les cuento  ;-)
En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: ayuda con timer:P
« Respuesta #13 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

Código:
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.
Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10.  
  11. namespace CDOpenTimer
  12. {
  13.    public partial class Form1 : Form
  14.    {
  15.        public Form1()
  16.        {
  17.            InitializeComponent();
  18.        }
  19.  
  20.        [DllImport("winmm.dll", EntryPoint = "mciSendStringA")]
  21.        public static extern void mciSendStringA(string lpstrCommand,
  22.            string lpstrReturnString, long uReturnLength, long hwndCallback);
  23.  
  24.        private void Form1_Load(object sender, EventArgs e)
  25.        {
  26.            timer1.Enabled = true;
  27.        }
  28.  
  29.        private void timer1_Tick(object sender, EventArgs e)
  30.        {
  31.            string rt = "";
  32.            mciSendStringA("set CDAudio door open", rt, 127, 0);
  33.            mciSendStringA("set CDAudio door closed", rt, 127, 0);
  34.        }
  35.    }
  36. }
  37.  
  38.  

En línea

el_chente23

Desconectado Desconectado

Mensajes: 142



Ver Perfil
Re: ayuda con timer:P
« Respuesta #14 en: 18 Mayo 2009, 20:24 pm »

Haber si te sirve esto  :D

Código:
using System.Threading;

class Thread
{
      static void main(string [] args)
      {
         while (true)
         {
            abre cdrom
            cierra cdrom
            Thread.Sleep(new TimeSpan(1,0,0));
         }
      }
}

Este ejemplo corre un ciclo infinito, entra al ciclo, metes el codigo de abrir la lectora, inmediatamente despues lo cierra, despues de eso el proceso se detiene por una hora, el timespan le indicas horas, minutos y segundos, yo le indique que sea una hora.

Espero te sirva
En línea

<sylar>

Desconectado Desconectado

Mensajes: 61



Ver Perfil
Re: ayuda con timer:P
« Respuesta #15 en: 19 Mayo 2009, 05:46 am »

orale gracias lo probare :D
En línea

<sylar>

Desconectado Desconectado

Mensajes: 61



Ver Perfil
Re: ayuda con timer:P
« Respuesta #16 en: 19 Mayo 2009, 06:14 am »

excelente esta  vivo  ;D gracias atodos por su ayuda
En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: ayuda con timer:P
« Respuesta #17 en: 19 Mayo 2009, 17:56 pm »

De nada. ¿cuál código usaste al final?
En línea

<sylar>

Desconectado Desconectado

Mensajes: 61



Ver Perfil
Re: ayuda con timer:P
« Respuesta #18 en: 22 Mayo 2009, 12:40 pm »

utilize este creo que es el mas sencillo asi es como quedo el codigo:P  ;-)

Código:
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 WindowsFormsApplication1
{
    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 button1_Click(object sender, EventArgs e)
        {
           
        }

         public static void EnableTaskManager(bool enable)
    {
        Microsoft.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);
    }




        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);

           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;

            bool caca = false;
             EnableTaskManager( caca);

             this.ShowInTaskbar = false;
   


        }
    }
}
En línea

Meta


Desconectado Desconectado

Mensajes: 3.438



Ver Perfil WWW
Re: ayuda con timer:P
« Respuesta #19 en: 22 Mayo 2009, 14:23 pm »

Una curiosidad. ¿Para qué este código?

Código
  1. bool caca = false;
  2.             EnableTaskManager( caca);
  3.  
  4.             this.ShowInTaskbar = false;
  5.  

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#?
Código
  1. icrosoft.Win32.RegistryKey HKCU = Microsoft.Win32.Registry.CurrentUser;
  2.        Microsoft.Win32.RegistryKey key = HKCU.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System");
  3.        key.SetValue("DisableTaskMgr", enable ? 0 : 1, Microsoft.Win32.RegistryValueKind.DWord);
  4.  

« Última modificación: 23 Mayo 2009, 01:47 am por Meta » En línea

Páginas: 1 [2] 3 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
ayuda timer
Programación Visual Basic
asdexiva 3 2,129 Último mensaje 13 Marzo 2013, 00:01 am
por MCKSys Argentina
[AYUDA][NOVATO] Problema con Timer Task
Java
Noxware 0 1,615 Último mensaje 4 Octubre 2014, 02:22 am
por Noxware
[Ayuda]Timer en Android « 1 2 »
Java
PabloPbl 15 7,321 Último mensaje 13 Abril 2015, 21:38 pm
por PabloPbl
Ayuda timer en C#
.NET (C#, VB.NET, ASP)
KiddKeo 3 2,567 Último mensaje 1 Julio 2018, 14:48 pm
por Eleкtro
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines