Results 1 to 3 of 3

Thread: check to see if a reg key exists

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    socal
    Posts
    74

    check to see if a reg key exists

    langage: vbscript

    I want to check if a registry key exisits, not what its values is, just that fact that its there. what I am trying to do is rebrand office defualt file save locations.

    i want to reset that in my vbs logons scripts. so, how can i check if the key exisits?

    reason: the key only exisst if word,excel have been run.


    -nex6

  2. #2
    New Member gecko_au2003's Avatar
    Join Date
    Sep 2004
    Posts
    4

    Re: check to see if a reg key exists

    If you go here :

    http://ourworld.compuserve.com/homep...azaar/WSH2.htm

    about half way down the page there is an example ( You can modify it for your needs to check the existance of a registry key )

  3. #3
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: check to see if a reg key exists

    here is an edited version for you.

    No need to set it to a variable ..
    if it gives an error when reading the key then it doesnt exist.
    Code:
    Option Explicit
    
    If KeyExists("HKCR\.bmp\") Then
        MsgBox "Found"
    Else
        MsgBox "Not Found"
    End If
    
    Function KeyExists(key)
        Dim objShell
        On Error Resume Next
        Set objShell = CreateObject("WScript.Shell")
            objShell.RegRead (key)
        Set objShell = Nothing
        If Err = 0 Then KeyExists = True
    End Function
    Last edited by rory; Sep 2nd, 2006 at 09:59 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width