programadorvb6 Posted October 31, 2019 at 04:41 PM Report Share #616489 Posted October 31, 2019 at 04:41 PM (edited) Olá boa tarde, estou com um problema e peço a vossa ajuda. Já estive a procurar como ejectar USB Drives que estejam 'ligadas' ao PC; não encontrei nada para VB.Net que funciona-se o que encontrei foi neste site do CodeProject e estavam em c# o mesmo código não funcionava correctamente. Desejava que no final do varrimento desconecta-se todas as USB Drives existentes e fizesse então o Shutdown ao Pc. Fiz assim a algum código em VB.net : 1- Fiz o Varrimento de todas USB Drives 2 - Identifiquei as e no final faz o Shutdown ao Pc ( sem premir mais nenhum botão ). Imports System.Runtime.InteropServices Public Class Form1 <DllImport("winmm.dll")> _ Private Shared Function mciSendString(ByVal command As String, ByVal buffer As String, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer End Function Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click '--------------------------------------------------- Dim drives = System.IO.DriveInfo.GetDrives() Dim usbDrive = drives.FirstOrDefault(Function(m) m.DriveType = System.IO.DriveType.Removable) Dim CDR = drives.FirstOrDefault(Function(m) m.DriveType = System.IO.DriveType.CDRom) For i As Integer = 0 To drives.Count - 1 If drives(i).DriveType = System.IO.DriveType.Removable AndAlso usbDrive.IsReady = True Then MessageBox.Show(drives(i).ToString) 'Codigo para remover USB End If If drives(i).DriveType = IO.DriveType.CDRom = True And CDR.IsReady = True Then MessageBox.Show("CDRom ejectado !") mciSendString("set CDAudio door open", vbNullString, 0, IntPtr.Zero) 'Fechar ' mciSendString("set CDAudio door closed", vbNullString, 0, IntPtr.Zero) End If Next i MessageBox.Show("Shutdown") 'System.Diagnostics.Process.Start("ShutDown", "/s") ' - Shutdown '---------------------------------------------------- End Sub End Class Grato desde já pela vossa atenção. Um abraço. Edited October 31, 2019 at 05:09 PM by programadorvb6 ______________________________________________________________________________ Que minha coragem seja maior que meu medo e que minha força seja tão grande quanto minha fé. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now