?
Solved

How to delete registry key.. VB script

Posted on 2005-02-24
4
Medium Priority
?
5,980 Views
Last Modified: 2008-01-09
Hi

Creating registry keys using the script from  http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21325149.html

I now need a VB script to delete it.

I'm trying this but it does not seem to work.

Option Explicit

Dim strComputer
Dim oReg
Dim strKeyPath
Dim strValueName

const HKEY_CURRENT_USER = &H80000001
'Set objArgs = WScript.Arguments
'strValueName = objArgs(0)

strComputer = "optimist"

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "\HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI"
strValueName = "Northwind"
 
oReg.DeleteValue HKEY_CURRENT_USER,strKeyPath,strValueName



Any suggestions

Thanks

- Jeff
0
Comment
Question by:jeffg_91911
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
Smallint earned 2000 total points
ID: 13396822
Here you have.

Cheers


Option Explicit

Dim oShell
Dim sRemoteComputer
Dim DataSourceName
Dim sRootPath


function CapturingCMDInfo(strCommand)

     dim oExec
     
     CapturingCMDInfo= "" 
     Set oExec = oShell.Exec (strCommand)

     Do While Not oExec.StdOut.AtEndOfStream
         CapturingCMDInfo = oExec.StdOut.ReadAll()
          If Instr(CapturingCMDInfo, "out") > 0 Then
               Exit Do
          End If
     Loop

end function

Sub DeleteRemoteRegValue(sRemoteComputer,sPath,sKey)

     Dim sResult

     if skey = "" then          
           sResult = CapturingCMDInfo("REG DELETE " & chr(34) & sRemoteComputer & sPath & chr(34) &" /f")
     else
      sResult = CapturingCMDInfo("REG DELETE " & chr(34) & sRemoteComputer & sPath & chr(34) & " /v "& sKey & " /f")
     end if            
         

     If instr (sResult, "operation completed successfully") = 0 Then
          msgbox("Failed Deleting " & sPath & "\" & sKey & "!!!" )
          Set oShell = Nothing
          WScript.quit
     end if


end Sub

'***** Specify remote computer *****
sRemoteComputer = "\\maverick"
 
Set oShell= WScript.CreateObject("WScript.Shell")
     
'***** Specify the DSN parameters *****
DataSourceName = "Northwind"
sRootPath = "\HKLM\SOFTWARE\ODBC\ODBC.INI\"


call DeleteRemoteRegValue(sRemoteComputer,sRootPath & "ODBC Data Sources" , DataSourceName)
call DeleteRemoteRegValue(sRemoteComputer,sRootPath & DataSourceName,"" )

msgbox("Success!!!")

Set oShell = Nothing
0
 

Author Comment

by:jeffg_91911
ID: 13396903
Excellet. thanks so much.
0
 
LVL 7

Expert Comment

by:Smallint
ID: 13397370
Glad to help. Thanks to you for points. :))
0
 

Author Comment

by:jeffg_91911
ID: 13442472
I have a follow up queston to this.
I will Post it as a new question with the subject "VB Script How to remotely delete multiple odbc connections."

Thanks

- Jeff
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question