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: 3483 | Odgovora: 6 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

mega_michulin
bla

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



Profil

icon Startup aplikacije pri pokretanju OS-a23.07.2008. u 14:23 - pre 190 meseci
Kako napraviti da se aplikacija programirana u C# pokrece pri podizanju OS-a ( ali ne da ju postavim u startup)?
 
Odgovor na temu

DarkMan
Darko Matesic

Član broj: 20445
Poruke: 572
79.101.87.*

Jabber: DarkMan


Profil

icon Re: Startup aplikacije pri pokretanju OS-a23.07.2008. u 18:34 - pre 190 meseci
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.
 
Odgovor na temu

Shadowed
Vojvodina

Član broj: 649
Poruke: 12846



+4783 Profil

icon Re: Startup aplikacije pri pokretanju OS-a23.07.2008. u 18:42 - pre 190 meseci
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.
 
Odgovor na temu

mega_michulin
bla

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



Profil

icon Re: Startup aplikacije pri pokretanju OS-a25.07.2008. u 10:52 - pre 190 meseci
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]
 
Odgovor na temu

mega_michulin
bla

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



Profil

icon Re: Startup aplikacije pri pokretanju OS-a25.07.2008. u 12:10 - pre 190 meseci
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).
 
Odgovor na temu

DarkMan
Darko Matesic

Član broj: 20445
Poruke: 572
79.101.183.*

Jabber: DarkMan


Profil

icon Re: Startup aplikacije pri pokretanju OS-a25.07.2008. u 14:48 - pre 190 meseci
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);
    }
}
 
Odgovor na temu

mega_michulin
bla

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



Profil

icon Re: Startup aplikacije pri pokretanju OS-a25.07.2008. u 15:03 - pre 190 meseci
Svaka cast DarkMan,zahvaljujen se
 
Odgovor na temu

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

[ Pregleda: 3483 | Odgovora: 6 ] > FB > Twit

Postavi temu Odgovori

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