Jump to content

Retrieving data in a FOR loop for a batch file


Recommended Posts

Hello, I'd like to create a script that drops a file in the startup dir of each profile located on the computer.

So far it's working pretty good, except for the profile that has space in its name. Exemple: Default User

Here is what I got so far:

REM Drops all profile name in a temporary file

dir "%_rootProfile%" /a:d /b > %SystemDrive%\_Profile.txt

REM Read the file, line by line, then verifies if if "ALL USERS", in that case we do nothing. Then verifies if Profile name is valid (We don't want to drop in System Dir: Exemple: NetworkService). If the 2 condition are ok, drops the scripts in the startup dir.

for /f %%f in (c:\_Profile.txt) do (

if not %%f=="All Users" (

if exist "%_rootProfile%\%%f\%_startupDir%" (

COPY "%_AppPath%\SetOfficeName.vbs" "%_rootProfile%\%%f\%_startupDir%")))

Works great except when %%f = Default instead of "Default User"

Any help is appreciated.

Thanks

Link to comment
Share on other sites


Now having another problem, i want to use the var defined in the fisrt loop to define a new var for the root of all profile

<snip>COPY "%_AppPath%\SetOfficeName.vbs" "%PD_%\%%?\%_startupDir%" /Y</snip>

In the COPY, still uses the %SYSTEMDRIVE% and it seems that the command COPY doesn't like it...

Link to comment
Share on other sites

The variable shouldn't really be affecting the copy command, but to make it a little less complicated:

The first for loop only gives you the location %PD_%. What you should do from there is move to that location. The second loop then could then have the "%PD_%" removed and the copy would then just state

COPY "%_AppPath%\SetOfficeName.vbs" "%%?\%_startupDir%"

The location then being relative to the current one.

Attached is an example with 'less complicated' code!

ProfDir2.cmd

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