Hello Manish,
thanks for your reply. I tried it with different user accounts with different rights but the result is the same.
Here is my solution to solve the problem:
"-Begin-----------------------------------------------------------------
Report ZTEST.
"-Includes----------------------------------------------------------
Include OLE2INCL.
"-Variables---------------------------------------------------------
Data rc Type i Value -1.
">Stop<
Break-Point.
PerForm CreateKey1 Using 'Software' '' '' Changing rc.
PerForm CreateKey1 Using 'Software' 'Test' 'Test' Changing rc.
PerForm CreateKey2 Using 'Software' '' '' Changing rc.
PerForm CreateKey2 Using 'Software' 'Test' 'Test' Changing rc.
"-End-------------------------------------------------------------------
"-Subroutines begin-----------------------------------------------------
"-Function CreateKey1-------------------------------------------------
Form CreateKey1 Using SubKey Type String ValueName Type String
Value Type String Changing rc Type i.
"-Variables-------------------------------------------------------
Data ret Type i Value 0.
Data rValue Type String Value ''.
Call Method cl_gui_frontend_services=>registry_set_value
Exporting
root = cl_gui_frontend_services=>hkey_current_user
key = SubKey
value_name = ValueName
value = Value
Importing
rc = ret
Exceptions
registry_error = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
Others = 5.
Call Method cl_gui_cfw=>flush.
Call Method cl_gui_frontend_services=>registry_get_value
Exporting
root = cl_gui_frontend_services=>hkey_current_user
key = SubKey
value = Value
Importing
reg_value = rValue
Exceptions
get_regvalue_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
Others = 5.
Call Method cl_gui_cfw=>flush.
If rValue = Value.
rc = 0.
Else.
rc = 1.
EndIf.
EndForm.
"-Class BASIC---------------------------------------------------------
Class cBASIC Definition.
Public Section.
Methods Right Importing Str Type String Length Type i
Exporting Result Type String.
EndClass.
Class cBASIC Implementation.
"-Method Right----------------------------------------------------
Method Right.
"-Variables---------------------------------------------------
Data pos Type i Value 0.
pos = strlen( Str ) - Length.
Move Str+pos(Length) To Result.
EndMethod.
EndClass.
"-Function CreateKey2-------------------------------------------------
Form CreateKey2 Using SubKey Type String ValueName Type String
Value Type Any Changing rc Type i.
"-Variables-------------------------------------------------------
Data BASIC Type Ref To cBASIC.
Data WShell Type OLE2_OBJECT.
Data Key Type String Value ''.
Data rValue Type String Value ''.
Data strTmp Type String Value ''.
Create Object WShell 'WScript.Shell'.
If sy-subrc = 0 And WShell-Handle <> 0 And WShell-Type = 'OLE2'.
Create Object BASIC.
Call Method BASIC->Right Exporting Str = SubKey Length = 1
Importing Result = strTmp.
If strTmp <> '.
Concatenate 'HKCU SubKey ' ValueName Into Key.
Else.
Concatenate 'HKCU SubKey ValueName Into Key.
EndIf.
Call Method Of WShell 'RegWrite' Exporting #1 = Key #2 = Value.
Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
Call Method Of WShell 'RegRead' = rValue Exporting #1 = Key.
Call Function 'AC_SYSTEM_FLUSH' Exceptions Others = 1.
If rValue = Value.
rc = 0.
Else.
rc = 1.
EndIf.
Free Object WShell.
EndIf.
EndForm.
"-Subroutines end-------------------------------------------------------
I use two different ways. The first is with the standard methods - from the class with the ProgID Sapgui.InfoCtrl.1 on SAP GUI for Windows. And the second is via Windows Scripting Host and the methods RegWrite resp. RegRead. Both work as expected.
Cheers
Stefan