刷新 Windows 缓存

huangapple go评论78阅读模式
英文:

How to refresh Windows Cache

问题

安装我们的应用程序将添加一个新的系统环境变量。版本号将根据安装的套件而变化。例如,一个套件的版本号为10.0.0.1,而另一个套件的版本号将为10.0.0.2,依此类推。

考虑我正在在第一个套件的基础上安装第二个套件(第一个套件的版本为10.0.0.1),在系统环境变量中,我可以看到正确的值为10.0.0.2。此外,如果我导航到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment,我可以看到环境变量具有正确的版本。

如果我在命令窗口中键入echo %MYKITPATH%,它也会正确地显示为'C:\Program Files(x86)\MYKIT\10.0.0.2'。然而,如果我键入%MYKITPATH%以导航到路径,它会打开旧版本的路径'C:\Program Files(x86)\MYKIT\10.0.0.1'。

我尝试了以下操作来刷新环境变量,但仍然没有解决问题。
即使我尝试获取环境变量,它也指向较新的版本。只有在开始窗口中,如果我尝试使用环境变量导航到路径,才会出现问题。如果我打开运行窗口(Windows+R),它可以正确导航。从资源管理器中,它也可以正确导航。问题仅出现在开始窗口中。
这不是在所有计算机上都发生。如果出现了这种情况,唯一的解决方法就是重新启动计算机。

因此,我猜刷新环境变量并不是问题的原因,某种方式,Windows 在某个地方缓存了旧值。这就是为什么资源管理器正常工作,问题仅出现在开始窗口的原因。

