user2801425
user2801425

Reputation: 11

How to install to current user path?

I'm making an installer and I want it to extract to a specific user path like C:\Current User\Documents with current user being the current user installing it. Anyway to do this?

Upvotes: 0

Views: 4495

Answers (1)

Superbob
Superbob

Reputation: 732

The most important thing is to never hard-code a path like C:\Current User\Documents or C:\Documents and Settings\username, because the actual folder names will vary depending on the Operating System and language of the user's computer.

In most installers, you can use a pre-defined command-line variable for various OS defined folders. For example, the variable %HOMEDRIVE% points to the default driver letter such as C:\, and %HOMEPATH% is usually the profile folder. So, on my computer,

%HOMEDRIVE%\%HOMEPATH% = C:\Users\username

The command-line variable %USERPROFILE% points to the same location. If you just need the username, use %USERNAME%.

If you are looking for the user's "My Documents" folder or other similar folders, you can get it from the registry:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

Upvotes: 1

Related Questions