Click here to Skip to main content
15,912,897 members
Home / Discussions / C#
   

C#

 
QuestionHow to switch off autorun function Pin
zlaty12-Jun-04 22:40
zlaty12-Jun-04 22:40 
AnswerRe: How to switch off autorun function Pin
Colin Angus Mackay13-Jun-04 1:02
Colin Angus Mackay13-Jun-04 1:02 
GeneralRe: How to switch off autorun function Pin
zlaty13-Jun-04 3:19
zlaty13-Jun-04 3:19 
AnswerRe: How to switch off autorun function Pin
Stefan Troschuetz13-Jun-04 4:03
Stefan Troschuetz13-Jun-04 4:03 
GeneralRe: How to switch off autorun function Pin
zlaty13-Jun-04 5:27
zlaty13-Jun-04 5:27 
GeneralRe: How to switch off autorun function Pin
Stefan Troschuetz13-Jun-04 5:44
Stefan Troschuetz13-Jun-04 5:44 
GeneralRe: How to switch off autorun function Pin
zlaty13-Jun-04 9:59
zlaty13-Jun-04 9:59 
AnswerRe: How to switch off autorun function Pin
Heath Stewart13-Jun-04 18:15
protectorHeath Stewart13-Jun-04 18:15 
There is a programmatic way, and many installers (including the Windows Installer runtime) will do this when prompting for CDs.

In order to do this, you must P/Invoke the RegisterWindowsMessage API to register a windows message that should be handled in your Forms override to the WndProc method. I would recommend defining a property to easily enable or disable autorun:
public class MyForm : Form
{
  // ...
  internal static uint QueryCancelAutoPlayMsg;
  private bool enableAutoPlay = true;
  public bool EnableAutoPlay
  {
    get { return enableAutoPlay ; }
    set { enableAutoPlay = value; }
  }
  [DllImport("user32.dll", CharSet=CharSet.Auto)]
  private static extern uint RegisterWindowMessage(string msg);
  protected override void WndProc(ref Message m)
  {
    base.WndProc(ref m);
    if (QueryCancelAutoPlayMsg == 0)
      QueryCancelAutoPlayMsg = RegisterWindows=Message("QueryCancelAutoPlay");
    if (m.Msg == QueryCancelAutoPlayMsg)
      m.Result = new IntPtr((int)enableAutoPlay);
  }
}
Please note that this is only a sample. I recommend you read more about canceling autoplay on MSDN in Enabling and Disabling AutoPlay[^].

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: How to switch off autorun function Pin
zlaty14-Jun-04 4:26
zlaty14-Jun-04 4:26 
GeneralC# Noob in trouble with enumerations Pin
Wingnut7412-Jun-04 20:02
Wingnut7412-Jun-04 20:02 
GeneralRe: C# Noob in trouble with enumerations Pin
David M. Kean12-Jun-04 20:22
David M. Kean12-Jun-04 20:22 
GeneralRe: C# Noob in trouble with enumerations Pin
Daniel Turini12-Jun-04 23:56
Daniel Turini12-Jun-04 23:56 
GeneralRe: C# Noob in trouble with enumerations Pin
Wingnut7413-Jun-04 5:07
Wingnut7413-Jun-04 5:07 
GeneralRe: C# Noob in trouble with enumerations Pin
Cotter13-Jun-04 5:34
Cotter13-Jun-04 5:34 
GeneralRe: C# Noob in trouble with enumerations Pin
Wingnut7413-Jun-04 5:37
Wingnut7413-Jun-04 5:37 
GeneralRe: C# Noob in trouble with enumerations Pin
leppie13-Jun-04 7:06
leppie13-Jun-04 7:06 
GeneralGeneric in C# Pin
vcorn12-Jun-04 19:19
vcorn12-Jun-04 19:19 
GeneralRe: Generic in C# Pin
Stefan Troschuetz12-Jun-04 22:01
Stefan Troschuetz12-Jun-04 22:01 
GeneralRe: Generic in C# Pin
vcorn13-Jun-04 6:18
vcorn13-Jun-04 6:18 
GeneralConvert String to Integer Pin
visitsaadi12-Jun-04 18:35
visitsaadi12-Jun-04 18:35 
GeneralRe: Convert String to Integer Pin
Xiangyang Liu 刘向阳12-Jun-04 19:13
Xiangyang Liu 刘向阳12-Jun-04 19:13 
GeneralRe: Convert String to Integer Pin
eggie512-Jun-04 19:13
eggie512-Jun-04 19:13 
GeneralRe: Convert String to Integer Pin
Clickok13-Jun-04 5:19
Clickok13-Jun-04 5:19 
GeneralMulti-Styled lable... Pin
mikker_12312-Jun-04 17:48
mikker_12312-Jun-04 17:48 
GeneralRe: Multi-Styled lable... Pin
Heath Stewart12-Jun-04 18:21
protectorHeath Stewart12-Jun-04 18:21 

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.