2015-10-06 86 views
0

我個人對此問題的關注是因爲我創建了一個動態桌面程序,其目的是讓用戶單擊桌面上的文件夾,並將該文件夾的內容變爲新桌面。 (我將在下面發佈代碼作爲答案,以免讓我的實際問題變得複雜)。但是,部分代碼需要終止並重新啓動explorer.exe進程,才能重新初始化桌面以顯示新位置。通過dll桌面刷新

這個問題的文檔很難找到,因爲它比大多數人願意爲這個特定領域所採用的技術更具技術性。 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的命令,並且桌面的功能,其中i的假定後來到USER32.DLL依賴性已發現多種用途被用於更新在某種形式的桌面。如果你想查看這個,download dependency walker並從程序中打開它到這個文件夾。 (C:\的Windows \ WinSxS文件\ Amd64_microsoft窗口-user32_31bf3856ad364e35_6.3.9600.18123_none_be367a2e4123fd9d \ USER32.DLL)

+0

我認爲你正在尋找的術語是「shell擴展」,但我不確定是否可以覆蓋任何類型的桌面文件夾的默認行爲(打開)。 – Filburt

+1

'如果我能找到在註冊表編輯器中傳遞了什麼變量'是什麼讓您認爲註冊表與打開桌面上的文件夾有關? –

+0

我可能會做一個廉價的修復,一旦資源管理器打開文件,有一個腳本複製該路徑,並在關閉Windows資源管理器時在其周圍重新創建vbs文件。 至於我「假設」它與註冊表有關,有一些explorer.exe在註冊表中被調用的實例,這是用於在程序中可視化移動的同一個可執行文件。如果你願意,我可以告訴你這些我感興趣的實例和這個話題。 – Jouster500

回答

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資源管理器將自行重新啓動,以重新初始化新的桌面位置。

直到我可以得到一個工作模型,我必須做的是點擊/與文件夾進行初始化程序的交互,本手冊將不得不做。

+0

我不知道是否有反正,而不是打開一個文件夾與資源管理器,我可以用vbs腳本打開它與參數0 =文件夾點擊,所以也許我需要做什麼來禁用Windows資源管理器? – Jouster500