PDA

View Full Version : How to correctly update a REG_EXPAND_SZ setting?



NewsArchive
09-14-2017, 11:25 AM
Hi all, hi Friedrich,

I need to update a REG_EXPAND_SZ setting:

Original:
---------
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems\Windows
%SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows
SharedSection=1024,20480,768 Windows=On SubSystemType=Windows
ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3
ServerDll=sxssrv,4 ProfileControl=Off MaxRequestThreads=16

Must become:
------------
%SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows
SharedSection=1024,20480,8192 Windows=On SubSystemType=Windows
ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3
ServerDll=sxssrv,4 ProfileControl=Off MaxRequestThreads=16

So the part, that has to be changed is:
SharedSection=1024,20480,768
into:
SharedSection=1024,20480,8192
The third number (768) is the size of non-interactive (services)
sessions, and has to become: 8192

So how can I accomplish this with SB?

Can somebody please help me?

--
Best regards,
Jeffrey

NewsArchive
09-15-2017, 03:31 AM
Anyone?
I need to finish my setup and don't know how to handle with this
REG_EXPAND_SZ setting in SB. ;-)

Best regards,
Jeffrey

NewsArchive
09-15-2017, 08:33 AM
Hi Jeffrey,

> I need to finish my setup and don't know how to handle with this
> REG_EXPAND_SZ setting in SB. ;-)

Just one script function (see attached screenshots) with the changed value
(768 to 8192).

Does this help?

Friedrich

NewsArchive
09-15-2017, 08:34 AM
Hi Friedrich,

Thank you, but it's more complicated:

I know how to create/update a registry setting in SB, but I *only* want
to change 768 into 8192. So I don't want to overwrite the rest at my
customers pc. Because then I take the risk that I overwrite other
settings at my customers pc.

So first I need to read THEIR original registry setting.
And after that, I have to replace 768 into 8192, and put this little
portion back into THEIR original registry setting.

I hope you understand me?

Best regards
Jeffrey

NewsArchive
09-15-2017, 08:35 AM
Hi Jeffrey,

> Thank you, but it's more complicated:
>
> I know how to create/update a registry setting in SB, but I *only* want
> to change 768 into 8192. So I don't want to overwrite the rest at my
> customers pc. Because then I take the risk that I overwrite other
> settings at my customers pc.
>
> So first I need to read THEIR original registry setting.
> And after that, I have to replace 768 into 8192, and put this little
> portion back into THEIR original registry setting.
>
> I hope you understand me?

No problem (see attached screenshot). Read the old value (Line 76), replace
768 with 8192 (Line 78), re-write the new value (Line 80).

Does this help?

Friedrich

NewsArchive
09-15-2017, 08:36 AM
Hi Friedrich,

Yes, super, that's what I'm looking for.
You're the master!
SB rocks, so so powerful!!

Best regards,
Jeffrey

NewsArchive
09-15-2017, 08:36 AM
Hi Friedrich,

Oops...

SB reads:
%SystemRoot%\system32\csrss.exe as:
C:\WINDOWS\system32\csrss.exe

What will happen when I write my find/replace stuff back?
Will it contain %SystemRoot% (which is needed) or will it contain
C:\WINDOWS (wrong)?

Best regards,
Jeffrey

NewsArchive
09-15-2017, 08:37 AM
Hi Friedrich,

When writing back, %SystemRoot% has been "overwritten" by C:\WINDOWS
I don't want that of course.
The culprit is that the ReadRegistry is expanding %SystemRoot% into
C:\WINDOWS, so that I'm not able to write back the original %SystemRoot%.

Hmm, complex, this one...

Best regards,
Jeffrey

NewsArchive
09-15-2017, 08:38 AM
Hi Jeffrey,

> When writing back, %SystemRoot% has been "overwritten" by C:\WINDOWS
> I don't want that of course.
> The culprit is that the ReadRegistry is expanding %SystemRoot% into
> C:\WINDOWS, so that I'm not able to write back the original %SystemRoot%.
>
> Hmm, complex, this one...

This is what I see here from my test script (it rertieves %SystemRoot%).
And it writes back %SystemRoot% after the replace operation....

Friedrich

NewsArchive
09-15-2017, 08:39 AM
Hi Friedrich,

Here on my Windows 10 Pro 64-bit machine, it's shown expanded, see
screenshot attached.

Best regards,
Jeffrey

NewsArchive
09-15-2017, 08:40 AM
Hi Friedrich,

Your helpfile about "Edit Registry" says:

"Remarks
Return values for the REG_EXPAND_SZ type are automatically expanded."

Best regards,
Jeffrey

NewsArchive
09-15-2017, 08:41 AM
Hi Friedrich,

FYI:

I saw this thread about Powershell:
https://www.sepago.com/blog/2013/08/22/reading-and-writing-regexpandsz-data-with-powershell

In Powershell, there is an option "DoNotExpandEnvironmentNames" to NOT
expand.

Best regards,
Jeffrey

NewsArchive
09-15-2017, 09:10 AM
Jeffrey,

what happens when you read the same value from a Clarion program?

SetupBuiler retrieves this value directly from the Windows Registry via the
Windows APIs. As far as I know, the Windows APIs always resolve the system
variables (when defined). I don't see any option in the APIs to not resolve
the system variables. Do you see such an option?

Friedrich

NewsArchive
09-15-2017, 09:11 AM
Hi Friedrich,

Clarion doesn't expand the values eg


PROGRAM

MAP
END

INCLUDE('EQUATES')

