• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

Malware Infected - Need scritping help.

We were recenlty hit with a new variant of the Delf worm that hid and renamed all .exe and .ico files and replaces the original with a copy of itself.  The malware hides the original file and renames it by placing a lowercase letter "g" in front of the original filename. I need a script that renames and unhides the original files and runs windows system file checker. Kaspersky has created an update which now catches the worm, but doesn't repair the damage.
0
IPSBadmin
Asked:
IPSBadmin
  • 6
1 Solution
 
IPSBadminAuthor Commented:
So far I figured out I can list the files with dir /S /A:H /B g*.exe > outputfile.txt
Which gives me the output c:\folder\gfile.exe. How do I rename them without the "g" in front?

Also I found an executable unhide.exe (part of combofix) that will unhide the files in question that I run after renaming them.
0
 
IPSBadminAuthor Commented:
Here's what I came up with... if anyone is interested.

Make sure you set bDebug to False ... unless you need a whole lot of info (and clicking).

 
'==============================================================================
' LANG		: VBScript 
' NAME		: Delf.wl.CleanupTool 
' VERSION	: 1.0 2011-10-10
' Description	:Script to search for hidden and renamed files caused by 
'				Delf.wl infection
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'==============================================================================
Option Explicit

' Variable Declarations
Dim bDEBUG
Dim WshShell
Dim ObjFSO
Dim LogExists

' Constants Declarations
Const WAIT_ON_RETURN = True
Const DO_NOT_WAIT_ON_RETURN = False
Const HIDE_WINDOW = 0
Const SHOW_WINDOW = 1
Const THIS_COMPUTER = "."
Const FOR_READING = 1
Const FOR_WRITING = 2
Const FOR_APPENDING = 8
Const EXE = "g*.exe"		'All executables that start with "g"
Const ICO = "g*.ico"		'All icon files that start with "g"
Const HIDDEN_EXE_LOG_FILE = "_HiddenExecLogFile.txt"		'Location of Hidden Exec Log File
Const HIDDEN_ICO_LOG_FILE = "_HiddenIcoLogFile.txt"		'Location of Hidden Ico Log File

' Set Variable Intial Values
bDEBUG=false		'Set to TRUE to help with script debugging.
'==============================================================================
' Main Routine
On Error Resume Next
If bDEBUG then On Error Goto 0

' Create system objects
Set WshShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
LogExists = 0

