Jump to content

T-12 Problem with deleting shortcuts on user account.


Recommended Posts

@echo off
cmdow @ /HID

SetLocal enableextensions
SET CDROM=%~d0

IF NOT DEFINED UserName FOR /F "tokens=3 delims=\" %%d IN ("%UserProfile%") DO SET UserName=%%d

COPY /Y "%CDROM%\$OEM$\system32\cmdow.exe" "%systemroot%\system32\"
DEL /F /Q "%systemroot%\Web\Wallpaper\*.jpg"
DEL /F /Q "%systemroot%\system32\*.scr"

DEL /F /Q "%AllUsersProfile%\Documents\My Music"
DEL /F /Q "%AllUsersProfile%\Documents\My Pictures"
RD /S /Q "%AllUsersProfile%\Documents\Recorded TV"
DEL /F /Q "%AllUsersProfile%\Start Menu\Activate Windows.lnk"
DEL /F /Q "%AllUsersProfile%\Start Menu\Set Program Access and Defaults.lnk"
DEL /F /Q "%AllUsersProfile%\Start Menu\Windows Update.lnk"
DEL /F /Q "%AllUsersProfile%\Start Menu\Programs\Accessories\System Tools\Activate Windows.lnk"

RD /S /Q "%UserProfile%\Favorites\Links"
DEL /F /Q "%UserProfile%\My Pictures\"
DEL /F /Q "%UserProfile%\Start Menu\Programs\Remote Assistance.lnk"
DEL /F /Q "%UserProfile%\Start Menu\Programs\Windows Media Player.lnk"
DEL /F /Q "%UserProfile%\Start Menu\Programs\Accessories\Windows Explorer.lnk"

DEL /F /Q "%UserProfile%\Start Menu\Programs\Outlook Express.lnk"
DEL /F /Q "%UserProfile%\Start Menu\Programs\Accessories\Address Book.lnk"

EndLocal
EXIT

The last "DEL" commands are meant to remove the outlook express and address book shortcuts.

But doesnt seem to work.

The shortcuts only appear in the Administrators account. So what is the environment variable for the administrators account?

Link to comment
Share on other sites


The last "DEL" commands are meant to remove the outlook express and address book shortcuts.

But doesnt seem to work.

Outlook express shortcut seems to be created at 1st Active Desktop logon. I use a script from HKCU RunOnce to clean up these shortcuts.

The shortcuts only appear in the Administrators account. So what is the environment variable for the administrators account?

This is no environmental variable for the Administrator's profile. The code below should do it.

%AllUsersProfile%\..\Administrator

Link to comment
Share on other sites

IF NOT DEFINED UserName FOR /F "tokens=3 delims=\" %%d IN ("%UserProfile%") DO SET UserName=%%d

Although %USERNAME% isn't used in your batch file, you could probably replace it with the following shorter code.
if not defined username for %%? in ("%userprofile%") do set username=%%~nx?

The quotes around the %userprofile% are needed just in case the username contains spaces and the x in the variable expansion just in case there is a stop in the username. It will help your code on occasions where the profile directory has been redirected to any location which is not one level below root i.e

  • drive:\parent\username (the third token would be okay)
    drive:\windows\profiles\username (the third token would be incorrect)

There may still be problems with even the improved code on some part installed systems however. If a user name has been changed, after creation of their profile folder its profile name often remains at the original thereby not holding the %username%.

COPY /Y <snip>

The /Y switch should not be required in a batch file
DEL /F /Q  "%AllUsersProfile%\Documents\My Music"
DEL /F /Q "%AllUsersProfile%\Documents\My Pictures"

You may prefer to use RD for directory removal
DEL /F /Q <snip>

The /Q switch is only used to prevent prompts with wildcards and therefore not required with single named files.

I hope this information helps!

Link to comment
Share on other sites

@ T-13/12/9 the %userprofile% doesn't exist yet.

you need a 'logged in user' to have a %userprofile%

at best, this variable would default to the "Default User' folder at these stages of installation.

the %allusersprofile% is however available.

try running your batch file by runounce or runonceex instead of T-12.

shark

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