获取Windows下载文件夹的路径 [英] Get the Windows Download folder's path

查看:519
本文介绍了获取Windows下载文件夹的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些Excel VBA代码,需要了解下载文件夹路径。我可以怎么做?

I have some Excel VBA code that requires knowing the Downloads folder path. How could I do it?

由于您可以移动下载文件夹(以及文档和大部分那些文件夹,通过文件夹属性),环境变量,如%USERPROFILE%是无用的构造一个路径,如%USERPROFILE%\Downloads WScript.Shell.SpecialFolders 不列出下载文件夹。

Since you can move around the Downloads folder (and also Documents and most of those folders, via the folder properties), the environmental variables like %USERPROFILE% are useless to construct a path like %USERPROFILE%\Downloads, and WScript.Shell.SpecialFolders doesn't list the Downloads folder.

我想它必须要完成阅读注册表,但是我对此无所作为。

I guess it has to be done reading the registry, but I'm clueless about that.

谢谢!

推荐答案

找到答案google一点点...

Found the answer google a little more...

读取注册表的方式是,as根据 http://vba-corner.livejournal.com/3054.html

The way to read the registry is, as per http://vba-corner.livejournal.com/3054.html:

'reads the value for the registry key i_RegKey
'if the key cannot be found, the return value is ""
Function RegKeyRead(i_RegKey As String) As String
Dim myWS As Object

  On Error Resume Next
  'access Windows scripting
  Set myWS = CreateObject("WScript.Shell")
  'read key from registry
  RegKeyRead = myWS.RegRead(i_RegKey)
End Function

GUID为下载文件夹,根据MSDN的 http://msdn.microsoft.com/en-us/library/windows/desktop/dd378457(v = vs85).aspx

And the GUID for the Downloads folder, as per MSDN's http://msdn.microsoft.com/en-us/library/windows/desktop/dd378457(v=vs.85).aspx:

{374DE290-123F-4565-9164-39C4925E467B}

因此 RegKeyRead HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\ {374DE290-123F-4565-9164-39C4925E467B})产生当前用户的下载文件夹路径。

Thus RegKeyRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\{374DE290-123F-4565-9164-39C4925E467B}") yields the current user's Downloads folder path.

这篇关于获取Windows下载文件夹的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