I am attempting to get a value from the registry in order to complete a print function using crystal reports.
But it errors out when I do the path because my registry path isn't working properly.
Values- Global.gAPPNAME = "TEST" Global.gAPPSECTION = "STARTUP"
Global.gREPORTDIR = Registry.GetValue(Global.gAPPNAME, Global.gAPPSECTION, "REPORTDIR").ToString();
When it hits the Global.gREPORTDIR line I get the error - "registry key name must start with a valid base key name"
I am new to this and I was wondering whether this is something that can be fixed with code or something I need to find within the actual computer to find the correct path. Any advice would help. Thanks.
You need to specify a valid root name:
Valid root names are
HKEY_CURRENT_USER
,HKEY_LOCAL_MACHINE
,HKEY_CLASSES_ROOT
,HKEY_USERS
,HKEY_PERFORMANCE_DATA
,HKEY_CURRENT_CONFIG
, andHKEY_DYN_DATA
.
You can read about Registry.GetValue here: http://msdn.microsoft.com/library/microsoft.win32.registry.getvalue.aspx
So your error comes from first parameter:
Valid root names are HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, HKEY_USERS, HKEY_PERFORMANCE_DATA, HKEY_CURRENT_CONFIG, and HKEY_DYN_DATA. For example, in Visual Basic the string "HKEY_CURRENT_USER\\MyTestKey" accesses key/value pairs for the subkey "MyTestKey" in the HKEY_CURRENT_USER root.
You can use static keys for easy use
Registry.LocalMachine.Name
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.