' Call the functions
Call GetFixedDrives
Call CheckForLogFiles(HIDDEN_EXE_LOG_FILE, LogExists)
If bDEBUG then wscript.echo "DEBUG: Returned from Check for log file: """ &HIDDEN_EXE_LOG_FILE &"""."
Call CheckForLogFiles(HIDDEN_ICO_LOG_FILE, LogExists)
If bDEBUG then wscript.echo "DEBUG: Returned from Check for log file: """ &HIDDEN_ICO_LOG_FILE &"""."

If LogExists = 1 Then
	Wscript.echo "Computer has already been scanned.  To scan this computer again remove logfiles: " & HIDDEN_EXE_LOG_FILE &" & " & HIDDEN_ICO_LOG_FILE
else
	Call ScanForHiddenFiles(EXE,HIDDEN_EXE_LOG_FILE)
	Call ScanForHiddenFiles(ICO,HIDDEN_ICO_LOG_FILE)
	Call RenameHiddenFiles(HIDDEN_EXE_LOG_FILE)
	Call RenameHiddenFiles(HIDDEN_ICO_LOG_FILE)
End If



' Clean up objects and exit
Set WshShell = Nothing

wscript.quit

'=====================================================================================
'SubRoutine GetFixedDrives
'		This routine Scans for Drives
'	INPUTS: none
'	OUTPUT: Names of fixed hard drives
'	ASSUMES: 
'	NOTES: This funtion returns fixed hard drive letters
'======================================================================================
Sub GetFixedDrives
	If bDEBUG then wscript.echo "DEBUG: Entered GetFixedDrives Function"
	Dim objFso
	Dim objFile
	Dim strFile
	Dim objTextFile
	Dim drives
	Dim drive
	Const ForReading = 1
	Const ForWriting = 2
	Const ForAppending = 8
	
	strFile = "C:\Drives.txt"
	If bDEBUG then wscript.echo "DEBUG: " &strFile
	Set objFso = CreateObject("Scripting.FileSystemObject")
	If (objFso.FileExists(strFile)) Then
		If bDEBUG then wscript.echo "DEBUG: Drive.txt already exists"
	Else
		Set objFile = objFso.CreateTextFile(strFile)
		Set objFile = nothing 'Releases Text File for Opening
		Set objTextFile = objFso.OpenTextFile(strFile, ForAppending, True) 'Opens text file for appending
		
		Set drives = objFso.Drives ' Creates a Drive Array
		For Each drive in drives
			if drive.DriveType = 2 then objTextFile.WriteLine(drive.path) 'Writes to text file each fixed hard drive
		Next
		objTextFile.Close 'Closes Text File
	End If
	If bDEBUG then wscript.echo "DEBUG: Leaving GetFixedDrives Sub"
End Sub

'=====================================================================================
'SubRoutine CheckForLogFiles
'		This routine Scans for hidden executable files that start with "g"
'	INPUTS: LogFileLocation
'	OUTPUT: LogExists
'	ASSUMES: nothing 
'	NOTES: This funtion check for the presence of log files.      
'======================================================================================
Private Sub CheckForLogFiles(LogFileLocation, LogExists)
' Variable Declarations
	Dim ObjFso
	Dim strDriveTextFile
	Dim drives
	Dim DrvLetter
	Dim objTextFile

	' Constants Declarations
	Const ForReading = 1
	
	' Set Variable Intial Values
	strDriveTextFile = "C:\Drives.txt"
	Set ObjFso = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFso.OpenTextFile(strDriveTextFile, ForReading) 'Opens text file for Reading
	DrvLetter = ""
	
	Do until objTextFile.atEndOfStream 
		DrvLetter = objTextFile.readLine
		If (ObjFso.FileExists(DrvLetter &"\" &LogFileLocation)) Then
			LogExists = 1
			If bDEBUG then wscript.echo "DEBUG: LogFile """ &DrvLetter &"\" &LogFileLocation & """ already exists."
		Else
			LogExists = 0
			If bDEBUG then wscript.echo "DEBUG: LogFile """ &DrvLetter &"\" &LogFileLocation & """ does not exist."
		End If
	loop
	objTextFile.close
End Sub


'=====================================================================================
'SubRoutine ScanForHiddenFiles
'		This routine Scans for hidden executable files that start with "g"
'	INPUTS: HiddenExecLogFile
'	OUTPUT: Logs Hidden files
'	ASSUMES: The existence of the WshShell, objFSO, 
'	NOTES: This funtion creates a log file of hidden executables that start with "g".      
'======================================================================================
Function ScanForHiddenFiles(FileType,LogLocation)
	
	' Variable Declarations
'	Dim WshShell
	Dim ObjFso
	Dim strScanCommand
	Dim ComCommand
	Dim drives
	Dim DrvLetter
	Dim objTextFile
	Dim strDriveTextFile
	
	' Constants Declarations
	Const ForReading = 1
	Const ForWriting = 2
	Const ForAppending = 8
	
	' Set Variable Intial Values
'	Set WshShell = WScript.CreateObject("WScript.Shell")
	Set objFso = CreateObject("Scripting.FileSystemObject")
	strDriveTextFile = "C:\Drives.txt"
	strScanCommand = "dir /S /B /A:H"	'Recursive Search for Hidden Files, Bare Output
	
	If bDEBUG then wscript.echo "DEBUG: Scanning for hidden files with " & FileType
	
