Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Retrieving data in a FOR loop for a batch file

Featured Replies

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

The quickfix for your problem is likely changing

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

to

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

Take a look at the attached batch file, and run it to see what it does, it may help!

ProfDirs.cmd

  • Author

Wow! How complicated is that batch file! Works great! I'll adjust it to use it in my script.

Thanks!

Its not very complicated at all, its only 5 lines and took about 3 minutes to create. Since your question was about 'FOR loops', I just decided to use two of them!

  • Author

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

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

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.