Jump to content

Easy Renaming Hotfix files to KBXXXXXX.exe


Recommended Posts

Hello,

I have not posted much, but I have enjoyed all the information about making unattended Windows CD's here.

I was annoyed at renaming the KBXXXXXX.exe files to update my svpack.inf file

I wrote a little perl script to auto rename files once you download them. I know most of you

already probably had a solution to this. I am just starting perl so if you find any better to the solutions or suggestions

feel free to comment. Hope this may help some one.

kypumper

#!C:\PERL -w
############################################################################
#### Written by kypumper feel free to modify or comment ####################
#### email suggestions to kyumper+msfn@gmail.com ###########################
############################################################################
$i=0,

#############################################################################
### uncomment the chdir function if you want to specify a dir where you hotfix files are located otherwise run this ###
### script in the same dir as your hotfix files. ############
#############################################################################
#chdir ("New Ones") || die "cannot change dir: ($!)";
@oldfiles = glob "Windows*.*";


##############################################################################
### This Loop matches files that match "KB and have digits that follow" ######
### then extracts just that part of the filename so the oldfiles array can ##
### be renamed with the newfiles array. ######################################
##############################################################################
foreach (@oldfiles) {
$_ =~ /(KB[\d]+)/;
$newfiles[$i] = "$1.exe";

##### Testing to see if file exists ########
if (-e $newfiles[$i]) {
warn "Can't rename $oldfiles[$i] to $newfiles[$i] exists \n"; }


##### Renaming File and printing a success indication ###########
elsif (rename $oldfiles[$i], $newfiles[$i]) {
print "Renaming $oldfiles[$i] to $newfiles[$i] \n";
}

##### Warning if program cannot rename files ######
else { warn "rename $oldfiles[$i] to $newfiles[$i] failed: ($!) \n";
}


### Increments thru the arrays ######
$i++;
### End of foreach loop #############
}


#### Warns if No Files were parsed ############
$match=@newfiles;
if ($match < 1) {
print"No Files Matched to parse! \n";
}

Link to comment
Share on other sites


I have never used a perl script but here a VBS script that will rename the KB

Save As ReNameKB.vbs

On Error Resume Next 
Const OverwriteExisting = True
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
'/-> If You Are Running The Script In The Same Folder
Dim Folder : Set Folder = Fso.GetFolder(Fso.GetParentFolderName(WScript.ScriptFullName))
'/-> If You Want To Add A Full Path Comment Out The Above And Use Below In Between The Quotes
'Dim Folder : Set Folder = Fso.GetFolder("PLACE_A_FULL_PATH_HERE_TO_THE_FOLDER_WHERE_THE_KB_ARE_LOCATED")
Dim File : Set File = Folder.Files
Dim Rn1,StrF
'/-> CHECK AND REMOVE LONNGNAMES FROM UPDATES
For Each StrF In File
If InStr(StrF.Path,"KB") Or InStr(StrF.Path,"Kb") Or InStr(StrF.Path,"kb") Then
If InStr(StrF.Name,"-") Then
Rn1 = Split(StrF.Name,"-")
Fso.CopyFile(StrF.Name),(Rn1(1) & ".exe"),OverwriteExisting
Fso.DeleteFile(StrF.Path)
End If
End If
Next

Edited by gunsmokingman
Link to comment
Share on other sites

that script you wrote is much shorter than mine.

I can update my script to automaticaaly generate the svcpack.inf file also

if anyone would be interested.

Edited by KYPUMPER
Link to comment
Share on other sites

Well before it gets even more complicated, here's a batch file version.

@ECHO OFF
SETLOCAL
FOR /F "DELIMS=" %%? IN ('DIR/B/A-D *KB*.EXE') DO CALL :GI_ %%?
GOTO :EOF
:GI_
SET "N_=%1"
:LP_
SET "N_=%N_:*-=%"
ECHO/%N_%|FINDSTR/I "KB[0-9]*">NUL||GOTO LP_
SET "N_=%N_:~0,8%.exe"
IF NOT EXIST %N_% REN %1 %N_%
GOTO :EOF

Link to comment
Share on other sites

Well before it gets even more complicated, here's a batch file version.
@ECHO OFF
SETLOCAL
FOR /F "DELIMS=" %%? IN ('DIR/B/A-D *KB*.EXE') DO CALL :GI_ %%?
GOTO :EOF
:GI_
SET "N_=%1"
:LP_
SET "N_=%N_:*-=%"
ECHO/%N_%|FINDSTR/I "KB[0-9]*">NUL||GOTO LP_
SET "N_=%N_:~0,8%.exe"
IF NOT EXIST %N_% REN %1 %N_%
GOTO :EOF

B)
Link to comment
Share on other sites

Here is a VBS Script I wrote because I was bored it will Rename the KB in any folder on the computer.

Since this is a WMI VBS Script it can be ran across networks to Rename the Updates.

To Run this against a Network Computer

Change This

Dim StrC :StrC = "."

To This

