Unable to add %APPDATA% to the path

Darren Collins
Darren Collins used Ask the Experts™
on
I would like to be able to add "%APPDATA%\AFolder" to the %PATH%.

This is so that whoever logs on to the computer will have a path statement with

;C:\Documents and Settings\user1\Application Data\AFolder

I am adding it using the Environment table within an MSI.  See Code box below for Environment table entry.

The result is that the Path environment variable is not expanding the %APPDATA% variable.

I get:
   C:\ >set PATH
   PATH=%APPDATA%\AFolder

Instead of:
   C:\ >set PATH
   PATH="C:\Documents and Settings\user1\Application Data\AFolder"

This behaviour is described as a bug in shell32.dll (for over two years!!) here: http://support.microsoft.com/kb/329308  and here: http://windowsitpro.com/article/articleid/77604/jsi-tip-6300-appdata-environment-variable-does-not-expand-when-added-to-the-path.html  and both describe the same workaround which is to set the path manually using the Manage Computer GUI.

I need to know if there is a way to this programmatically so I can create a custom action in the MSI to bypass the bug.

Many thanks,
Daz
Environment  Name      Value                   Component_
PATH         *=-PATH   [~];%APPDATA%\AFolder   Environment

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I think WHY this does it is obvious when you think that the PATH envrionment variable is global and the APPDATA is user specific.  The method specified as a workaround actually resolves the %appdata% (and any other entries in there such as the systemroot entries and stores that user specific entry not the user one.

I'm listening here mainly to see if anyone has any workarounds as I gave up on a similar issue a while back and relocated the files to a non user-based dir instead... the other ways being potential bodges that amends the path as users login I guess.

Steve
Darren CollinsTech Lead (Windows), Endpoint Device Management Services

Author

Commented:
Cheers, Steve.  I thought this might be an easy way to use a secure local directory structure that already exists, but not as easy as I thought.  I will probably either abandon this dev path as you suggest or perhaps use the old Active Setup to amend the users own path at logon.

Daz.
Commented:
You can see the point of dragon-it when you add the %TEMP% variable to the PATH. This will resolve to "C:\Temp" instead of "C:\Documents and Settings\<username>\Local Settings\Temp".

Perhaps you could add the following line to the logon script:
SET PATH=%PATH%;%APPDATA%\AFolder

Or set a Logon script in a GPO for all users with this line.

Both can be more easily managed than the Active Setup approach.
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Commented:
If you set the path like that though it does not change the path the users will see, there are ways of doing that BUT the path is not editable by a non-admin user AND you need to run it as your user because it is their appdata ... catch 22
Darren CollinsTech Lead (Windows), Endpoint Device Management Services

Author

Commented:
Hi Steve,

When you use setx.exe without the -m switch, it sets a permanent environment variable that is a user environment variable visible to that user only, stored in their profile (HKCU).  The machine path is indeed not amended, but an additional user environment variable (in this case PATH) is created including any amendments.

Therefore since Active Setup is run once per user, per machine, in the user context, this provides the solution I need.

Daz.
Darren CollinsTech Lead (Windows), Endpoint Device Management Services

Author

Commented:
Thanks for taking the time to answer.  I'm glad that there wasn't anything obvious I was missing so thanks for confirming that.

Daz.

Commented:
Good stuff... I'll check sex out, never had a need to do that before but can see it helping for this.
Darren CollinsTech Lead (Windows), Endpoint Device Management Services

Author

Commented:
Setx.exe is included as part of the Windows XP Service Pack 2 Support Tools:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=49ae8576-9bb9-4126-9761-ba8011fabf38


Daz.

Commented:
Oh for the ability to edit typos out of mistakes :-(
Darren CollinsTech Lead (Windows), Endpoint Device Management Services

Author

Commented:

  :o)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial