Arun
Arun

Reputation: 685

startup script in c#

My application need to start when windows start. so i writed a batch file for running the application.

This is the code for writing the batch file path entry to registry.

private void RegisterInStartup(bool isChecked)
{
    RegistryKey registryKey = Registry.CurrentUser.OpenSubKey
            ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
    if (isChecked)
    {
        registryKey.SetValue("ApplicationName", Application.StartupPath+"\\autorun.bat");
    }
    else
    {
        registryKey.DeleteValue("ApplicationName");
    }
}

And this is my batch file code.

start File.exe
exit

When I restart my system the batch file is executing but the application File.exe is not executing.

Why this happening?

Upvotes: 0

Views: 503

Answers (2)

Darek
Darek

Reputation: 4797

The batch file is not started from the directory where it exists. therefore File.exe will not be found. Replace batch with exe, or provide a full path to the exe as well.

Upvotes: 1

Manuel Amstutz
Manuel Amstutz

Reputation: 1388

  1. Test your batch file manually. Click on it. Does the application start?
  2. Enter the path manually in the registry. Does the registry key work?
  3. Export the registry key to a file. Delete the registry and and add it again with your program and export it and compare the two files. If 1 and 2 where working, there must be a difference in the registry key, and with this way you will find the difference

Upvotes: 0

Related Questions