Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Delete Registry Key 2

Status
Not open for further replies.

123FakeSt

IS-IT--Management
Aug 4, 2003
182
I get an error "can't delete registry key" when running. I can delete it manually.

Code:
'--------------Main Function----------------
Dim FSo, logFile, objCmd, path, fileName

Set FSO = CreateObject("scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")

'Create Log File and Write Header
Set logFile = FSO.CreateTextFile ("C:\Temp\HP_Removal.txt", True)
logFile.Write "HP Printer Port Removal Progress" & VBCrLf
logFile.Write "--------------------------------" & VBCrLf

'Stop Printer Service
WshShell.popup "Stopping Spooler Service" , 1 , "", 0
Set objCmd = WshShell.Exec("Net Stop Spooler")
Wscript.sleep 6000

'Rename the three HP dll files
fileName = "HPTcpMon.dll"
	path = "C:\WINDOWS\system32\"	
	If FSO.fileexists(path & fileName) then
		logFile.Write "System32 File Found and renamed" & VBCrLf
		FSO.movefile path & fileName, path & filename & ".old"
	Else
		logFile.Write "System32 File NOT Found!!!!!!!!!!" & VBCrLf
	End If

	path = "C:\Program Files\Hewlett-Packard\HP Install Network Printer Wizard\portmon\nt40tcp\local\"
	If FSO.fileexists(path & fileName) then
		logFile.Write "nt40tcp File Found and renamed" & VBCrLf
		FSO.movefile path & fileName, path & filename & ".old"
	Else
		logFile.Write "nt40tcp File NOT Found!!!!!!!!!!" & VBCrLf
	End If

	path = "C:\Program Files\Hewlett-Packard\HP Install Network Printer Wizard\portmon\win9xtcp\local\"
	If FSO.fileexists(path & fileName) then
		logFile.Write "nt40tcp File Found and renamed" & VBCrLf
		FSO.movefile path & fileName, path & filename & ".old"
	Else
		logFile.Write "win9xtcp File NOT Found!!!!!!!!!!" & VBCrLf
	End If

'Delete the Registry Folder
	path = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\HP Standard TCP/IP Port"
	logFile.Write "Attempted Removing HP Registry Key"
	WshShell.RegDelete path & "\"

	
'Start Spooler Service
WshShell.popup "Starting Spooler Service" , 1 , "", 0
Set objCmd = WshShell.Exec("Net Start Spooler")

Set FSo = nothing
Set logFile = nothing

The early bird gets the worm, but the second mouse gets the cheese.
 
Seems that you have to delete the subkeys first ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks, that was the problem.

The early bird gets the worm, but the second mouse gets the cheese.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top