[ mega_michulin @ 23.07.2008. 14:23 ] @
Kako napraviti da se aplikacija programirana u C# pokrece pri podizanju OS-a ( ali ne da ju postavim u startup)?
[ DarkMan @ 23.07.2008. 18:34 ] @
Moze preko registry-a. Koristi sledeci property:

Code:

using Microsoft.Win32;

....

        public bool StartWithWindows
        {
            get
            {
                bool startWithWindows = false;
                try {
                    RegistryKey key = Registry.LocalMachine.CreateSubKey(key_startup);
                    if(key != null) {
                        string fileName = Convert.ToString(key.GetValue(value_startup, ""));
                        if(fileName == Application.ExecutablePath) {
                            startWithWindows = true;
                        } else {
                            key.DeleteValue(value_startup);
                        }
                    }
                } catch { }
                return startWithWindows;
            }
            set
            {
                try {
                    RegistryKey key = Registry.LocalMachine.CreateSubKey(key_startup);
                    if(key != null) {
                        if(value) {
                            key.SetValue(value_startup, Application.ExecutablePath);
                        } else {
                            key.DeleteValue(value_startup);
                        }
                    }
                } catch { }
            }
        }

        private string key_startup = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
        private string value_startup = System.IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath);

Kada mu stavis vrednost na true u registriju ce biti upisano da se aplikacija pokrene pri podizanju windowsa.
[ Shadowed @ 23.07.2008. 18:42 ] @
Imas u Windows desktop forumu temu o nacinima da se neka tema pokrece pri startup-u. Pogledaj tamo a onda samo implementiraj neki od tih nacina.
[ mega_michulin @ 25.07.2008. 10:52 ] @
Unija san kod u aplikaciju i sve radi kako triba,zahvaljujen se svima na pomoci.

[Ovu poruku je menjao mega_michulin dana 25.07.2008. u 12:39 GMT+1]
[ mega_michulin @ 25.07.2008. 12:10 ] @
DarkMan ima bi jos jednu zamolbu.
Jeli znas mozda kako da modificiran kod koji si mi dao tako da aplikacija kad se pokrene, nepokrene se na desktopu vec da bude samo kao ikonica u donjem desnom kutu(system tray-u).
[ DarkMan @ 25.07.2008. 14:48 ] @
Evo ti mali primer za koriscenje tray ikone i koji u sebi sadrzi gore dati kod za pokretanje programa pri podizanju windowsa.

Code:

using System;
using System.Drawing;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using Microsoft.Win32;

namespace WindowsApplication1
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ContextMenuStrip cm = new ContextMenuStrip();
            cm.Items.Add("About...", null, new EventHandler(OnAbout));
            cm.Items.Add("-");
            cm.Items.Add("Configuration...", null, new EventHandler(OnConfiguration));
            cm.Items.Add("-");
            menuStartWithWindows = cm.Items.Add("Start With Windows", null, new EventHandler(OnStartWithWindows)) as ToolStripMenuItem;
            cm.Items.Add("-");
            cm.Items.Add("Exit", null, new EventHandler(OnExit));
            cm.Opening += new System.ComponentModel.CancelEventHandler(OnMenuOpening);

            NotifyIcon notifyIcon = new NotifyIcon();
            notifyIcon.ContextMenuStrip = cm;
            notifyIcon.Icon = Properties.Resources.app_icon;
            notifyIcon.MouseDoubleClick += new MouseEventHandler(OnAbout);
            notifyIcon.Visible = true;
            notifyIcon.Text = "Test";

            Application.Run();
            notifyIcon.Visible = false;
            notifyIcon.Dispose();
        }
        private static ToolStripMenuItem menuStartWithWindows = null;

        private static void OnAbout(object sender, EventArgs e)
        {
            MessageBox.Show("Test", "About", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private static void OnConfiguration(object sender, EventArgs e)
        {
            Form form = new Form();
            form.ShowDialog();
            form.Dispose();
        }

        private static void OnMenuOpening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            menuStartWithWindows.Checked = Program.StartWithWindows;
        }

        private static void OnStartWithWindows(object sender, EventArgs e)
        {
            Program.StartWithWindows = !Program.StartWithWindows;
        }

        private static void OnExit(object sender, EventArgs e)
        {
            Application.Exit();
        }

        public static bool StartWithWindows
        {
            get
            {
                bool startWithWindows = false;
                try {
                    RegistryKey key = Registry.LocalMachine.CreateSubKey(key_startup);
                    if(key != null) {
                        string fileName = Convert.ToString(key.GetValue(value_startup, ""));
                        if(fileName == Application.ExecutablePath) {
                            startWithWindows = true;
                        } else {
                            key.DeleteValue(value_startup);
                        }
                    }
                } catch { }
                return startWithWindows;
            }
            set
            {
                try {
                    RegistryKey key = Registry.LocalMachine.CreateSubKey(key_startup);
                    if(key != null) {
                        if(value) {
                            key.SetValue(value_startup, Application.ExecutablePath);
                        } else {
                            key.DeleteValue(value_startup);
                        }
                    }
                } catch { }
            }
        }

        private static string key_startup = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
        private static string value_startup = System.IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath);
    }
}
[ mega_michulin @ 25.07.2008. 15:03 ] @
Svaka cast DarkMan,zahvaljujen se