Jump to content

Recommended Posts

Posted

Does anyone have an example where you can include functions in the same vbscript file and call them? I'm thinking of checking whether a reg key exists before deleting it.

  • Moderators
Posted

I guess I am not understanding what you're after. If you Google "function in vbscript example" there are literally a million hits that show the proper syntax. What have you tried that is not working?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted (edited)

In the following code I want to check whether a registry key exists before deleting the key. I have a function that checks whether a key exists. See below. I can't get the key to delete, in other words MsgBox "123" never happens.

Dim strKey12

strKey12 = "HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Access\Security\Trusted Locations\Location3\"

If ReadRegistry(strKey12)=True Then
MsgBox "123"
Set objShell = CreateObject("WScript.Shell")
objShell.RegDelete (strKey12)
Set objShell = Nothing
End If

 

Public Function ReadRegistry(strKey)

Dim strValue

Set objShell = CreateObject("WScript.Shell")    
strValue = objShell.RegRead(strKey)
MsgBox strValue

If strValue = "" then
    ReadRegistry = False
    MsgBox "False"
Else
    ReadRegistry = True
    MsgBox "True"
end if

End Function

Edited by azizrasul

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...