Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Batch script for windows & software updates installation

  • Please log in to reply
52 replies to this topic



    Just simple

  • Member
  • PipPipPipPipPipPipPip
  • 1,689 posts
  • Joined 02-August 04
  • OS:Windows 7 x64
  • Country: Country Flag

I have figured out there are two lines that it writes to the files %variable%.txt  So when %variable%=%computername%.txt the resultant file would be Computername.txt.txt

The program is writing correctly now, but all that displays is the screen showing what has/has not installed. It appears stalled and I see no progress. Is there a way we can see what is installing as it is being installed? 

I doubt the corrections you made are fixing anything. Seems you misunderstand the operation of what the script is doing. The delimited file of Computername.txt.txt is not a mistake, but rather deliberate with adding a 2nd extension on the original filename to create another filename for use. Example: Computername.txt is created with initial information. The information is used and changes are recorded to Computername.txt.txt. At the end of the script, Computername.txt.txt is moved over to overwrite Computername.txt. This is done as the script can not read and write to the same file with out messing it up. So Computername.txt.txt is actually a temporary file that later replaces the original file named Computername.txt. Perhaps I could have made a temporary filename more unique though I chose for an easy method.
I could summarize the script though you may not be able to link what words to what code. I will rather comment the code more and so that you can see what each line of code is doing. I included the pause at the end of the script and the progress output like how Yzöwl mentioned.

Heavier commented code:



Edit: Upon review and to avoid further confusion with the .txt and .txt.txt use of file handling, I have done a small change by using .txt and .txt.tmp as the later has a better reference to actually being a temporary file.

Edited by MHz, 21 February 2015 - 08:43 PM.

How to remove advertisement from MSFN




  • Member
  • 14 posts
  • Joined 17-October 14
  • OS:XP Pro x86
  • Country: Country Flag

hi,Yzowl. I am a newbe here..your code is awesome :thumbup thanks a lot.
But I just got a little problem,when I tested this batch by choosing "run as administrator"(windows7 x64) in a folder with all MSU and EXE update files, .bat processed and listed them,
but in fact none of them was actuelly installed. Then I tried to add "cd /d %~dp0" to change the path at the beginning before your code, and it worked finally.
But in your code these is already "FOR /R "%~dp0" %%A IN (*-KB*.MSU) DO (" , looks like this parte doesn't work for me, I dont understand why, could you please explain?
PS: your second code for .exe file updating woks well.

That is correct.

Do bear in mind that WUSA.EXE is located within %PATH% as is SHUTDOWN.EXE and that executables located within the path do not require their path prepending to the command. You have done so with one and not the other, whilst both are correct it seems pointless to include that which isn't required.
You can also simplify lines 2 & 3 by merging them into one thus

FOR /R "%~dp0" %%A IN (*-KB*.MSU) DO (
	CALL :SUB %%~nA
	ECHO= Installing KB!KB_NUM!
	WUSA "%%A" /quiet /norestart)
ECHO= == Press any key to restart ==

FOR /F "DELIMS=-" %%B IN ("%KB_NUM:*-KB=%") DO SET "KB_NUM=%%B"


Hello how can i change the script not to restart after it finish and just close/exit the script??

Edited by dimitris77, 25 June 2015 - 01:13 PM.




  • Patrons
  • 4,716 posts
  • Joined 14-September 05
  • OS:none specified
  • Country: Country Flag

:crazy: Change it to the following or just delete the line.

"REM" makes it a Comment line. The characters "::" instead of "REM" work the same way.


*HOWEVER* I wouldn't recommend that since there will be Pending Actions that will *NOT* occur until you Reboot.

Someday the tyrants will be unthroned... Jason "Jay" Chasteen; RIP, bro!

Posted Image

2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users