Environment.SetEnvironmentVariable("MYKITPATH", installedPath, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("MYKITPATH", installedPath, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable("MYKITPATH", installedPath, EnvironmentVariableTarget.Machine);

变量名称:MYKITPATH
变量值:C:\Program Files(x86)\MYKIT\10.0.0.2

英文:

Installing our application will add a new system environmental variable. The version number will vary depending upon the kit installed. Say for example one kit has 10.0.0.1 means the other kit will have 10.0.0.2 and so on.

Consider I am installing the 2nd kit on top of 1st kit (which has the version 10.0.0.1), in the system environmental variable I could see the correct value of 10.0.0.2. Also if I navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment, I could see the environment variable is having correct version.

If I type echo %MYKITPATH% in command window also it is correctly giving as 'C:\Program Files(x86)\MYKIT\10.0.0.2'. However if I type %MYKITPATH% to navigate to the path, it is opening the path of older version 'C:\Program Files(x86)\MYKIT\10.0.0.1'.

I tried to do the following to refresh the ENV variable, still it didn't solve the problem.
Even if I try to get the enviroment variable, it points to the newer version. Only in the start window, if i try to navigate to the path using environmental variable, having the problem. If i open the run window (Windows+R), it is navigating correctly. From explorer, it is navigating correctly. It's just with the start window I am having the problem
This is not happening in all the machines. If it happens, the only way to work around is to reboot the machine.

So I guess refreshing environment variable is not the problem here, somehow windows is caching the old values somewhere. That's why explorer.exe works and problem is with only start window.

Environment.SetEnvironmentVariable("MYKITPATH", installedPath, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("MYKITPATH", installedPath, EnvironmentVariableTarget.User);
Environment.SetEnvironmentVariable("MYKITPATH", installedPath, EnvironmentVariableTarget.Machine);


Variable name: MYKITPATH
Variable value: C:\Program Files(x86)\MYKIT.0.0.2

答案1

得分: 1

Broadcast WM_SETTINGCHANGE to all top-level windows with lParam of "Environment".

Reference: https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange

Note that the "cache" is not Windows-wide, it is the process environment block in each independent running process, and each process must include logic to handle WM_SETTINGCHANGE (which is non-trivial, most applications won't do so, but the Windows shell which handles the start menu textbox, does)

Although since you say Windows Explorer sees the new value, I suspect this broadcast has already been done for you by .NET.

英文:

Broadcast WM_SETTINGCHANGE to all top-level windows with lParam of "Environment".

Reference: https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-settingchange

Note that the "cache" is not Windows-wide, it is the process environment block in each independent running process, and each process must include logic to handle WM_SETTINGCHANGE (which is non-trivial, most applications won't do so, but the Windows shell which handles the start menu textbox, does)

Although since you say Windows Explorer sees the new value, I suspect this broadcast has already been done for you by .NET

答案2

得分: -1

看起来环境变量MYKITPATH仍指向旧版本的MYKIT。
你可以尝试按照以下步骤更新环境变量以指向正确路径:

  1. 打开“开始”菜单并搜索“环境变量”。
  2. 点击“编辑系统环境变量”。
  3. 点击“环境变量”按钮。
  4. 在“系统变量”下,找到变量“MYKITPATH”。
  5. 将变量值更新为正确路径:“C:\Program Files(x86)\MYKIT\10.0.0.2”。
  6. 点击“确定”关闭所有窗口。
  7. 重新启动命令窗口,然后重试。
    这应该确保MYKITPATH指向正确路径,可以导航到正确的目录。

另外;
根据您的描述,似乎问题出在开始菜单快捷方式没有识别到更新的环境变量。在这种情况下,您可以尝试删除旧的快捷方式并创建一个新的快捷方式。
要删除旧的快捷方式:

  1. 右键单击不起作用的开始菜单快捷方式。
  2. 选择“从开始中取消固定”。
  3. 按Windows键打开开始菜单。
  4. 右键单击应用程序,选择“更多” -> “应用程序设置”。
  5. 滚动到“高级选项”部分,点击“重置”。
  6. 这将删除应用程序数据和设置,包括旧的快捷方式。
    要创建带有更新环境变量的新快捷方式:
  7. 按Windows键,输入应用程序名称。
  8. 右键单击应用程序,选择“打开文件位置”。
  9. 右键单击应用程序可执行文件,选择“创建快捷方式”。
  10. 右键单击新的快捷方式,选择“属性”。
  11. 在“目标”字段中,添加更新的环境变量。
  12. 点击“应用”和“确定”。
    现在,尝试从新快捷方式启动应用程序,应该识别到更新的环境变量。

另外,
听起来问题可能与开始菜单加载不正常有关。您可以尝试将开始菜单重置为默认状态,看看是否解决了问题。这是操作步骤:

  1. 右键单击开始菜单图标,选择“Windows PowerShell(管理员)”。
  2. 输入以下命令并按Enter键:Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  3. 等待命令完成(可能需要几分钟)。
  4. 关闭PowerShell并重新启动计算机。
    这应该重置开始菜单,并希望解决任何加载不正常的问题。

"所以我猜刷新环境变量不是问题,某种方式Windows在某处缓存了旧值。这就是为什么explorer.exe有效,问题只出现在开始菜单窗口上。"

嗯,可能的。这也可能是开始菜单的权限问题,阻止其访问和显示更新的环境变量。我们可以尝试将开始菜单重置为默认状态,看看是否解决问题。
要做到这一点,我们需要再次打开PowerShell并运行以下命令:

Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}

这个命令将重新注册Windows中的所有默认应用程序,并将开始菜单重置为默认设置。一旦命令运行完成,请注销您的帐户然后重新登录,查看问题是否已解决。

英文:

It seems like the environment variable MYKITPATH is still pointing to the older version of MYKIT.
You can try updating the environment variable to point to the correct path by following these steps:

  1. Open the Start menu and search for "Environment Variables"
  2. Click on "Edit the system environment variables"
  3. Click on the "Environment Variables" button
  4. Under "System Variables", locate the variable "MYKITPATH"
  5. Update the variable value to the correct path: "C:\Program Files(x86)\MYKIT\10.0.0.2"
  6. Click "OK" to close all windows
  7. Restart the command window and try again
    This should ensure that MYKITPATH points to the correct path and navigation to the correct
    directory should be possible.

Also;
Based on your description, it seems like the issue is with the Start Menu shortcut not picking up the
updated environment variable. In this case, you could try deleting the old shortcut and creating a
new one.
To delete the old shortcut:

  1. Right-click on the Start Menu shortcut that is not working.
  2. Select "Unpin from Start".
  3. Press the Windows key to open the Start Menu.
  4. Right-click on the application and select "More" -> "App settings".
  5. Scroll down to the "Advanced Options" section and click on "Reset".
  6. This will remove the app data and settings, including the old shortcut.
    To create a new shortcut with the updated environment variable:
  7. Press the Windows key and type the name of the application.
  8. Right-click on the application and select "Open file location".
  9. Right-click on the application executable and select "Create shortcut".
  10. Right-click on the new shortcut and select "Properties".
  11. In the "Target" field, add the updated environment variable.
  12. Click "Apply" and "OK".
    Now, try launching the application from the new shortcut and it should pick up the updated
    environment variable.
    Also,
    It sounds like the problem may be related to the start menu not loading properly. You could try
    resetting the start menu to its default state to see if that resolves the issue. Here's how:
  13. Right-click on the Start menu icon and select "Windows PowerShell (Admin)"
  14. Type the following command and press Enter: Get-AppXPackage -AllUsers | Foreach
    {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
  15. Wait for the command to complete (this may take a few minutes)
  16. Close PowerShell and restart your computer
    This should reset the start menu and hopefully resolve any issues with it not loading properly.

"So I guess refreshing environment variable is not the problem here, somehow windows is caching the old values somewhere. That's why explorer.exe works and problem is with only start window."

Hmm, that's possible. It could also be a permissions issue with the Start menu, preventing it from
accessing and displaying the updated environment variables. We can try resetting the Start menu to
see if that resolves the issue.
To do this, we'll need to open PowerShell again and run the following command:

Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register
"$($_.InstallLocation)\AppXManifest.xml"}

This command will re-register all the default apps in Windows and reset the Start menu to its default
settings. Once the command has finished running, log out of your account and log back in to see if
the issue has been resolved.

huangapple
  • 本文由 发表于 2023年6月15日 00:09:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76475576.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定