Archive: System variable for system AppData


System variable for system AppData
Hi all,

I am wondering if NSIS installer has a system variable to point to this location:

$SYSDIR\config\systemprofile\AppData\Roaming\

or at least variable for "AppData". This is system not user's AppData.

Many thanks!


When running as system (In a service or whatever), $APPDATA should point there (I have never tried)

But I'm guessing you are really asking how to get that folder when running as admin so you can put data there for your service/driver/whatever. I don't think you are really supposed to do that. There are several hacky ways to get that path, but unless you have a very specific need for something microsoft specific stored there, I would suggest you just store $instdir (or whatever files you need access to) somewhere in the HKLM part of the registry (If it is for a service, your service key will have a parameters subkey etc)


Thanks Anders!
Yep, I want to remove service log at that location. Our application stores service log there, so I need to remove it when uninstall.


Well, there are many ways to skin this cat:

A) Store the log somewhere else (Why the hell would you store it there? No user is ever going to check it)

B) Use the system even log, that's what it is there for (Unless you are logging lots of stuff)

C) Use ControlServiceEx and send custom control codes to the service so the service can perform the action for you

D) The service could store the AppData path somewhere in the registry when it starts so you can read it in any app (If you can't change the service itself, create a helper service or taskscheduler app that can)

E) Hack#1: Get path to profile from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-18 and hardcode the rest or search the subfolders for your log

F) Hack#2: Somehow ;) get a copy of the system token and call ShGet*() functions with it

---

This is just off the top of my head, I'm sure there are more (and possibly) better ways to go about this


Thanks Anders! I am asking the client to update a HKLM entry "LogDirectory" that installer will create when run installation. Upon un-installation, I'll read that entry then remove the log. Will that work?


It'll work, assuming that the directory has not been changed since the regkey was last updated. But you don't need to create the regkey during installation, you can let the service create it.