Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use registry to startup a program, and also change the current working directory?

I am trying to start a program I made in this directory:

C:\example\example.exe -someargument

when the computer starts up. I am attempting to use this registry key:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

with the key being:

Name: example
Type: REG_SZ
Data: "C:\example\example.exe -someargument"

But my program also needs files from the directory C:\example but can't find them since the current working directory is different. Is is possible to do something like this in the registry key value

"cd C:\example\; example.exe -someargument"

so that it will change the directory? Or is there a better solution?

Thanks!

like image 875
Joel Avatar asked May 12 '10 21:05

Joel


People also ask

Where in the registry is the startup programs?

The Run subkey—By far the most common registry location for autorun programs is the Run entry, which you'll find at HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run and HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.

What is the registry used for?

The Registry contains information that Windows continually references during operation, such as profiles for each user, the applications installed on the computer and the types of documents that each can create, property sheet settings for folders and application icons, what hardware exists on the system, and the ports ...


2 Answers

You can also create a shortcut for the program in the folder and reference this shortcut in the registry:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
Name: example
Type: REG_SZ
Data: "C:\example\example.lnk
like image 147
Yuri Avatar answered Sep 21 '22 03:09

Yuri


At the start of the application, do the following (this is C#, convert to C++):

    using System.IO;
:
:
    Environment.CurrentDirectory = Path.GetDirectoryName(Application.ExecutablePath);
like image 31
Simon Chadwick Avatar answered Sep 22 '22 03:09

Simon Chadwick