桌面刷新通过DLL

时间:2015-10-06 22:56:59

标签: windows batch-file dll vbscript registry

我个人对此问题的关注是因为我正在创建一个动态桌面程序,其目的是让用户单击桌面上的文件夹,该文件夹的内容将成为新桌面。 (我将在下面发布代码作为答案,以便不回答我的实际问题)。但是,部分代码需要终止并重新启动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窗口-user32_31bf3856ad364e35_6.3.9600.18123_none_be367a2e4123fd9d \ user32.dll中)

1 个答案:

答案 0 :(得分:0)

这是通过批处理和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资源管理器将重新启动以重新初始化新桌面位置。

直到我能够获得一个工作模型,我只需单击/与文件夹交互以初始化程序,本手册就必须这样做。