3

マシンの起動後に自動的に実行されるアプリケーションを作成したいと考えています。

C#でどうすればいいのか、誰でも助けてくれますか?

4

4 に答える 4

21

これは、アプリをスタートアップに追加する方法です。

// The path to the key where Windows looks for startup applications
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

if (!IsStartupItem())
    // Add the value in the registry so that the application runs at startup
    rkApp.SetValue("My app's name", Application.ExecutablePath.ToString());

そしてそれを削除するには:

// The path to the key where Windows looks for startup applications
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

if(IsStartupItem())
    // Remove the value from the registry so that the application doesn't start
    rkApp.DeleteValue("My app's name", false);

そして、私のコードの IsStartupItem 関数:

private bool IsStartupItem()
{
    // The path to the key where Windows looks for startup applications
    RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

    if (rkApp.GetValue("My app's name") == null)
        // The value doesn't exist, the application is not set to run at startup
        return false;
    else
        // The value exists, the application is set to run at startup
        return true;
}
于 2011-09-30T09:12:51.487 に答える
4

アプリケーションの Windows サービスを作成し、その Windows サービスを登録し、スタートアップ プロパティを automatic に設定します。これで、Windows が起動するたびにサービスが自動的に開始され、次のリンクが表示されます: http://www.geekpedia.com/tutorial151_Run-the-application-at-Windows-startup.html

于 2011-09-30T09:23:08.843 に答える
2

レジストリにキーを追加するよりも良い方法は、WindowsStartUpフォルダーにショートカットを追加することだと思います。これは、ユーザーにとってより透過的であり、ユーザーがアプリケーションを必要としない場合は、ショートカットを削除することをユーザーに選択させることができます。 Windows の起動時に開始します。

于 2011-09-30T09:35:39.057 に答える
2

プログラムがこれを実現する方法のほとんどはインストーラーを介して行われます。インストーラーは、起動時にプログラムが確実に開始されるようにレジストリを変更するなど、多くのことを実行できますが、この動作を無効にするオプションを常にユーザーに提供する必要があります。

于 2011-09-30T09:11:30.423 に答える