'	On Error Resume Next
'	If bDEBUG then wscript.echo "DEBUG: Returned from GetFixedDrives Function. Location of Text File: " &strDriveTextFile
	Set objTextFile = objFso.OpenTextFile(strDriveTextFile, ForReading) 'Opens text file for Reading
	DrvLetter = ""
	Do until objTextFile.atEndOfStream 
		DrvLetter = objTextFile.readLine
		If bDEBUG then wscript.echo "DEBUG: Drive Letter is: " &DrvLetter
		' Run Command
		ComCommand = "%comspec% /c " &" " &DrvLetter &" & cd \ & " &strScanCommand &" " &FileType &" >> " &DrvLetter &"\" &LogLocation

		If bDEBUG then wscript.echo "DEBUG: Running Command: " &ComCommand
		WshShell.Run(ComCommand &",1,True")
	loop
	objTextFile.close
	If bDEBUG Then On Error Goto 0
End Function

'=====================================================================================
'SubRoutine RenameHiddenFiles
'		This routine unhides and renames files foung in ScanForHiddenFiles
'	INPUTS:	LogFileLocation
'	OUTPUT:	Renames files
'	ASSUMES:	The existence of the c:\Drives.txt 
'	NOTES: 	This funtion unhides files made hidden and system and renames
'			them minus the "g"      
'======================================================================================
Function RenameHiddenFiles(LogFileLocation)
	If bDEBUG then wscript.echo "DEBUG: Entering RenameHiddenFiles Function."
	' Variable Declarations
	Dim ObjFSO
	Dim strDriveTextFile
	Dim drives
	Dim DrvLetter
	Dim objDriveTextFile
	Dim objLogTextFile
	Dim strFiletoRename
	Dim strFileWithoutPath
	
	' Constants Declarations
	Const ForReading = 1
	
	' Set Variable Intial Values
	strDriveTextFile = "C:\Drives.txt"
	Set ObjFso = CreateObject("Scripting.FileSystemObject")
	Set objDriveTextFile = objFso.OpenTextFile(strDriveTextFile, ForReading) 'Opens text file for Reading
	DrvLetter = ""
	strFileWithoutPath = ""
	
	Do until objDriveTextFile.atEndOfStream 
		DrvLetter = objDriveTextFile.readLine
		If (ObjFso.FileExists(DrvLetter &"\" &LogFileLocation)) Then
			Set objLogTextFile = objFso.OpenTextFile(DrvLetter &"\" &LogFileLocation, ForReading) 'Opens text file for Reading
			If bDEBUG then wscript.echo "DEBUG: Opening hidden files log file: " &DrvLetter &"\" &LogFileLocation
			Do until objLogTextFile.atEndOfStream
				strFiletoRename = objLogTextFile.readLine
				If bDEBUG then wscript.echo "DEBUG: Renaming file: " &strFiletoRename
				RenameTo strFiletoRename, strFileWithoutPath
				If bDEBUG then wscript.echo "DEBUG: strFileWithoutPath =" &strFileWithoutPath
				Call UnhideFile(strFiletoRename)
				NewFileName strFileWithoutPath
				If bDEBUG then wscript.echo "DEBUG: Returning from NewFileName Function with strFileWithoutPath = : " &strFileWithoutPath
				Call RenameFile (strFiletoRename, strFileWithoutPath)
			loop
		End If
	loop
End Function

Function RenameTo(FileToRename, strFileWithoutPath)
	
	Dim arrFileName
	Dim arrFileArray
	Dim x
	
	arrFileName = FileToRename
	
	arrFileArray = Split (arrFileName, "\", -1, 1)
	x = UBound (arrFileArray)
	strFileWithoutPath = arrFileArray(x)
	If bDEBUG then wscript.echo "DEBUG: Returning from RenameTo Function with value: " &strFileWithoutPath
	
End Function

Function UnhideFile(strFiletoRename)
	Dim ComspecCommand
	
	ComspecCommand = "%comspec% /c  ATTRIB -S -H " &chr(34) &strFiletoRename &chr(34)
	If bDEBUG then wscript.echo "DEBUG: Unhiding file: " &ComspecCommand
	WshShell.Run(ComspecCommand)
	Set ComspecCommand = Nothing
	
End Function

Function NewFileName(strFileWithoutPath)
	
	Dim LengthOfFileName
	
	LengthOfFileName = Len(strFileWithoutPath)
	If bDEBUG then wscript.echo "DEBUG: Length of FileName = " &LengthOfFileName
	LengthOfFileName = LengthOfFileName - 1
	strFileWithoutPath = Right(strFileWithoutPath, LengthOfFileName)
	
End Function

Function RenameFile(strFiletoRename, strFileWithoutPath)
	
	Dim ObjFSO
	Dim objFile
	Dim strFilePathOnly
	Dim ComspecCommand
	
	Set ObjFso = CreateObject("Scripting.FileSystemObject")
	
	strFilePathOnly = Left(strFiletoRename,(Len(strFiletoRename) - (Len(strFileWithoutPath) + 1)))
	If bDEBUG then wscript.echo "DEBUG: File Path to file to be renames is: " &strFileWithoutPath

	If (ObjFso.FileExists(strFilePathOnly &strFileWithoutPath)) then
		set objFile = objFSO.GetFile(strFilePathOnly &strFileWithoutPath)
		If bDEBUG then wscript.echo "DEBUG: File to be renamed already exists: " &objFile
		If objFile.Size = 0 then
			objFile.DeleteFile
			If bDEBUG then wscript.echo "DEBUG: " &objFile &" deleted."
			wscript.echo "DEBUG: " &objFile &" deleted."
		End If
	End If
	
	ComspecCommand = "%comspec% /c rename " &chr(34) &strFiletoRename &chr(34) &" " &strFileWithoutPath
	If bDEBUG then wscript.echo "DEBUG: RenameFile Function: " &ComspecCommand
	WshShell.Run(ComspecCommand)
	
End Function

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
IPSBadminAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for IPSBadmin's comment http:/Q_27383941.html#36956315

for the following reason:

No Help...
0
 
IPSBadminAuthor Commented:
Had to add a timer to wait for the log files to build.  The rest of the script was trying to proceed without the logs.
'==============================================================================
' LANG		: VBScript 
' NAME		: Delf.wl.CleanupTool 
' VERSION	: 1.0 2011-10-10
' Description	:Script to search for hidden and renamed files caused by 
'				Delf.wl infection
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'==============================================================================
Option Explicit

' Variable Declarations
Dim bDEBUG
Dim WshShell
Dim ObjFSO
Dim LogExists

' Constants Declarations
Const WAIT_ON_RETURN = True
Const DO_NOT_WAIT_ON_RETURN = False
Const HIDE_WINDOW = 0
Const SHOW_WINDOW = 1
Const THIS_COMPUTER = "."
Const FOR_READING = 1
Const FOR_WRITING = 2
Const FOR_APPENDING = 8
Const EXE = "g*.exe"		'All executables that start with "g"
Const ICO = "g*.ico"		'All icon files that start with "g"
Const HIDDEN_EXE_LOG_FILE = "_HiddenExecLogFile.txt"		'Location of Hidden Exec Log File
Const HIDDEN_ICO_LOG_FILE = "_HiddenIcoLogFile.txt"		'Location of Hidden Ico Log File

' Set Variable Intial Values
bDEBUG=false		'Set to TRUE to help with script debugging.
'==============================================================================
' Main Routine
On Error Resume Next
If bDEBUG then On Error Goto 0

' Create system objects
Set WshShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
LogExists = 0

' Call the functions
Call GetFixedDrives
Call CheckForLogFiles(HIDDEN_EXE_LOG_FILE, LogExists)
If bDEBUG then wscript.echo "DEBUG: Returned from Check for log file: """ &HIDDEN_EXE_LOG_FILE &"""."
Call CheckForLogFiles(HIDDEN_ICO_LOG_FILE, LogExists)
If bDEBUG then wscript.echo "DEBUG: Returned from Check for log file: """ &HIDDEN_ICO_LOG_FILE &"""."

If LogExists = 1 Then
	Wscript.echo "Computer has already been scanned.  To scan this computer again remove logfiles: " & HIDDEN_EXE_LOG_FILE &" & " & HIDDEN_ICO_LOG_FILE
else
	Call ScanForHiddenFiles(EXE,HIDDEN_EXE_LOG_FILE)
	Call ScanForHiddenFiles(ICO,HIDDEN_ICO_LOG_FILE)
	Call RenameHiddenFiles(HIDDEN_EXE_LOG_FILE)
	Call RenameHiddenFiles(HIDDEN_ICO_LOG_FILE)
End If



' Clean up objects and exit
Set WshShell = Nothing

wscript.quit

'=====================================================================================
'SubRoutine GetFixedDrives
'		This routine Scans for Drives
'	INPUTS: none
'	OUTPUT: Names of fixed hard drives
'	ASSUMES: 
'	NOTES: This funtion returns fixed hard drive letters
'======================================================================================
Sub GetFixedDrives
	If bDEBUG then wscript.echo "DEBUG: Entered GetFixedDrives Function"
	Dim objFso
	Dim objFile
	Dim strFile
	Dim objTextFile
	Dim drives
	Dim drive
	Const ForReading = 1
	Const ForWriting = 2
	Const ForAppending = 8
	
	strFile = "C:\Drives.txt"
	If bDEBUG then wscript.echo "DEBUG: " &strFile
	Set objFso = CreateObject("Scripting.FileSystemObject")
	If (objFso.FileExists(strFile)) Then
		If bDEBUG then wscript.echo "DEBUG: Drive.txt already exists"
	Else
		Set objFile = objFso.CreateTextFile(strFile)
		Set objFile = nothing 'Releases Text File for Opening
		Set objTextFile = objFso.OpenTextFile(strFile, ForAppending, True) 'Opens text file for appending
		
		Set drives = objFso.Drives ' Creates a Drive Array
		For Each drive in drives
			if drive.DriveType = 2 then objTextFile.WriteLine(drive.path) 'Writes to text file each fixed hard drive
		Next
		objTextFile.Close 'Closes Text File
	End If
	If bDEBUG then wscript.echo "DEBUG: Leaving GetFixedDrives Sub"
End Sub

'=====================================================================================
'SubRoutine CheckForLogFiles
'		This routine Scans for hidden executable files that start with "g"
'	INPUTS: LogFileLocation
'	OUTPUT: LogExists
'	ASSUMES: nothing 
'	NOTES: This funtion check for the presence of log files.      
'======================================================================================
Private Sub CheckForLogFiles(LogFileLocation, LogExists)
' Variable Declarations
	Dim ObjFso
	Dim strDriveTextFile
	Dim drives
	Dim DrvLetter
	Dim objTextFile

	' Constants Declarations
	Const ForReading = 1
	
	' Set Variable Intial Values
	strDriveTextFile = "C:\Drives.txt"
	Set ObjFso = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFso.OpenTextFile(strDriveTextFile, ForReading) 'Opens text file for Reading
	DrvLetter = ""
	
	Do until objTextFile.atEndOfStream 
		DrvLetter = objTextFile.readLine
		If (ObjFso.FileExists(DrvLetter &"\" &LogFileLocation)) Then
			LogExists = 1
			If bDEBUG then wscript.echo "DEBUG: LogFile """ &DrvLetter &"\" &LogFileLocation & """ already exists."
		Else
			LogExists = 0
			If bDEBUG then wscript.echo "DEBUG: LogFile """ &DrvLetter &"\" &LogFileLocation & """ does not exist."
		End If
	loop
	objTextFile.close
End Sub


'=====================================================================================
'SubRoutine ScanForHiddenFiles
'		This routine Scans for hidden executable files that start with "g"
'	INPUTS: HiddenExecLogFile
'	OUTPUT: Logs Hidden files
'	ASSUMES: The existence of the WshShell, objFSO, 
'	NOTES: This funtion creates a log file of hidden executables that start with "g".      
'======================================================================================
Function ScanForHiddenFiles(FileType,LogLocation)
	
	' Variable Declarations
'	Dim WshShell
	Dim ObjFso
	Dim strScanCommand
	Dim ComCommand
	Dim drives
	Dim DrvLetter
	Dim objTextFile
	Dim strDriveTextFile
	Dim objExec
	
	' Constants Declarations
	Const ForReading = 1
	Const ForWriting = 2
	Const ForAppending = 8
	
	' Set Variable Intial Values
'	Set WshShell = WScript.CreateObject("WScript.Shell")
	Set objFso = CreateObject("Scripting.FileSystemObject")
	strDriveTextFile = "C:\Drives.txt"
	strScanCommand = "dir /S /B /A:H"	'Recursive Search for Hidden Files, Bare Output
	
	If bDEBUG then wscript.echo "DEBUG: Scanning for hidden files with " & FileType
	
'	On Error Resume Next
'	If bDEBUG then wscript.echo "DEBUG: Returned from GetFixedDrives Function. Location of Text File: " &strDriveTextFile
	Set objTextFile = objFso.OpenTextFile(strDriveTextFile, ForReading) 'Opens text file for Reading
	DrvLetter = ""
	Do until objTextFile.atEndOfStream 
		DrvLetter = objTextFile.readLine
		If bDEBUG then wscript.echo "DEBUG: Drive Letter is: " &DrvLetter
		' Run Command
		ComCommand = "%comspec% /c " &" " &DrvLetter &" & cd \ & " &strScanCommand &" " &FileType &" >> " &DrvLetter &"\" &LogLocation

		If bDEBUG then wscript.echo "DEBUG: Running Command: " &ComCommand
		Set objExec = WshShell.Exec(ComCommand &",1,True")
		
		Do while objExec.Status = 0
			wscript.Sleep 100
		Loop
	Loop
	objTextFile.close
	If bDEBUG Then On Error Goto 0
End Function

'=====================================================================================
'SubRoutine RenameHiddenFiles
'		This routine unhides and renames files foung in ScanForHiddenFiles
'	INPUTS:	LogFileLocation
'	OUTPUT:	Renames files
'	ASSUMES:	The existence of the c:\Drives.txt 
'	NOTES: 	This funtion unhides files made hidden and system and renames
'			them minus the "g"      
'======================================================================================
Function RenameHiddenFiles(LogFileLocation)
	If bDEBUG then wscript.echo "DEBUG: Entering RenameHiddenFiles Function."
	' Variable Declarations
	Dim ObjFSO
	Dim strDriveTextFile
	Dim drives
	Dim DrvLetter
	Dim objDriveTextFile
	Dim objLogTextFile
	Dim strFiletoRename
	Dim strFileWithoutPath
	
	' Constants Declarations
	Const ForReading = 1
	
	' Set Variable Intial Values
	strDriveTextFile = "C:\Drives.txt"
	Set ObjFso = CreateObject("Scripting.FileSystemObject")
	Set objDriveTextFile = objFso.OpenTextFile(strDriveTextFile, ForReading) 'Opens text file for Reading
	DrvLetter = ""
	strFileWithoutPath = ""
	
	Do until objDriveTextFile.atEndOfStream 
		DrvLetter = objDriveTextFile.readLine
		If (ObjFso.FileExists(DrvLetter &"\" &LogFileLocation)) Then
			Set objLogTextFile = objFso.OpenTextFile(DrvLetter &"\" &LogFileLocation, ForReading) 'Opens text file for Reading
			If bDEBUG then wscript.echo "DEBUG: Opening hidden files log file: " &DrvLetter &"\" &LogFileLocation
			Do until objLogTextFile.atEndOfStream
				strFiletoRename = objLogTextFile.readLine
				If bDEBUG then wscript.echo "DEBUG: Renaming file: " &strFiletoRename
				RenameTo strFiletoRename, strFileWithoutPath
				If bDEBUG then wscript.echo "DEBUG: strFileWithoutPath =" &strFileWithoutPath
				Call UnhideFile(strFiletoRename)
				NewFileName strFileWithoutPath
				If bDEBUG then wscript.echo "DEBUG: Returning from NewFileName Function with strFileWithoutPath = : " &strFileWithoutPath
				Call RenameFile (strFiletoRename, strFileWithoutPath)
			loop
		End If
	loop
End Function

Function RenameTo(FileToRename, strFileWithoutPath)
	
	Dim arrFileName
	Dim arrFileArray
	Dim x
	
	arrFileName = FileToRename
	
	arrFileArray = Split (arrFileName, "\", -1, 1)
	x = UBound (arrFileArray)
	strFileWithoutPath = arrFileArray(x)
	If bDEBUG then wscript.echo "DEBUG: Returning from RenameTo Function with value: " &strFileWithoutPath
	
End Function

Function UnhideFile(strFiletoRename)
	Dim ComspecCommand
	
	ComspecCommand = "%comspec% /c  ATTRIB -S -H " &chr(34) &strFiletoRename &chr(34)
	If bDEBUG then wscript.echo "DEBUG: Unhiding file: " &ComspecCommand
	WshShell.Run(ComspecCommand)
	Set ComspecCommand = Nothing
	
End Function

Function NewFileName(strFileWithoutPath)
	
	Dim LengthOfFileName
	
	LengthOfFileName = Len(strFileWithoutPath)
	If bDEBUG then wscript.echo "DEBUG: Length of FileName = " &LengthOfFileName
	LengthOfFileName = LengthOfFileName - 1
	strFileWithoutPath = Right(strFileWithoutPath, LengthOfFileName)
	
End Function

Function RenameFile(strFiletoRename, strFileWithoutPath)
	
	Dim ObjFSO
	Dim objFile
	Dim strFilePathOnly
	Dim ComspecCommand
	
	Set ObjFso = CreateObject("Scripting.FileSystemObject")
	
	strFilePathOnly = Left(strFiletoRename,(Len(strFiletoRename) - (Len(strFileWithoutPath) + 1)))
	If bDEBUG then wscript.echo "DEBUG: File Path to file to be renames is: " &strFileWithoutPath

	If (ObjFso.FileExists(strFilePathOnly &strFileWithoutPath)) then
		set objFile = objFSO.GetFile(strFilePathOnly &strFileWithoutPath)
		If bDEBUG then wscript.echo "DEBUG: File to be renamed already exists: " &objFile
		If objFile.Size = 0 then
			objFile.DeleteFile
			If bDEBUG then wscript.echo "DEBUG: " &objFile &" deleted."
			wscript.echo "DEBUG: " &objFile &" deleted."
		End If
	End If
	
	ComspecCommand = "%comspec% /c rename " &chr(34) &strFiletoRename &chr(34) &" " &strFileWithoutPath
	If bDEBUG then wscript.echo "DEBUG: RenameFile Function: " &ComspecCommand
	WshShell.Run(ComspecCommand)
	
End Function

Open in new window

0
 
IPSBadminAuthor Commented:
Sorry, had to add extra info to solution
0
 
IPSBadminAuthor Commented:
No Help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now