Jump to content

Login script for cleaning up partitions sought


Recommended Posts

Hi,

I'd like to use some sort of login script for a Windows PE (Win7PE SE) doing this:

  • detect all existing drives (read-write), c:, d:, e: ..., x: (default PE ramdrive)
  • check each drive on root for a specific folder, i.e. RECYCLER / $Recycle.bin
  • delete each match

I thought of executing this script each time the PE is booted. I don't know what's best for it; probably a cmd/batch script...?

I know, that the desired action could be done using something like rd /q/s c:\RECYCLER and so forth, but it should execute well for several systems (some having merely c:, x:; another one with c:, d:, e:, f:, v:, x: etc.).

My first idea was to use e.g. diskpart to get a list of available (NTFS) volumes and corresponding drive letters.

Dunno how to script this, though.

Any suggestions on this? :unsure:

Greetings,

Mikka

Edited by Mikka
Link to comment
Share on other sites


Okay, I've written a basic script (still alpha) that works for Windows XP and Windows 7. I still have to test it within my PE project.

Instead of diskpart I used wmic (need to verify this for my Win7PESE build as well) to get the relevant NTFS drives.

Here's what I've got so far:

@echo off
REM Need to loop through all available NTFS volumes, excluding volume X: (on any system)
For /f "skip=3" %%i In ('wmic logicaldisk where "filesystem='ntfs'" get Name^') Do If Not "%%i"=="X:" (
For %%t In ($RECYCLE.BIN RECYCLER "System Volume Information") Do (
If Exist %%~di\%%t Rd /q/s %%~di\%%t
)
)

Little problem: If I omit "skip=3" (which might be skip=2 in your case), the script will try twice to delete matches on C:—don't know why.

Any CMD guru reading along who could comment on this (Yzöwl maybe)? ;)

Cheers,

Mikka

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