On 2019-12-25 21:48, WFB wrote:
On Wed, 25 Dec 2019 at 23:10, ToddAndMargo via perl6-users
<[email protected] <mailto:[email protected]>> wrote:
Hi All,
Windows
https://docs.microsoft.com/en-us/windows/win32/sysinfo/retrieving-data-from-the-registry
How do I use this to read retrieve a value of a registry key?
Many thanks,
-T
Hi Todd,
Two things comes to mind for solving this. First, you use the Windows
Commandline command REG together with "run". See REG /? for more
information.
Or second, use NativeCall to use the Windows API calls similar to your
MessageBox module.
Your link shows the needed API calls.
BTW, hat would be also a great module for pushing to
https://modules.raku.org/.
Greetings,
Wolf
Hi Wolf,
I am trying to do it with native call. So far, I get
$ perl6 -I. -e "use WinMount :GetLUA; say GetLUA();"
===SORRY!=== Error while compiling /home/CDs/Windows/NtUtil/WinMount.pm6
(WinMount)
Calling RegQueryValueExW(Str, NativeCall::Types::CArray[uint16], int,
NativeCall::Types::CArray[uint16]) will never work with declared
signature (NativeCall::Types::CArray[uint16] $,
NativeCall::Types::CArray[uint16] $, int32,
NativeCall::Types::CArray[uint16] $ --> int32)
at /home/CDs/Windows/NtUtil/WinMount.pm6 (WinMount):69
------> $DWord = âRegQueryValueExW( "HKEY_LOCAL_MACHINE",
I am doing something wrong:
<part of WinMount.pm6>
constant WCHAR = uint16;
sub to-c-str( Str $str ) returns CArray[WCHAR] {
my @str := CArray[WCHAR].new;
for ( $str.comb ).kv -> $i, $char { @str[$i] = $char.ord; }
@str[ $str.chars ] = 0;
@str;
}
sub GetLUA() is export( :GetLUA ) {
#`{
Returns the LUA value in the registry to True (0x00000001) or False
(0x00000000)
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
"EnableLUA"=dword:00000000
use RegQueryValueExW if you know key and value name
https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw
https://docs.perl6.org/language/nativecall
C++
LSTATUS RegQueryValueExW(
HKEY hKey, # Hive name (HKEY_LOCAL_MACHINE)
LPCWSTR lpValueName, # path to the
key(/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System/EnableLUA)
LPDWORD lpReserved, # give it "int32" without the quotes to
give it a NULL
LPDWORD lpType, # Registry Value Type (REG_DWORD which is
32 bit)
LPBYTE lpData, # Pointer to the return value
LPDWORD lpcbData # number of bytes in the return value
);
}
my Str $SubName = &?ROUTINE.name;
my Str $OS = $*KERNEL.name;
if not $OS eq "win32" { say "Sorry, $SubName only work in Windows.";
exit; }
constant hKey = CArray[WCHAR];
constant lpValueName = CArray[WCHAR];
constant INT = int32;
constant lpType = CArray[WCHAR];
constant lpData = Pointer[void];
constant lpcbData = uint32;
my Bool $LUA = True;
my int32 $DWord;
my int32 $DLen;
sub RegQueryValueExW( hKey, lpValueName, INT, lpType ) is
native('user32') returns INT { * };
$DWord = RegQueryValueExW( "HKEY_LOCAL_MACHINE",
to-c-str(
"/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System/EnableLUA" ),
int32,
to-c-str( "REG_DWORD" ) );
if $DWord == 0 { $LUA = False; }
return $LUA;
}
</part of WinMount.pm6>