Bienvenidos a Soft-Tecni.Net

Programación en general => Vb.net => Mensaje iniciado por: jrchico en Mayo 20, 2012, 01:18:13 am

Título: Open & Close CDROM VB.NET
Publicado por: jrchico en Mayo 20, 2012, 01:18:13 am
Vmos a crear un pequeño proyecto para abrir y cerrar el cdrom en windows,<br /><br />Primero creamos un nuevo proyecto de windows application y ahora en el form1 remplazar por este codigo, crear un button1 y un button2 y listo.<br /><br /><br />
Código: [Seleccionar]
Imports System.Runtime.InteropServices<br />Public Class Form1<br />&nbsp; &nbsp; Private rt As String = &quot;&quot;<br />&nbsp; &nbsp; Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />&nbsp; &nbsp; &nbsp; &nbsp; EjectCD()<br />&nbsp; &nbsp; End Sub<br />&nbsp; &nbsp; &lt;DllImport(&quot;winmm.dll&quot;, EntryPoint:=&quot;mciSendStringA&quot;)&gt; _<br />Private Shared Sub mciSendStringA(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Int32, ByVal hwndCallback As Int32)<br />&nbsp; &nbsp; End Sub<br />&nbsp; &nbsp; Private Sub EjectCD()<br />&nbsp; &nbsp; &nbsp; &nbsp; Try<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mciSendStringA(&quot;set CDAudio door open&quot;, rt, 127, 0)<br />&nbsp; &nbsp; &nbsp; &nbsp; Catch ex As Exception<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; End Try<br /><br />&nbsp; &nbsp; End Sub<br />&nbsp; &nbsp; Private Sub CloseCD()<br />&nbsp; &nbsp; &nbsp; &nbsp; Try<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mciSendStringA(&quot;set CDAudio door closed&quot;, rt, 127, 0)<br />&nbsp; &nbsp; &nbsp; &nbsp; Catch ex As Exception<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; End Try<br /><br />&nbsp; &nbsp; End Sub<br /><br />&nbsp; &nbsp; Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />&nbsp; &nbsp; &nbsp; &nbsp; CloseCD()<br />&nbsp; &nbsp; End Sub<br />End Class<br /><br />Nota: imaginense si lo utilizaramos como un pequeño virus y hicieramos esto:<br />creamos un timer y hacemos que se ejecute cada sierto tiempo y ejecute las funciones.<br /> EjectCD()<br />&nbsp; CloseCD()<br />lol<br /><br />Nos vemos,