Access Violation in Cmd.exe in Long Batch Files Using "FOR /F"

This article was previously published under Q250998
This article has been archived. It is offered "as is" and will no longer be updated.
Symptoms
When you are running complex batch files for a long time (to run routine jobs, monitor services, and so on), and the batch files contain the for /f command to process files line-by-line and run commands using the line contents as parameters, you may receive "access violation" and "access denied" error messages in Cmd.exe
Cause
When you run the batch files for a long time, the reuse of memory areas by the program is more likely. In this case, the memory is not "nulled out" by the operating system. The algorithm used by Cmd.exe to extract tokens used as parameters for the command in the for /f command is vulnerable to reused memory.
Resolution

Windows 2000

To resolve this problem, obtain the latest service pack for Windows 2000. For additional information, click the following article number to view the article in theMicrosoft Knowledge Base:
260910 How to Obtain the Latest Windows 2000 Service Pack

Windows NT 4.0

A supported fix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Apply it only to computers that are experiencing this specific problem.

To resolve this problem, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information about support costs, visit the following Microsoft Web site:NOTE: In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

The English version of this fix should have the following file attributes or later:
   Date       Time     Size      File name   Platform   --------------------------------------------------   01/25/00   08:51a   208,144   Cmd.exe     x86   01/25/00   08:50a   357,648   Cmd.exe     Alpha				

Workaround
This problem is aggregated by the changes in Heap Manager introduced in Windows NT 4.0 Service Pack 4. You should be able to avoid the problem by using the workaround described in the following Microsoft Knowledge Base article:
195009 Application Access Violation or Hang After Applying SP4
Status

Windows 2000

Microsoft has confirmed that this is a problem in Windows 2000. This problem was first corrected in Windows 2000 Service Pack 1.

Windows NT 4.0

Microsoft has confirmed that this is a problem in Windows NT 4.0.
Properties

Article ID: 250998 - Last Review: 11/03/2013 00:12:00 - Revision: 3.0

  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Professional Edition
  • Microsoft Windows NT Workstation 4.0 Developer Edition
  • Microsoft Windows NT Server 4.0 Enterprise Edition
  • Microsoft Windows NT Server 4.0 Standard Edition
  • kbnosurvey kbarchive kbhotfixserver kbqfe kbbug kbfix KB250998
Feedback