Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Startup aplikacije pri pokretanju OS-a

[es] :: .NET :: .NET Desktop razvoj :: Startup aplikacije pri pokretanju OS-a

[ Pregleda: 696 | Odgovora: 6 ]

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

mega_michulin

Član broj: 188663
Poruke: 16
*.adsl.net.t-com.hr.



Profil

icon Startup aplikacije pri pokretanju OS-a23.07.2008. u 14:23

Kako napraviti da se aplikacija programirana u C# pokrece pri podizanju OS-a ( ali ne da ju postavim u startup)?
23.07.2008. u 14:23 

DarkMan
Darko Matesic

Član broj: 20445
Poruke: 530
79.101.87.*



Profil

icon Re: Startup aplikacije pri pokretanju OS-a23.07.2008. u 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.
23.07.2008. u 18:34 

Shadowed
.NET developer

SuperModerator
Član broj: 649
Poruke: 9023
*.dynamic.sbb.rs.

Sajt: www.diskusije.net


Profil

icon Re: Startup aplikacije pri pokretanju OS-a23.07.2008. u 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.
23.07.2008. u 18:42 

mega_michulin

Član broj: 188663
Poruke: 16
*.adsl.net.t-com.hr.



Profil

icon Re: Startup aplikacije pri pokretanju OS-a25.07.2008. u 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]
25.07.2008. u 10:52 

mega_michulin

Član broj: 188663
Poruke: 16
*.adsl.net.t-com.hr.



Profil

icon Re: Startup aplikacije pri pokretanju OS-a25.07.2008. u 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).
25.07.2008. u 12:10 

DarkMan
Darko Matesic

Član broj: 20445
Poruke: 530
79.101.183.*



Profil

icon Re: Startup aplikacije pri pokretanju OS-a25.07.2008. u 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);
    }
}
25.07.2008. u 14:48 

mega_michulin

Član broj: 188663
Poruke: 16
*.adsl.net.t-com.hr.



Profil

icon Re: Startup aplikacije pri pokretanju OS-a25.07.2008. u 15:03
Svaka cast DarkMan,zahvaljujen se
25.07.2008. u 15:03 

[es] :: .NET :: .NET Desktop razvoj :: Startup aplikacije pri pokretanju OS-a

[ Pregleda: 696 | Odgovora: 6 ]

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.