Click here to Skip to main content
15,890,527 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: vb.net thread problem Pin
Ray Cassick20-Jun-06 8:09
Ray Cassick20-Jun-06 8:09 
AnswerRe: vb.net thread problem [modified] Pin
Steve Pullan20-Jun-06 13:21
Steve Pullan20-Jun-06 13:21 
QuestionHow do I change JUST the color of a Group Boxs' line?????? Pin
Joey Picerno20-Jun-06 5:19
Joey Picerno20-Jun-06 5:19 
AnswerRe: How do I change JUST the color of a Group Boxs' line?????? Pin
Dave Kreskowiak21-Jun-06 9:18
mveDave Kreskowiak21-Jun-06 9:18 
QuestionModule Pin
Lansky20-Jun-06 5:18
Lansky20-Jun-06 5:18 
AnswerRe: Module Pin
Dave Kreskowiak21-Jun-06 9:14
mveDave Kreskowiak21-Jun-06 9:14 
QuestionDisable/Enable CD/DVD-Drive Pin
Lennard Fonteijn20-Jun-06 4:38
Lennard Fonteijn20-Jun-06 4:38 
AnswerRe: Disable/Enable CD/DVD-Drive Pin
progload20-Jun-06 6:38
progload20-Jun-06 6:38 
What do you mean by disable them? and why?

Do You want to "Lock the tray's from opening and closing" ?


'--- form code --- form1.vb ------------

Imports System.Runtime.InteropServices

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(32, 24)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Lock"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(32, 64)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(96, 24)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Unlock"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 118)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "CDLock Demo"
Me.ResumeLayout(False)

End Sub

#End Region

'*********************************************************
' IO Demo Locks/Unlocks Optical Disk Drive - VB.Net
'*********************************************************

#Region " API IO Control "

Private Structure OVERLAPPED
Dim Internal As IntPtr
Dim InternalHigh As IntPtr
Dim Offset As Integer
Dim OffsetHigh As Integer
Dim EventHandle As IntPtr
End Structure

Private Structure PREVENT_MEDIA_REMOVAL
Dim PreventMediaRemoval As Boolean
End Structure

<DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function CreateFile( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Integer, _
ByVal dwShareMode As Integer, _
ByVal lpSecurityAttributes As IntPtr, _
ByVal dwCreationDisposition As Integer, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) As Integer
End Function

<DllImport("kernel32.dll", ExactSpelling:=True, SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function DeviceIoControl( _
ByVal hDevice As Integer, _
ByVal dwIoControlCode As Int32, _
ByVal lpInBuffer As IntPtr, _
ByVal nInBufferSize As Int32, _
ByVal lpOutBuffer As IntPtr, _
ByVal nOutBufferSize As Int32, _
ByRef lpBytesReturned As Int32, _
ByVal lpOverlapped As OVERLAPPED) As Boolean
End Function

Private Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Integer) As Integer

Private Const INVALID_HANDLE_VALUE As Integer = -1
Private Const GENERIC_READ As Integer = &H80000000
Private Const GENERIC_WRITE As Integer = &H40000000
Private Const FILE_SHARE_READ As Integer = &H1
Private Const FILE_SHARE_WRITE As Integer = &H2
Private Const OPEN_EXISTING As Integer = 3
Private Const FILE_ATTRIBUTE_NORMAL As Integer = &H80
Private Const ERROR_ACCESS_DENIED As Integer = 5
Private Const IOCTL_STORAGE_MEDIA_REMOVAL As Integer = &H2D4804

'--------------------------------------------------------------------------
'cref: uses OVERLAPPED structure as per MSDN specifications.
'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/ioctl_storage_media_removal.asp
'--------------------------------------------------------------------------
Private Sub LockOpticalDrive(ByVal sDrive As String, ByVal bLockState As Boolean)
Dim dwRetval As Integer = 0
Dim pmr As PREVENT_MEDIA_REMOVAL
Dim hDevice As Integer
Dim ol As OVERLAPPED

