Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Retrieving registry keys... (WinXP, O2003 UK)

    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
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Retrieving registry keys... (WinXP, O2003 UK)

    Yes - with Environ:
    Environ("username")
    and so on.

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

    Microsoft MVP - Excel

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieving registry keys... (WinXP, O2003 UK)

    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:
    <code>
    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
    </code>
    You can parse the array elements to extract the name and value separately.

  4. #4
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieving registry keys... (WinXP, O2003 UK)

    Hi Hans,

    As usual - this is exactly what I was looking for - really useful (and so simple once you know it <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15> )

    THX
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieving registry keys... (WinXP, O2003 UK)

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •