Author Topic: Read Registry Values and store as variables  (Read 3049 times)

samkatakouzinos

  • Newbie
  • *
  • Posts: 14
Read Registry Values and store as variables
« on: August 28, 2017, 01:20:14 AM »
Feature Request: Read Registry Values and store as variables

VoiceAttack would read registry values on Windows systems.

An example would be to 'Set a Text Value' called UserDocumentsFolder
and Set Text Value To Value from file/URI: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders,Personal

This would then put the users 'My Documents' location into a variable for later reference.
The idea is taken from the reg.exe query command .

References:
https://ss64.com/nt/reg.html (REG.exe Read, Set or Delete registry keys and values, save and restore from a .REG file)
https://stackoverflow.com/questions/3492920/is-there-a-system-defined-environment-variable-for-documents-directory (Is There A System Defined Environment Variable For Documents Directory?)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Read Registry Values and store as variables
« Reply #1 on: August 28, 2017, 06:00:45 AM »
You can retrieve that value using an inline C# function:
Code: [Select]
using System;
using Microsoft.Win32;

public class VAInline
{
    public void main()
    {
        VA.SetText("UserDocumentsFolder", Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Personal", "").ToString());
    }
}

samkatakouzinos

  • Newbie
  • *
  • Posts: 14
Re: Read Registry Values and store as variables
« Reply #2 on: August 28, 2017, 12:16:07 PM »
Urgh, the dark corners of programming  :-\
Where's my flashlight. I'll need to go exploring  ???

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4759
  • RTFM
Re: Read Registry Values and store as variables
« Reply #3 on: August 28, 2017, 12:25:32 PM »
All you need to do is to paste that code snippet into the "Inline Function - C# Code" action found under Other->Advanced->Execute an Inline Function->C# Code

When it runs, a text value named "UserDocumentsFolder"(as used in your example) will contain what is in that registry key.