【问题标题】:Desktop Refresh via dll通过 dll 刷新桌面
【发布时间】:2015-10-06 22:56:59
【问题描述】:

我个人对此问题的担忧是因为我正在创建一个动态桌面程序,其目的是让用户单击桌面上的文件夹,该文件夹的内容成为新桌面。 (我将在下面发布代码作为答案,以免混淆我的实际问题)。但是,部分代码需要终止并重新启动 explorer.exe 进程,以便重新初始化桌面以显示新位置。

很难找到这个问题的文档,因为它比大多数人愿意为这个特定领域去研究的技术要多。 This man is trying to do the exact same thing as me except using autoithere users looked more into doing it vbscript side 但都得出了相同的结果,即杀死并重新启动 explorer.exe 以更新桌面。

我以强行方式终止explorer.exe 进程的问题可能导致系统不稳定,并且实际终止该进程需要更长的时间来重新启动桌面,而不是when you simply move the desktop location 发生的任何操作。我想知道如何通过调用更新它的 dll 来更新我的桌面,但是从批处理和 vbscript 混合中。

编辑:

rundll32.exe user32.dll,LockWorkStation 等命令的调查以及后来对 user32.dll 依赖项的调查发现了桌面功能的多种用途,我假设这些功能用于以某种形式更新桌面。如果您想查看此内容,请download dependency walker 并从程序中将其打开到此文件夹。 (C:\Windows\WinSxS\amd64_microsoft-windows-user32_31bf3856ad364e35_6.3.9600.18123_none_be367a2e4123fd9d\user32.dll)

【问题讨论】:

  • 我认为您正在寻找的术语是“shell 扩展”,但我不确定是否可以覆盖任何类型的桌面文件夹的默认行为(打开)。
  • If I can find what variable is being passed within the registry editor 是什么让您认为注册表与在桌面上打开文件夹有什么关系?
  • 在大多数 Windows 版本中(至少到 8.1,我还没有使用 10),桌面只是一个对 Windows shell(AKA Explorer)具有特殊意义的文件夹。它与注册表的唯一关系是该位置存储在那里。有特定的 API 调用用于检索该文件夹的位置,但据我所知,没有一个允许通过代码更改它。 (FWIW,我认为这是一个可怕的想法,特别是如果它不是用于您自己的个人 PC 的。就像物理桌面一样,您可以(并且应该)从 Windows 桌面拾取(拖放)文件并移动它们。)
  • (续)。如果您想动态地更改内容,只需通过脚本将文件从现有桌面文件夹移动到另一个文件夹,然后(通过脚本)将文件从另一个文件夹移动到现有桌面文件夹。瞧 - 桌面内容被替换,而不会乱用注册表,也不会冒损坏您(或其他人)操作系统的风险。
  • 不知道如何在 vbs 中执行此操作,但您可以制作一个使用 SetWindowsHookEx() 挂钩 WH_CALLWNDPROCRET 事件的 c/c++ 应用程序。然后通过检查 WM_CREATE 消息来侦听 explorer.exe 进程中新创建的窗口。最后,调用 GetWindowText() 获取名称。

标签: windows batch-file dll vbscript registry


【解决方案1】:

这里是通过批处理和 vbs 混合手动更改桌面。它并不完美,但它在移入和移出目录以选择要更新到的目录之间提供了一个很好的界面。 这使用了我想用其他东西贬值的taskkill。

这是初始批处理脚本...

    @echo off
setlocal enableextensions
  ::Below computes the desktop location that the program will reference  
for /f %%a in ('cscript //nologo C:\HighestPrivelege\DesktopTools\findDesktop.vbs') do set "fold=%%a"
echo %fold%

::this loop will allow users to input new locations for the desktop by 
moving through a terminal. Wildcards and autotab completion is usable are 
and lack of input results in continuation of script
:loop
echo ################## %fold%
dir %fold% /A:D /B
echo _________________________
set loc=
set /p loc=[New Location?]
cd %fold%\%loc%
set fold=%cd%

IF [%loc%]==[] (goto cont) ELSE (goto loop)
:cont

::Below is the program that runs the regedit rewrite of the desktop variable 
for the current user. It passes the decided folder value from earlier as the 
new desktop.

cscript //nologo C:\HighestPrivelege\DesktopTools\setdesktop.vbs %fold%

::This restarts explorer.exe in order to reboot the newly created desktop 
location. I wish i didnt have to kill explorer.exe forcefully in the process 
but so far its the only way to make this program work.

taskkill /F /IM explorer.exe
explorer.exe
endlocal
pause
exit

以及随后的 VBS 脚本...

Option Explicit
'variable invocation
Dim objShell, strDesktop, strModify, strDelete, fso, f, File, content, parthe, args, arg1
Set args = WScript.Arguments
set objShell = CreateObject("WScript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")
'this will take in the new desktop location.
set file= fso.OpenTextFile("C:\HighestPrivelege\DesktopTemporary.txt")
content = file.ReadAll
arg1 = args.Item(0)
parthe = ""&arg1&""
'The actual rewrite of the registry file containing the script lies below.
strDesktop = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Desktop"
strModify = objShell.RegWrite(strDesktop,parthe,"REG_EXPAND_SZ")

激活批处理脚本将提示用户他们希望将桌面重定位到的位置,并将该变量传递到 VBscript 以重写到注册表。 VBScript 完成后,Windows 资源管理器将自行重启以重新初始化新的桌面位置。

在我得到一个工作模型之前,我所要做的就是单击/与文件夹交互以初始化程序,这本手册将不得不做。

【讨论】:

  • 我想知道是否有任何方法可以用 vbs 脚本打开它,而不是用资源管理器打开一个文件夹,参数 0=单击的文件夹,所以也许我需要做些什么来禁用 Windows探险家?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-27
  • 1970-01-01
  • 2012-06-25
  • 1970-01-01
  • 2016-07-02
  • 1970-01-01
相关资源
最近更新 更多