Share via

Error in batch file

StewartBW 1,905 Reputation points
2025-03-01T06:12:36.9966667+00:00

Hi

I have a batch code .bat which runs as admin and installs .net fw 3.5 on Win 10, but sometimes mostly on new Windows installs it won't run and will give a not found error:

CD /D "%~dp0"

DISM /Online /Enable-Feature /FeatureName:NetFX3 /All /LimitAccess /Source:"%~dp0"

The correct cab files are copied beside this .bat file:

Microsoft-Windows-NetFx3-OnDemand-Package~31bf3856ad364e35~amd64~en-US~.cab

microsoft-windows-netfx3-ondemand-package~31bf3856ad364e35~amd64~~.cab

Any idea what's wrong?

Sorry it's not PowerShell exactly, but .bat batch file which is similar.

Thanks.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2025-03-06T03:41:27.93+00:00

    Hello

    Thank you for posting in Q&A forum.

    Here are a few steps you can try to troubleshoot:

    1. Ensure that the path to the CAB files is correct and accessible. The %~dp0 variable should point to the directory where the batch file is located.
    2. Ensure that the CAB files are correctly named and located in the same directory as the batch file.
    3. Ensure that the batch file is being run with administrative privileges.
    4. Ensure that the DISM command is correctly formatted and that the source path is correct. You can try specifying the full path to the CAB files.
    5. Add logging to capture the output and errors from the DISM command for further analysis:

    DISM /Online /Enable-Feature /FeatureName:NetFX3 /All /LimitAccess /Source:"%~dp0" > dism_log.txt

    I hope the information above is helpful.

    If you have any questions or concerns, please feel free to let us know.

    Best Regards,

    Daisy Zhou

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.