azizrasul Posted October 4, 2020 Posted October 4, 2020 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 JLogan3o13 Posted October 4, 2020 Moderators Posted October 4, 2020 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!
azizrasul Posted October 5, 2020 Author Posted October 5, 2020 (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 October 5, 2020 by azizrasul
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now