'Get desired lock state
pmr.PreventMediaRemoval = bLockState
'Get a handle to the drive
hDevice = CreateFile("\\.\" & sDrive & ":", GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, 0)
Debug.WriteLine("WIN32 CreateFile: " & "Error: " & Err.LastDllError & " Handle: " & Handle.ToInt32)
If hDevice = INVALID_HANDLE_VALUE Then
MsgBox("Unable to find optical drive")
Exit Sub
End If
' Marshal Structure
Dim inBufferSize As Integer = Marshal.SizeOf(pmr)
Debug.WriteLine("inBbufferSize: " & inBufferSize)
Dim inBuffer As IntPtr = Marshal.AllocCoTaskMem(inBufferSize)
Marshal.StructureToPtr(pmr, inBuffer, False)
'Lock the drive
If DeviceIoControl(hDevice, IOCTL_STORAGE_MEDIA_REMOVAL, inBuffer, inBufferSize, IntPtr.Zero, 0, dwRetval, ol) = False Then
Debug.WriteLine("WIN32 DeviceIoControl: " & Err.LastDllError & " dwRetval: " & dwRetval)
MsgBox("Error accessing drive")
End If
'Free the memory and close the handle.
Marshal.FreeCoTaskMem(inBuffer)
CloseHandle(hDevice)
End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Lock the "E" optical drive
LockOpticalDrive("E", True)
MsgBox("Drive is locked")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Unlock the "E" optical drive
LockOpticalDrive("E", False)
MsgBox("Drive is unlocked")
End Sub

End Class

'------------------------------------


progload
QuestiontreevieW in vb.net 1.1 Pin
constantinejones20-Jun-06 4:19
constantinejones20-Jun-06 4:19 
AnswerRe: treevieW in vb.net 1.1 Pin
Lennard Fonteijn20-Jun-06 4:45
Lennard Fonteijn20-Jun-06 4:45 
QuestionType SqlConnection is not defined Pin
Quecumber25620-Jun-06 3:53
Quecumber25620-Jun-06 3:53 
AnswerRe: Type SqlConnection is not defined Pin
Edbert P20-Jun-06 19:39
Edbert P20-Jun-06 19:39 
GeneralRe: Type SqlConnection is not defined Pin
Quecumber25621-Jun-06 3:49
Quecumber25621-Jun-06 3:49 
GeneralRe: Type SqlConnection is not defined Pin
Edbert P21-Jun-06 13:52
Edbert P21-Jun-06 13:52 
QuestionOnline Booking Pin
Daleen20-Jun-06 3:16
Daleen20-Jun-06 3:16 
AnswerRe: Online Booking Pin
mikanu20-Jun-06 9:42
mikanu20-Jun-06 9:42 
Generalto save multiple .bmp images Pin
Ganesh Nagargoje20-Jun-06 3:15
Ganesh Nagargoje20-Jun-06 3:15 
GeneralRe: to save multiple .bmp images Pin
toxcct20-Jun-06 3:21
toxcct20-Jun-06 3:21 
GeneralRe: to save multiple .bmp images Pin
Nitron20-Jun-06 3:22
Nitron20-Jun-06 3:22 
JokeRe: to save multiple .bmp images Pin
Don Miguel20-Jun-06 3:27
Don Miguel20-Jun-06 3:27 
GeneralRe: to save multiple .bmp images Pin
Monty220-Jun-06 3:28
Monty220-Jun-06 3:28 
JokeRe: to save multiple .bmp images Pin
toxcct20-Jun-06 3:52
toxcct20-Jun-06 3:52 
GeneralRe: to save multiple .bmp images Pin
Lennard Fonteijn20-Jun-06 4:43
Lennard Fonteijn20-Jun-06 4:43 
GeneralRe: to save multiple .bmp images [modified] Pin
Dave Kreskowiak20-Jun-06 5:26
mveDave Kreskowiak20-Jun-06 5:26 
GeneralRe: to save multiple .bmp images Pin
Dave Kreskowiak20-Jun-06 5:24
mveDave Kreskowiak20-Jun-06 5:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.