首页 > 解决方案 > Environment variabes - when and why

问题描述

Given Raymond Chen's description and conventional wisdom I'm curious about some observations:

First, if I'm quick and run set in a batch window on start-up (up-to-date Windows 10 Home) then I get a list of the environment variables I expect to be established.

But leave it a while and some other variables are created on further cmd instances FPS_BROWSER_APP_PROFILE_STRING and FPS_BROWSER_USER_PROFILE_STRING - apparently created by the Edge browser.

I have an initialisation batch executed by a link from the startup directory. This batch backs up some important directories and performs some other tasks. One of those tasks is to remove the icons that DROPBOX annoyingly imposes over icons zapiconoverlays:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

:: Get rid of dropbox-generated icon overlays
:: Provide a parameter to NOT restart explorer

SET "spaces=                                    "
(
ECHO Windows Registry Editor Version 5.00
ECHO/
FOR /L %%I IN (0,1,10) DO (
 FOR /L %%L IN (101,1,110) DO (
  SET /a iter=%%L
  FOR %%K IN (WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers
              Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers
             ) DO (
   ECHO [-HKEY_LOCAL_MACHINE\SOFTWARE\%%K\!spaces:~0,%%I!DropboxExt!iter:~-2!]
  )
 )
)
)>u:\zapiconoverlays.REG

regedit /s u:\zapiconoverlays.REG
del u:\zapiconoverlays.REG

SET "spaces=%~1"
SET "iter="
IF NOT DEFINED spaces CALL restartexplorer
GOTO :eof

Which I normally run without a parameter, so restartexplorer is executed:

@ECHO OFF
taskkill /f /im explorer.exe
DEL %userprofile%\AppData\Local\IconCache.db /a 2>nul
START explorer.exe

The curious thing is that variables that have been established in the local environment when restartexplorer is executed are then propagated to further cmd instances. For instance, I process the current date/time into various environment variables. If I run zapiconoverlays first thing in the initialisation batch (after a setlocal) then all runs as I expect, but if I put the zapiconoverlays call after having established the datetime variables, then the datetime variables are available in further cmd instances.

I'm looking for confirmation of my observations and possibly a rule that can be applied.

标签: batch-file

解决方案


推荐阅读