• Retrieving registry keys… (WinXP, O2003 UK)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Retrieving registry keys… (WinXP, O2003 UK)

    Author
    Topic
    #454832

    Hi,

    I need to retrieve a lot of system specific info. I’m letting the user run a ‘systems check’ from within a command bar in Excel (one they are already used to use)
    It writes a log file back to me and I can subsequently check for discrepancies to the expected standards.

    In a command prompt one can write ‘set’ and get a lot of systemvariables returned in an easy and simple overview.

    Is it possible from within VBA to retrieve either a bulk of values or single values using the same keywords as in ‘set’ (eg. %USERNAME%, %COMPUTERNAME% etc, etc)

    TIA

    Viewing 1 reply thread
    Author
    Replies
    • #1130051

      Yes – with Environ:
      Environ(“username”)
      and so on.

      Edit: You could also use:
      Set > C:environ.txt
      from a command prompt (or use Shell and cmd in vba) to write the whole lot to one text file.

    • #1130052

      You can use Environ(“username”) to retrieve the value of the %username% environment variable.

      You can also fill an array with strings of the form

      SystemDrive=C:

      where SystemDrive is the name of the environment variable and C: is the value:

      Sub ListEnvironment()
      Dim strEnv() As String
      Dim n As Integer
      n = 1
      Do While Not Environ(n) = ""
      ReDim Preserve strEnv(1 To n)
      strEnv(n) = Environ(n)
      n = n + 1
      Loop
      End Sub

      You can parse the array elements to extract the name and value separately.

      • #1130095

        Hi Hans,

        As usual – this is exactly what I was looking for – really useful (and so simple once you know it brickwall )

        THX

      • #1130146

        Nice one, Hans. Thanks.
        Handy for building simple but effective software keys, too!

    Viewing 1 reply thread
    Reply To: Retrieving registry keys… (WinXP, O2003 UK)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: