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.
PS. By setting environmental variable I mean using program to do it, not manually.
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.
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.
Hit WinKey+Break (same as right clicking my computer->properties) and click on the Advanced Tab, then click on Environment Variables
or you could use vbscript, for example:
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.
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.
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?
"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?
This program displays my path after about the sixth message box in XP.
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"?
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"?
Does that mean the both keys pointing to the same data?
Why not? The whole HKEY_CURRENT_USER key is virtual... :rolleyes:
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.
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?
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 :)
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
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
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.
and not with NameUniqueId.
I believe a numbered interface identifier key represent the administrator's
account.
Yes, GetUserNameEx() doesn't work on my machine eather exept with NameSamCompatible. And for that purpose it's easier to use GetUserName().
Not true, I have logged in on different accounts and each of them had little different ID, but only one.
But it seems nobody, even Administrator can mess with register of another accounts. I could be wrong of cource..
I believe a numbered interface identifier key represent the administrator's
account.
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..
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.
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...
AT? :confused:
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
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
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.
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.
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.
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.