I
I
Ingvar Von Bjork2016-11-05 00:20:43
C++ / C#
Ingvar Von Bjork, 2016-11-05 00:20:43

How to add a program to startup?

There is a program (prog1) that adds another program (prog2) to startup as follows:

string ExePath = Environment.CurrentDirectory + "\\prog2.exe"; //получает текущий путь до приложения
RegistryKey reg; //ключ реестра
reg = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run\\");
reg.SetValue("prog2.exe", ExePath); //добавляется в автозагрузку
reg.Close();

And prog2 checks for the existence of example.txt with File.Exists. If prog2 is started manually, then it successfully finds the file, but if prog2 is started from autoload, then it cannot find anything. Can anyone tell me how to be and what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Ингвар Фон Бьёрк, 2016-11-05
@DeboshiR

В аргументах File.Exists использовать Application.StartupPath

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question