Click here to Skip to main content
12,396,230 members (67,339 online)
Click here to Skip to main content

Stats

79.8K views
1.5K downloads
78 bookmarked
Posted

Implement an Autoplay Handler

, 18 Sep 2006 CPOL
Implementing an Autoplay handler in C#.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms;

using Almdal.AutoPlayDemo.Properties;
using Almdal.RegistryScript;

using System.Reflection;

namespace Almdal.AutoPlayDemo {

    /*****************************************************************************************
     *  Copyright (c) 2006 T. ALmdal
     *
     *  Permission is hereby granted, free of charge, to any person obtaining 
     *  a copy of this software and associated documentation files (the "Software"),
     *  to deal in the Software without restriction, including without limitation 
     *  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
     *  and/or sell copies of the Software, and to permit persons to whom the 
     *  Software is furnished to do so, subject to the following conditions:
     *
     *  The above copyright notice and this permission notice shall be included 
     *  in all copies or substantial portions of the Software.
     *  
     *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
     *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
     *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
     *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
     *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
     *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     * 
    /*******************************************************************************************/
    static class Program {
		/// <summary>
		/// The main entry point for the application.
		/// If the parameter is /r it will register the location of the executable
        /// as HKLM\Software\%Company%\%AppID%\%Location% = %LOCATION%
        /// 
        /// A parameter of /u will unregister it.
		/// </summary>
		[STAThread]
		static void Main(string [] cmds) {
            if (cmds.Length == 1) {
				CRegistryScript script = new CRegistryScript();
				string regScript = Almdal.AutoPlayDemo.Properties.Resources.RegisterScript;
				script.AddVariable("Company", Application.CompanyName);
				script.AddVariable("AppID", Application.ProductName);
				script.AddVariable("LOCATION", Application.ExecutablePath);
				script.AddVariable("Location", "{0F08197F-AF66-4198-9673-C5B5A33AACED}");

                if ("/r".Equals(cmds[0])) {
                    script.Register(regScript);
                    System.Console.WriteLine("Registration of Autoplay Demo Application completed successfully");
					return;
                }
                else {
                    script.Unregister(regScript);
                    System.Console.WriteLine("Unregistration of Autoplay Demo Application completed successfully");
                    return;
                }
            }

            Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new Form1());
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Tim Almdal
Canada Canada
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 18 Sep 2006
Article Copyright 2006 by Tim Almdal
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid