cancel
Showing results for 
Search instead for 
Did you mean: 

RegistryGet of TMP environment in Windows 7 returns -1

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

The registry key is restricted in Windows 7. Try either of the methods Terry or Mark posted.

Former Member
0 Kudos

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.

Former Member
0 Kudos

Here's an interesting read that tells you the why and how about registry restrictions.

http://www.registryonwindows.com/registry-security-2.php

Former Member
0 Kudos

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.

Former Member
0 Kudos

I always use the GetTempPath API function. That way I don't have to worry about the registry format.

Former Member
0 Kudos

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.

former_member1333806
Active Participant
0 Kudos

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.