我正在尝试在vb中创建一个快速链接组合框。但我似乎无法打开图片,音乐,视频&下载文件夹。
我试过Shell("explorer %HOMEPATH%/pictures", AppWinStyle.NormalFocus)
但那只是打开文档文件夹,Any help?
答案 0 :(得分:0)
你去......
'Open Pictures folder
Process.Start(My.Computer.FileSystem.SpecialDirectories.MyPictures)
'Open Music folder
Process.Start(My.Computer.FileSystem.SpecialDirectories.MyMusic)
'Open Videos folder
Dim strVideosPath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyVideos)
Process.Start(strVideosPath)
'Open Downloads folder
Dim strDownloadsPath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) & "\Downloads"
Process.Start(strDownloadsPath)
答案 1 :(得分:0)
如果你想可靠地获取下载文件夹(可能有不同的名称来自"下载",特别是在Windows的不同语言版本中,以及不是即使在"用户配置文件")的同一个驱动器上,您也需要询问shell32它在哪里:
Imports System.Runtime.InteropServices
Imports System.Text
Public Class OtherSpecialFolder
' Documentation of Common HRESULT Values:
' https://msdn.microsoft.com/en-us/library/windows/desktop/aa378137%28v=vs.85%29.aspx
Const S_OK As Integer = 0
Const E_FAIL As Integer = &H80004005
Const E_INVALIDARG As Integer = &H80070057
<DllImport("shell32.dll", CharSet:=CharSet.Auto)>
Private Shared Function SHGetKnownFolderPath(ByRef id As Guid, flags As Integer, token As IntPtr, ByRef path As StringBuilder) As Integer
' Documentation of SHGetKnownFolderPath function:
' https://msdn.microsoft.com/en-us/library/windows/desktop/bb762188%28v=vs.85%29.aspx
End Function
Public Shared Function GetDownloadsFolder() As String
' Known folder GUIDs at:
' https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457%28v=vs.85%29.aspx
Dim FOLDERID_Downloads As Guid = New Guid("374DE290-123F-4565-9164-39C4925E467B")
Dim sb As New StringBuilder
Dim hresult As Integer = SHGetKnownFolderPath(FOLDERID_Downloads, 0, IntPtr.Zero, sb)
Select Case hresult
Case S_OK
Return sb.ToString()
Case E_FAIL
Throw New ArgumentException(String.Format("KNOWNFOLDERID GUID {0} (Downloads) does not have a path.", FOLDERID_Downloads))
Case E_INVALIDARG
Throw New ArgumentException(String.Format("Known folder with GUID {0} (Downloads) is not present on the system.", FOLDERID_Downloads))
Case Else
Throw New Exception(String.Format("GetDownloadsFolder function failed, unexpected HRESULT = 0x{0:X}.", hresult))
End Select
End Function
End Class
SHGetKnownFolderPath函数可能仅在Windows Vista及更高版本中可用。
用法:
Dim downloadsFolder As String = OtherSpecialFolder.GetDownloadsFolder()