on 05-28-2013 5:50 PM
PB 11.5 on Win7 64bit PC.
I am not able to get the TEMP environment variable on windows 7 in Powerbuilder 11.5.1 build 4675.
int li
string ls_temp_dir
li = RegistryGet("HKEY_CURRENT_USER\Environment\TEMP", "", RegString!, ls_temp_dir)
li returns -1
Try this method...
long ll_rc,
contextKeyword lcx_key
string ls_values
string ls_temp_dir
// get the TEMP environment variable
ll_rc = getContextService("Keyword", lcx_key)
lcx_key.getContextKeywords("TEMP", ls_values)
ls_temp_dir = ls_values[1]
hth,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The registry key is restricted in Windows 7. Try either of the methods Terry or Mark posted.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am working now with Marks contextKeyword solution. Thank you all for your help.
I can tell that I can not GetRegistry for anything in HKEY_CURRENT_USER\Environment.
Can you tell me where it is documented that in Windows 7 no one can read this entry?
( I can set the value with SetRegistry.)
It would be good to know which items in Windows 7 registry can and can not be read.
Here's an interesting read that tells you the why and how about registry restrictions.
It's not a rights issue.
The TEMP and TMP registry values are of type REG_EXPAND_SZ and you need to use the ValueType RegExpandString! instead of RegString!, otherwise Powerbuilder doesn't know how to handle them. We use RegistryGet for picking up some environment variables for our helpdesk program and it works fine, even when run as a regular user. You just need to match the type of the registry value you're retrieving.
Using GetTempPath is still a good way to get the path for temp files, but for other environment variables (and registry settings in general), I was just stating that you need to use the proper ValueType in order to get data. Reading the registry is only restricted in a few places, and should not normally fail due to rights problems. Writing to the registry *IS* restricted in a lot of places and can require admin privileges to actually work. It all depends on where you're trying to write.
I always use the API functions (maybe faith that they'll be supported more consistently in the future than other methods?).
External Function Prototypes:
Function ulong GetTempPath (ulong nBufferLength, ref string lpBuffer) library "KERNEL32.DLL" Alias for "GetTempPathW"
Function uint GetTempFileName (ref string lpPathName, ref string lpPrefixString, uint uUnique, ref string lpTempFileName) Library "KERNEL32.DLL" Alias for "GetTempFileNameW"
Instance Variables
CONSTANT PROTECTED integer MAX_PATH = 260
function of_gettemppath () returns string
ulong lul_Return
string ls_Path = Space (MAX_PATH)
lul_Return = GetTempPath (MAX_PATH, ls_Path)
IF (lul_Return > MAX_PATH) OR (lul_Return = 0) THEN SetNull (ls_Path)
RETURN ls_Path
function of_gettempfilename (string as_prefix, string as_directory) returns string
ulong lul_Unique = 0, lul_Return
string ls_TempFile = Space (MAX_PATH)
lul_Return = GetTempFileName (as_Directory, as_Prefix, lul_Unique, ls_TempFile)
IF lul_Return = 0 THEN SetNull (ls_TempFile)
RETURN ls_TempFile
Good luck,
Terry.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.