I have tried for days, now, to add pathnames to "PATH" using SetEnvironmentVariable(). Useless. "The SetEnvironmentVariable function sets the contents of the specified environment variable for the current process.", states Platform SDK help. Is there another way to set it? It doesn't have to be System one, just User variable.
PS. By setting environmental variable I mean using program to do it, not manually.
Posted on 2003-08-19 18:51:37 by iwabee
In XP in the registry read
HKEY_USERS\keythatneedsenumeratedwithsubkeyenvironment\Environment
Read string "PATH" for instance of type REG_SZ and do your work on it.
You have to enumerate that one key with the {17264 wierd number}
I think SetEnvironmentVariable only works for life of program.
Posted on 2003-08-19 19:33:56 by roaknog
Hit WinKey+Break (same as right clicking my computer->properties) and click on the Advanced Tab, then click on Environment Variables
Posted on 2003-08-20 03:26:52 by eet_1024
or you could use vbscript, for example:


Set ws=WScript.CreateObject("WScript.Shell")
double_quote=""""
ws.Environment("SYSTEM").Item("PATH")=ws.Environment("SYSTEM").Item("PATH")+";"+double_quote+"C:

\Program Files\Common Files"+double_quote


in this example, the script if run would add: ;"C:\Program Files\Common Files" to the existing path.
you might want to make a backup copy of the path just in case you need to restore it.
Posted on 2003-08-20 05:20:30 by jack
Thanks roaknog, but I've searched and found easier way. Environmental settings for current user are at "HKEY_CURRENT_USER\Environment". Haven't tested it yet, but I think it will work. I also found something at
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", wold it be system environments? Danm, I didn't know that NT stores it's envs it register.

eet_1024 It's manual way you suggesting.

well... that script looks kinda cool. Unfortunatly I don't understand it. How can it be executed?
Posted on 2003-08-20 07:14:38 by iwabee
This program displays my path after about the sixth message box in XP.
Posted on 2003-08-20 14:06:12 by roaknog
I don't get it. It seems like when I manually modify User environments, windows stores them in two locations: "HKEY_USERS\S-1-5-21-2025429265-688789844-854245398-500\Environment" and in "HKEY_CURRENT_USER\Environment". Secondary, when I modify one of them using regedit the other changes as well. Does that mean the both keys pointing to the same data? I see no other explanation.
roaknog, I had no time to carefully study your program (yet), but considering what I written above why I have to use HKEY_USERS\666something\Environment" enstead of "HKEY_CURRENT_USER\Environment"?
Posted on 2003-08-20 16:56:22 by iwabee

Does that mean the both keys pointing to the same data?

Why not? The whole HKEY_CURRENT_USER key is virtual... :rolleyes:
Posted on 2003-08-20 17:06:36 by QvasiModo

I have to use HKEY_USERS6something\Environment" enstead of "HKEY_CURRENT_USER\Environment"?

If you want to change the config for the current user (no matter who it is) use HKEY_CURRENT_USER. If you want to change the config of specific users, go to HKEY_USERS\username. This goes for all Win32 platforms. Also works like this for the file associations (HKEY_CLASSES if I recall correctly), it is also virtual.
Posted on 2003-08-20 17:09:26 by QvasiModo
cool. That was my guess. Here goes another question then. Is it possible to know what account is in question when I see S-1-5-21-2025429265-688789844-854245398-500?
Posted on 2003-08-20 17:19:49 by iwabee
I'm unfamiliar with NT based systems... in Win9X the subkeys of HKEY_USERS are always the username in plaintext. Perhaps there's something about it in google, but I wouldn't know... (could be one of those thinks only M$ knows :grin: ) If not forgive my ignorance :)
Posted on 2003-08-20 17:29:40 by QvasiModo
Allright, just searched MSDN. It appears to be in NT based systems instead of the plain username you have the user ID instead. Perhaps there's an API to translate username to userids and visceversa?

Found this docs in MSDN too, you might find them useful anyway...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexnt02/html/ewn0102.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexnt01/html/ewn0201.asp

EDIT: Found GetUserNameEx API call, I think this is what you need...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsysteminfo.asp
Posted on 2003-08-20 17:49:16 by QvasiModo
The only time GetUserNameEx works for me is with: NameSamCompatible,
and not with NameUniqueId.

I believe a numbered interface identifier key represent the administrator's
account.
Posted on 2003-08-20 20:19:46 by roaknog
Yes, GetUserNameEx() doesn't work on my machine eather exept with NameSamCompatible. And for that purpose it's easier to use GetUserName().
I believe a numbered interface identifier key represent the administrator's
account.

Not true, I have logged in on different accounts and each of them had little different ID, but only one.


Administrator:S-1-5-21-2025429265-688789844-854245398-500
Guest: S-1-5-21-2025429265-688789844-854245398-501
itseolet: S-1-5-21-2025429265-688789844-854245398-1002

I thought that other keys are hidden or something, and tried to open using this code (on Administator):
HKEY hKey;
if (RegOpenKey(HKEY_USERS, "S-1-5-21-2025429265-688789844-854245398-501", &hKey) == ERROR_SUCCESS)
{
MessageBox(NULL, "Success", "Box-up-your-ass", MB_OK);
RegCloseKey(hKey);
}
else
MessageBox(NULL, "Failure", "Box-up-your-ass", MB_OK);

But it seems nobody, even Administrator can mess with register of another accounts. I could be wrong of cource..
Posted on 2003-08-21 05:29:06 by iwabee
that script looks kinda cool. Unfortunatly I don't understand it. How can it be executed?


you save it with a vbs extention, ie filename.vbs, and launch it just like any other program.
Posted on 2003-08-21 05:35:52 by jack

But it seems nobody, even Administrator can mess with register of another accounts. I could be wrong of cource..

You're probably right, there are several places in the registry not even Admin can access (like the SAM database). Try running your test program with AT (set it to be scheduled 10 seconds after the current time or so). If I remember correctly, apps scheduled with AT have System priviledges, not Admin (at least in NT it used to be true, I wouldn't know if this was fixed by M$ already). Since System always has access to the entire registry, it should work...
Posted on 2003-08-21 18:17:53 by QvasiModo
AT? :confused:
Posted on 2003-08-22 11:31:35 by iwabee
Originally posted by iwabee
Administrator:S-1-5-21-2025429265-688789844-854245398-500
Guest: S-1-5-21-2025429265-688789844-854245398-501
itseolet: S-1-5-21-2025429265-688789844-854245398-1002


On Win2K+ you may use ConvertStringSidToSid, then user LookupAccountSid to find the user name
Posted on 2003-08-22 18:59:59 by Morris
It's a scheduling program that comes with NT based systems -at least NT4 used to have it. Just type "AT /?" at the command prompt to see the help (it is really easy to use, but you can imagine I didn't memorize it :) ). It was something like "AT {time} {command}".

EDIT:
Indeed, apart from other optional switches, it is "AT time command". You can use "/interactive", I think it is used to allow the scheduled app to popup windows and receive user input.
Posted on 2003-08-22 19:08:02 by QvasiModo
Nope didn't work with AT, BUT that's not important cuz I've found a bigger problem.:(
If you change "path" under HKEY_CURRENT_USER\Environment with your program or regedit, changes will take place only when you logoff and then log in again. How can I reload environmentals?

Morris: Security ID? Sounds scary. Worthwhile to take a look at least.
Posted on 2003-08-23 16:22:38 by iwabee