|
-
Dec 23rd, 2010, 12:35 PM
#1
Thread Starter
New Member
Need Help With VBS Script
hi, I have a VBS script here that allows me to search, and delete any registry entry with a specified keyword in it.
At the end, it displays a message box, saying it finished, and how long it took to finish (Finished in "" minutes").
I want it to create a text file "finished.txt" instead of displaying this message.
How can I do this?
Code:
' Script that will do a substring search in all key names
' for the string in the variable sKey and delete the key
' if the string is found.
'
' You can set a key path in the variable sStartKeyPathx if
' you want to limit the search to a specific registry branch.
' Adjust callouts to sStartKeyPath1/2/3 as you see fit
Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Const OverwriteIfExist = -1
sStartKeyPath1 = "HKEY_CURRENT_USER"
sStartKeyPath2 = "HKEY_LOCAL_MACHINE"
sStartKeyPath3 = "HKEY_USERS"
sKey = "tomkey"
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
' get a temporary registry file name
sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName
sStart = Now
ExportRegistry sStartKeyPath1, sTempFile
CreateAndRunRegistryFile sKey, sTempFile
ExportRegistry sStartKeyPath2, sTempFile
CreateAndRunRegistryFile sKey, sTempFile
ExportRegistry sStartKeyPath3, sTempFile
CreateAndRunRegistryFile sKey, sTempFile
' delete temp file
If oFSO.FileExists(sTempFile) Then
oFSO.DeleteFile sTempFile
End If
MsgBox "Finished in " & DateDiff("n", sStart, Now) & " minutes", _
vbSystemModal, "SearchAndDelete"
Sub ExportRegistry(sStartKey, sFile)
If Trim(sKey) = "" Then
' export the complete registry
sCmd = "regedit.exe /S /E:A """ & sFile & """"
Else
' export the registry key to a file
sCmd = "regedit.exe /S /E:A """ & sFile & """ " & """" & sStartKey & """"
End If
oShell.Run sCmd, 0, True
End Sub
Sub CreateAndRunRegistryFile(sString, sInFile)
sOutFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName
' find all string starting with [ and ends with ], and that
' also contains at least one bachslash in addition to the
' text in the variable sString
sCmd = "%comspec% /c findstr.exe " _
& "/i /r ""^\[.*\\.*" & sString & ".*\]$"" """ _
& sInFile & """ >""" & sOutFile & """"
oShell.Run sCmd, 0, True
Set fFile = oFSO.OpenTextFile(sOutFile, ForReading, _
FailIfNotExist, OpenAsASCII)
sResult = ""
On Error Resume Next
sResult = fFile.ReadAll
fFile.Close
oFSO.DeleteFile sOutFile
On Error Goto 0
If sResult <> "" Then
Set fRegFile = oFSO.CreateTextFile(sOutFile, _
OverwriteIfExist, OpenAsASCII)
fRegFile.WriteLine "REGEDIT4" & vbCrLf
aResult = Split(sResult, vbCrLf)
For i = 0 To UBound(aResult)
sLine = aResult(i)
' do the same tests as the regexp in findstr just in case.
If InStr(1, sLine, sString, vbTextCompare) > 0 _
And Left(sLine, 1) = "[" And Right(sLine, 1) = "]" Then
sLine = "[-" & Mid(sLine, 2)
fRegFile.WriteLine sLine
End If
Next
fRegFile.WriteLine vbCrLf ' add two blank lines at the end
fRegFile.Close
sCmd = "regedit.exe /s """ & sOutFile & """"
oShell.Run sCmd, 0, True
End If
If oFSO.FileExists(sOutFile) Then
oFSO.DeleteFile sOutFile
End If
End Sub
-
Dec 23rd, 2010, 12:51 PM
#2
Re: Need Help With VBS Script
Thread moved from 'VB.Net' forum to 'ASP, VBScript' forum
-
Dec 24th, 2010, 07:42 AM
#3
Addicted Member
Re: Need Help With VBS Script
 Originally Posted by tommo020788
I want it to create a text file "finished.txt" instead of displaying this message.
Call the FSO CreateTextFile method.
-
Dec 24th, 2010, 07:58 AM
#4
Thread Starter
New Member
Re: Need Help With VBS Script
 Originally Posted by His Nibbs
Call the FSO CreateTextFile method.
Could you elaborate on how this would be achieved?
Maybe copy/paste my code, and impliment the method you are talking about, into the code, then copy/paste it back into a reply message?
Cheers
Tom
-
Dec 25th, 2010, 12:27 PM
#5
Re: Need Help With VBS Script
 Originally Posted by tommo020788
Could you elaborate on how this would be achieved?
Maybe copy/paste my code, and impliment the method you are talking about, into the code, then copy/paste it back into a reply message?
Cheers
Tom
Hi... Welcome to the forums...
Check this : http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|