Jump to content

batch file help


Recommended Posts

i wonder if you could help me with this batch file. The issue i am having is i want the file to delete itself after it has preformed its function. I have been able to do this before but i can no longer get it working.

@echo off

SET D=%SYSTEMROOT%\system32\
REM delete oeminfo.ini if exists
IF EXIST "%D%oeminfo.ini" DEL "%D%oeminfo.ini" /q
FOR %%d IN (c: d: e: f: g: h: i: j: k: l: m: n: o: p: q: r: s: t: u: v: w: x: y: z:) DO IF EXIST %%d\WIN51IP SET CDROM=%%d


echo [General] >> "%D%oeminfo.ini"
echo Manufacturer=Unattended Windows Install >> "%D%oeminfo.ini"
echo Model=" Version: (09.18.07)" >> "%C%oeminfo.ini"
echo [Support Information] >> "%D%oeminfo.ini"
echo Line1=Installation Date: %date% >> "%D%oeminfo.ini"
echo Line2= >> "%D%oeminfo.ini"
echo Line3=Slipstreamed Hotfixes:>> "%D%oeminfo.ini"
echo Line4= >> "%D%oeminfo.ini"

REM Line Number
SET i=5

REM List slipstreamed fixes
For /F "TOKENS=1 delims=.CA_" %%j in ( 'dir /B %CDROM%\I386\svcpack\KB*.CA_' )do ( ( set kbname=%%j ) & (call :myprint) )
For /F "TOKENS=1 delims=.CA_" %%j in ( 'dir /B %CDROM%\I386\svcpack\IE7*.CA_' )do ( ( set kbname=%%j ) & (call :myprint) )
For /F "TOKENS=1 delims=.CA_" %%j in ( 'dir /B %CDROM%\I386\svcpack\WMP11*.CA_' )do ( ( set kbname=%%j ) & (call :myprint) )
GOTO :NEXT

:myprint
echo Line%i%=%kbname% >> "%D%oeminfo.ini"
SET /A i+=1

:NEXT

DEL /F "%UserProfile%\Desktop\Cleanup.cmd"

Edited by Yzöwl
Link to comment
Share on other sites


The answer you are looking for is

@ECHO OFF&SETLOCAL ENABLEEXTENSIONS
SET "d=%SYSTEMROOT%\SYSTEM32\oeminfo.ini"
FOR /F %%? IN ('MOUNTVOL^|FIND ":\"^|FIND /V "A:\"') DO (
IF EXIST %%?WIN51IP SET "CDSPDIR=%%?I386\SVCPACK")
IF NOT DEFINED CDSPDIR GOTO ENDIT
>"%d%" (ECHO/[General]
ECHO/Manufacturer=Unattended Windows Install
ECHO/Model=" Version: (18.09.07)"
ECHO/[Support Information]
ECHO/Line1=Installation Date: %DATE%
ECHO/Line2=
ECHO/Line3=Slipstreamed Hotfixes:
ECHO/Line4=)
SET n=4
PUSHD %CDSPDIR%
FOR /F "DELIMS=" %%? IN ('DIR/B/A-D *.CA_^|FINDSTR/IB "KB IE7 WMP11"') DO (
CALL :ADDIT %%~n?)
POPD&GOTO ENDIT
:ADDIT
SET/A n+=1
>>"%d%" ECHO/Line%n%=%1
GOTO :EOF
:ENDIT
ENDLOCAL&DEL %0

I haven't tested it, but I'm fairly sure it should work for you.

Link to comment
Share on other sites

Maybe stupid question :blushing: , but does the file resides in %UserProfile%\Desktop\ ?

Personally I would use "%~dpnx0"

Other possibility, it is a timing problem of some kind. :unsure:

If this is the case, you may want to try a loop similar to the one detailed here:

http://www.catch22.net/tuts/selfdel.asp

BTW, you seem to be missing a GOTO :EOF to return from the calls in FOR loops. :blink:

jaclaz

EDIT: Sorry Yzöwl, cross-posting.

Edited by jaclaz
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...