Jump to content

Windows Scripting help!


Recommended Posts

Can somebody help me write a simple script that would run every hotfix in a directory with the /integrate: switch? I saw it posted in the forums earlier, but for the life of me I can't find the post again. Thanks again for the help

Link to comment
Share on other sites


The following command should do the trick.

For /f %i in ('DIR c:\Hotfixes\* /B') DO start /wait %i /integrate:c:\XPCD /q

Here I asume, that the Hotfixs are located in c:\Hotfixes and the CD files in c:\XPCD.

When you want to run this in a batch, you've got to use %%i instead of %i.

Link to comment
Share on other sites

  • 3 months later...

I found this post which had exactly the example I needed to get started with a batch script to automate my hotfixes. After playing around I came up with a script that can be placed anywhere on your computer allowing you to integrate all of your hotfixes located within one folder while still having other files in that folder and displays the number of files integrated.

Here's the code followed by a brief explanation of all the parts:

@echo off
set hotfix=X:\XP-CD\Hotfixes\
set xpcd=X:\XP-CD\XPSP2
set x=0
FOR /F %%i IN ('DIR %hotfix%KB*.exe /B') DO start /wait %hotfix%%%i /integrate:%xpcd% /q
FOR /F %%i IN ('DIR %hotfix%KB*.exe /B') DO set /a x=x+1
echo.
echo %x% files integrated.

Here is the explanation for the code:

@echo off

Turns off command echoing at the command prompt.

set hotfix=X:\XP-CD\Hotfixes\

Sets up an environment variable named "hotfix" representing the location of your hotfixes. Change after the equal sign to where your hotfixes are located. Notice the trailing backslash "\", this is important and must be there for the script to work!

set xpcd=X:\XP-CD\XPSP2

Sets up an environment variable named "xpcd" representing the location of your Windows source. Change after the equal sign to where your Windows source is located. Notice that there is no trailing backslash here, once again this is important, as having one there will break the script!

set x=0

Sets up an environment variable named "x" with the value of zero. This simply serves as a counter.

FOR /F %%i IN ('DIR %hotfix%KB*.exe /B') DO start /wait %hotfix%%%i /integrate:%xpcd% /q

This is the same command stated at the beginning of this post, altered for this script. It parses the DIRectory that you set earlier "%hotfix%" for any file starting with KB and ending in .exe (the asterisk is a wildcard that can represent any character in any amount) and assigns the resulting filename to variable %%i. It then executes that file "%%i" with the path "%hotfix%" tacked onto the front of the file using the integrate parameter pointing to the Windows source that you set %xpcd%. The /q executes the file silently.

FOR /F %%i IN ('DIR %hotfix%KB*.exe /B') DO set /a x=x+1

This is simply a counter. It adds 1 to the value of x for each file that it finds that matches the parsing filter.

echo.

This displays a blank line.

echo %x% files integrated.

This prints to the screen the number of files integrated using the variable x from the counter.

Hopefully a few of you will find this as useful as I have and maybe learned something in the process.

Enjoy!

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...