batch-file - 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.
解决方案
推荐阅读
- excel - 如果单元格值在数组内,则返回 true,否则返回 false
- ios - twaillio 调用后所需条件为 false:format.sampleRate == hwFormat.sampleRate'
- jqgrid - 如何实现jqgrid多选工具栏
- ios - 如何在使用多个 UIPopoverPresentationController allowedArrowDirections 时将首选项设置为一个箭头方向?
- c# - 我对数据集中查询中的参数有疑问
- c - 以矩阵形式输出二维数组
- r - R在列表中的数据框中的列中提取唯一行值
- android - 使用 facebook 进行身份验证时应用 ID 无效
- c# - 从 C# 将 Python 输出发送到文件
- python - 使用 tkinter 摆脱多余的空间