Dim StrC :StrC = "A_IP_ADDRESS_OR_COMPUTERNAME_ON_THE_NETWORK"

Save As RenameKB_V1.vbs

Const OverwriteExisting = True 
Dim StrC :StrC = "."
Dim Wmi :Set Wmi = GetObject("winmgmts:\\" & strC & "\root\cimv2")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim File, KB1, KB2, KB3, StrF
Set File = Wmi.ExecQuery(_
"Select * from CIM_DataFile WHERE FileName LIKE 'WindowsXP-KB%%%%%%' And Extension = 'exe'")
For Each StrF In File
Set KB1 = Fso.GetFile(StrF.Name)
KB2 = Split(KB1.Name,"-")
KB3 = Fso.GetParentFolderName(KB1.Path) & "\" & KB2(1) & ".exe"
Fso.CopyFile(KB1.Path),(KB3),OverwriteExisting
Next

This one I added a message box that will report either no files where Renamed or how many where Renamed.

Save As RenameKB_V2.vbs

Const OverwriteExisting = True 
Dim StrC :StrC = "."
Dim Wmi :Set Wmi = GetObject("winmgmts:\\" & strC & "\root\cimv2")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim File, KB1, KB2, KB3, StrF
Set File = Wmi.ExecQuery(_
"Select * from CIM_DataFile WHERE FileName LIKE 'WindowsXP-KB%%%%%%' And Extension = 'exe'")
For Each StrF In File
Set KB1 = Fso.GetFile(StrF.Name)
KB2 = Split(KB1.Name,"-")
KB3 = Fso.GetParentFolderName(KB1.Path) & "\" & KB2(1) & ".exe"
Fso.CopyFile(KB1.Path),(KB3),OverwriteExisting
Next
If File.Count = 0 Then
Act.Popup "There Where No Updates Found To Rename",9,"No Updates",4128
Else
Act.Popup "Completed Rename Of Updates" & vbCrLf & _
"This Many Updates where Rename : " & File.Count,9,"Rename KB",4128
End If

Yzöwl nice batch file :thumbup

Link to comment
Share on other sites

Thanks.

There is of course a small mistake in it, more to do with input checking than anything else, but I couldn't be bothered changing it.

Why...

Because I wanted to have the 'smallest looking script' on offer without concatenating lines, and that change would have made it look a little bit longer!

Link to comment
Share on other sites

Yzöwl, I ran into some issues with it the other day. First off, it doesn't behave nicely with hotfixes named IE7-WindowsXP-KBxxx. I ended up a file named WindowsX.exe. Second, is it possible the code you posted doesn't always handle multiple EXEs properly? I ran it in a dir with 5 or 6 hotfixes in it and it properly renamed the first EXE just fine, but it didn't touch the rest.

Basically, I've adapted your code with some code to go through a directory and expand all the hotfixes after renaming them, so I can run the batch file in a directory of standard as-downloaded EXEs and be left with a nice directory of KBxxxxxx folders instead :)

Link to comment
Share on other sites

You are intent on me making this thing bigger aren't you?

I will take a look at improving this thing as soon as I get a little time.

As far as the multiple EXEs go, there shouldn't be a problem, my initial test, (singular), seemed okay, but there was no 'real' testing done on it. I'll give the tidied version a go first and test it a little before reposting it here.

Link to comment
Share on other sites

Yzöwl, I ran into some issues with it the other day. First off, it doesn't behave nicely with hotfixes named IE7-WindowsXP-KBxxx. I ended up a file named WindowsX.exe. Second, is it possible the code you posted doesn't always handle multiple EXEs properly? I ran it in a dir with 5 or 6 hotfixes in it and it properly renamed the first EXE just fine, but it didn't touch the rest.

Basically, I've adapted your code with some code to go through a directory and expand all the hotfixes after renaming them, so I can run the batch file in a directory of standard as-downloaded EXEs and be left with a nice directory of KBxxxxxx folders instead :)

Try this script it should work, it will Rename any updates on any drive or folder on the local computer.

This can be run from your desktop.

Const OverwriteExisting = True 
Dim StrC :StrC = "."
Dim Wmi :Set Wmi = GetObject("winmgmts:\\" & strC & "\root\cimv2")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim File, KB1, KB2, KB3, StrF
Set File = Wmi.ExecQuery(_
"Select * from CIM_DataFile WHERE FileName LIKE '%-KB%%%%%%' And Extension = 'exe'")
For Each StrF In File
Set KB1 = Fso.GetFile(StrF.Name)
KB2 = Split(KB1.Name,"-")
KB3 = Fso.GetParentFolderName(KB1.Path) & "\" & KB2(1) & ".exe"
Fso.CopyFile(KB1.Path),(KB3),OverwriteExisting
Next
If File.Count = 0 Then
Act.Popup "There Where No Updates Found To Rename",9,"No Updates",4128
Else
Act.Popup "Completed Rename Of Updates" & vbCrLf & _
"This Many Updates where Rename : " & File.Count,9,"Rename KB",4128
End If

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...