Codeless Posted August 16, 2005 Posted August 16, 2005 I am writing an installation type program for an app that spans multiple CD's. When I insert the 2nd CD the OS (i believe) is opening a dialogue box that show's what's on the CD. The installation continue's fine, but I want to suppress the dialogue box. I thought maybe using the windows API would be able to accomplish this, but I can't seem to find anything even close to this. Can anyone point me in the right direction? Quote Codeless ...it just goes on and on.
VagabondSW Posted August 16, 2005 Posted August 16, 2005 Try this code. It is not a complete solution since it will only work if your Form is the Top-most form and has focus at the time the QueryCancelAutoPlay message is received. So, you'll have to write the code to make sure your installer form demands focus and is always on top of the Z-Order. 'Use Windows API calls to handle the AutoRun messages when a user inserts 'media into a CD/DVD-ROM drive. Public Declare Auto Function RegisterWindowMessage Lib "user32.dll" (ByVal lpString As String) As Integer Public Declare Auto Function SetWindowLong Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer Public Const DWL_MSGRESULT As Integer = 0 Private MessageID As Integer 'needed to handle window autorun message Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = MessageID Then 'System.Diagnostics.Debug.WriteLine("QueryCancelAutoPlay Received!") tmrInsertMedia.Enabled = True m.Result = New IntPtr(1) Else MyBase.WndProc(m) End If End Sub I derived my solution from Duncan Mackenzie's sample, which can be found about half way down the following page: http://www.duncanmackenzie.net/Samples/default.aspx Download the ZIP file and run it. Instead of disabling Autorun, you will see that it "intercepts" the QueryCancelAutoPlay message and handles it. Be aware that Duncan has added some necessary code to the "Windows Form Designer generated code" region. Quote "Never ascribe to malice that which can adequately be explained by incompetence." -- Napolean Bonaparte
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.