WordPad cstring(200)
vt long

CODE
WordPad =
GETREG(REG_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windo ws\CurrentVersion\App
Paths\WORDPAD.EXE ',,vt)
message(WordPad & ' ValueType: ' & vt)

Beware wordwrap above.
In fact Carl Barnes has a PTSS open on that specific issue
PTSS 42519
"If one of the Registry functions (e.g. GetReg()) returns ValueType
REG_EXPAND_SZ the return Value contains environment strings like
%windir% and must be run through Win32 function
ExpandEnvironmentStringA() to use it. This makes the CW REG API
incomplete"

Graham

NewsArchive
09-15-2017, 09:11 AM
Hi Graham,

thanks for the info! Yes, our SB REG function expands (defined) environment
variables automatically. I'll add an option to not automatically expand
environment strings.

Friedrich

NewsArchive
09-15-2017, 09:11 AM
Hi Jeffrey,

found a way to not automatically expand environment strings if the value is
of type REG_EXPAND_SZ. But this needs a compiler change and is not
available in your SB build :-(

Friedrich

NewsArchive
09-15-2017, 09:12 AM
Hi Friedrich,

See Graham's reaction.

Best regards,
Jeffrey

NewsArchive
09-15-2017, 09:12 AM
Thank you Graham for sharing this info.

Best regards,
Jeffrey

NewsArchive
09-15-2017, 09:28 AM
Hi Friedrich,

> found a way to not automatically expand environment strings if the
value is
> of type REG_EXPAND_SZ.

Nice, that's exactly what I need.
Perhaps some option "Expand ON" or "Expand OFF", so you can decide
yourself what's best?


> But this needs a compiler change and is not
> available in your SB build :-(

But I need it now. ;-) Is there some other way I can get this latest
version?

Best regards,
Jeffrey

NewsArchive
09-16-2017, 03:09 AM
Jeffrey,

> Nice, that's exactly what I need.
> Perhaps some option "Expand ON" or "Expand OFF", so you can decide
> yourself what's best?

Yes, I'll add this to the next SetupBuilder maintenance build.

> > But this needs a compiler change and is not
> > available in your SB build :-(
>
> But I need it now. ;-) Is there some other way I can get this latest
> version?

Unfortunately, it's not a simple re-compile :-( We have to recompile all
internal libraries and runtimes after this compiler modification.

As far as understand, it only works in Clarion because the CW REG API is
incomplete at the moment.

I have created a quick-and-dirty Clarion DLL (source code included):

http://www.lindersoft.com/RegHelperDll.zip

The installer calls into the Clarion DLL, reads the value (and does not
expand environment variables), then returns that value to the installer.
The installer modifies the registry value and writes it back to the
registry.

Does this work?

Friedrich

NewsArchive
09-16-2017, 03:09 AM
Should read:

http://www.lindersoft.com/projects/RegHelperDll.zip

Friedrich

NewsArchive
09-16-2017, 03:10 AM
404

Jeff Slarve
www.jssoftware.com

you know what happens when you assuage

NewsArchive
09-16-2017, 03:10 AM
2nd one worked

Jeff Slarve
www.jssoftware.com

you know what happens when you assuage

NewsArchive
09-16-2017, 03:11 AM
>
> 404
>

Sorry for that. Sent before I checked the link :-(

Friedrich

NewsArchive
09-16-2017, 03:12 AM
So what we are doing here is, we enhance (or change) the functionality of
SetupBuilder with Clarion ;-)

Friedrich

NewsArchive
09-16-2017, 03:12 AM
Hi Friedrich,

Yes, this certainly helps!!
Wow, what a great solution, thank you!

Best regards,
Jeffrey

NewsArchive
09-16-2017, 03:13 AM
Hi Jeffrey,

> Thank you Graham for sharing this info.
The solution to this can be simple: You can write your own DLLs for
SetupBuilder in Clarion. So you can call your dll and let IT handle the
APIs needed to update the registry. The general read registry API do
not expand environment variables and you may be able to use
GetReg/PutReg since it doesn't expand it either.

So your code could be pretty simple:

S STRING(10240)
CODE
S = GETREG(...)
! search / replace
PUTGET(...)

I have done a DLL for SB in C6 and it has worked for years with no
issues at all. If you need, I'd be happy to send you a copy of the source.

Best regards,


--
Arnor Baldvinsson
Icetips Alta LLC

NewsArchive
09-16-2017, 03:18 AM
Hi Jeffrey,

> I have done a DLL for SB in C6 and it has worked for years with no
> issues at all. If you need, I'd be happy to send you a copy of the source.
Never mind, I see Friedrich has already done that! :)

Best regards,


--
Arnor Baldvinsson
Icetips Alta LLC

NewsArchive
09-16-2017, 03:18 AM
Thank you Arnor!

Best regards
Jeffrey

NewsArchive
09-19-2017, 02:02 AM
Hi Friedrich,

Just to let you know that all is working fine now with this Helper DLL,
very powerful!

Thanks again!

Best regards,
Jeffrey

NewsArchive
09-19-2017, 02:04 AM
Hi Jeffrey,

> Just to let you know that all is working fine now with this Helper DLL,
> very powerful!
>
> Thanks again!

Thank you for the good news :-)

BTW, I have added a new option to the "Get Registry Key Value..." script
function. This will be available in the next maintenance build. Thank you
for your suggestion!

Friedrich

NewsArchive
09-19-2017, 02:05 AM
Hi Friedrich,

Thank YOU for adding this future option!

Best regards,
Jeffrey