Jump to content

Help with batch command


Recommended Posts

Hi there all,

It has been many years since i had to write anything serious in a batch file and for the life of my can't remember the right syntax for what i am tring to do - if you can help me out i would appreciate it. :yes:

I want to search the \documents and settings for certain folder (user profile) names for example

FOR %%p IN  (%userprofilesdir%) DO IF EXIST %%p\xyx | %%p\xyz SET theprofile=%%p

echo %theprofile%

Once i get a true, i want to then do some copying of stuff to these specific profiles.

Cheers,

Felix

Link to comment
Share on other sites


Ok i worked it out myself but for those of you that are interested here is my solution.

@echo off

:check
cd %allusersprofile%
cd ..
set userprofilesdir=%cd%
FOR %%d IN ("%userprofilesdir%") DO IF NOT EXIST %%d\xyz* GOTO false

cls
echo it is here
goto end

:false
cls
echo not here
goto end

:end

Now you may be wondering why I was looking for this solution? - I have had need to do some unattended installs to system that have had a copy of windows on them already prevously and I automatically delete the \windows directory during the isntallation, however the nice thing is that the documents and settings folder is left intact.

Now what happens is that after you install and logon as one of the same users that was previously configured before the upgrade, you end up with a user profile folder for example: \documents and settings\xyz.domain\ becasue the folder \documents and settings\xyz\ already existed.

This is fine and of course all of user XYZ's configuration (\documents and settings\xyz\)is intact, but it is in the wrong folder... so with the above script, I can search to see if it is there and then have some commands to copy the original settings etc to the new location, or better still change the registery to point to the original location. :w00t:

Stay tuned for a step by step guide to do this whole thing. Oh and why would i want to upgrade system that is already installed with Windows XP? Well from experience and more recently with SP2 updates - the system can become very bloated and or unstable. A clean installation is my preference everytime.

let me know your thoughts on this... and if you have any ideas to contribute - feel free. :yes:

Felix

Link to comment
Share on other sites

Nice job. I do something similar in my unattended, but it is only for Default, and all users that I do. I get around this with variables.%ALLUSERSPROFILE% will return for all users, and I set up the %DEFAULTUSERPROFILE% during setup for the default. Then I will extract the files to the proper locations, rather than store them in folders in my $DOCS folder. Saves a lot of headaches.

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...