Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to query the registry with WScript.Shell
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00571288
Message ID:
00571360
Views:
25
>>Running the following code result in an error if the key "Users" doesn't exist in the registry.
>>
>>goWsHost = CreateObject("WScript.Shell") && initiate Windows Scripting Host
>>
>>REGKEY_LOC = "HKEY_CURRENT_USER\Software\Ifö Ceramics AB\PiDoc\1.0\Window Positions\Users"
>>
>>* Next line gives an error saying it can not open the registry key.
>>lcBuffer = goWsHost.RegRead(REGKEY_LOC)
>>
>>Well i understand that it can not, but how can i query the registry to check for the existance of the key or att least avoid the error message ?
>
>You can use "local" error handler to trap errors or put the code into class and use class error event
>lcOnErrorSave = ON("ERROR")
>lnError = 0
>ON ERROR lnError = ERROR()
>
>lcBuffer = goWsHost.RegRead(REGKEY_LOC)
>
>IF lnError = 1429     && OLE Error
>  * OLE error on the previous line. Use AERROR() to get error details
>ELSE
>  * The key value retrieved
>ENDIF
>
>ON ERROR &lcOnErrorSave
You can also use Registry class from FFC. It's based on Windows API functions.

>> I have exactly such an local error handler but the code in the forms Error method still executes. Is it not possible to bypass the forms Error method and just letting the local error handler handle the error ?
I have added the "CASE nError = 1429" into the forms Error method just to avoid
getting the messagebox with the error message.

/Torgny
/Torgny
Previous
Reply
Map
View

Click here to load this message in the networking platform