Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA"(ByVal pidl As Integer, ByVal pszPath As String) As Integer
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Integer, ByVal nFolder As Integer, ByRef pidl As ITEMIDLIST) As Integer Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA"(ByVal nBufferLength As Integer, ByVal lpBuffer As String) As Integer
Private Structure ITEMID Dim cb As Integer Dim abID As Byte End Structure
Private Structure ITEMIDLIST Dim mkid As ITEMID End Structure
Const V_NETZWERKUMGEBUNG As Short = &H12s Const R_NETZWERKUMGEBUNG As Short = &H13s Const R_NETHOOD As Short = 19 Const R_NEW_SHELL As Short = &H15s Const R_TEMP_INTERNET As Short = &H20s
Const NOERROR As Short = 0
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load Dim Result As Integer Dim Buff As String Label1.Text = GetPath(R_NETHOOD)
'Buff = Space(20) & Chr$(0) 'Result = GetTempPath(Len(Buff), Buff) 'Label1.Caption = Trim$(Buff) End Sub
Private Function GetPath(ByRef Num As Integer) As String Dim Result As Integer Dim Buff As String Dim test As String Dim idl As ITEMIDLIST
Result = SHGetSpecialFolderLocation(Me.Handle.ToInt32, Num, idl) If Result = NOERROR Then Buff = Space(512) Result = SHGetPathFromIDList(idl.mkid.cb, Buff) If Result Then GetPath = Trim(Buff) End If test = Dir(GetPath & "\GA", FileAttribute.Volume)
分類:[.NET]
2004/02/02(Mon) 21:52:40 編集(投稿者)
vb.netでGetFolderPathを使いNETHOODの下にあるWebFolderのパスを取得し、
ファイルをコピーしようとしています。
しかし、このGetFolderPathではWebFolderのパスが取得できませんでした。
そこで、http://www.activevb.de/tipps/vb6tipps/tipp0061.htmlを
使ってみましたが、結果は同じでした。
何か、方法を知っている方がいらっしゃいましたら、教えていただけますでしょうか。
下記は、上記のURLから真似して作ったソースです。
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA"(ByVal pidl As Integer, ByVal pszPath As String) As Integer
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Integer, ByVal nFolder As Integer, ByRef pidl As ITEMIDLIST) As Integer
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA"(ByVal nBufferLength As Integer, ByVal lpBuffer As String) As Integer
Private Structure ITEMID
Dim cb As Integer
Dim abID As Byte
End Structure
Private Structure ITEMIDLIST
Dim mkid As ITEMID
End Structure
Const V_NETZWERKUMGEBUNG As Short = &H12s
Const R_NETZWERKUMGEBUNG As Short = &H13s
Const R_NETHOOD As Short = 19
Const R_NEW_SHELL As Short = &H15s
Const R_TEMP_INTERNET As Short = &H20s
Const NOERROR As Short = 0
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim Result As Integer
Dim Buff As String
Label1.Text = GetPath(R_NETHOOD)
'Buff = Space(20) & Chr$(0)
'Result = GetTempPath(Len(Buff), Buff)
'Label1.Caption = Trim$(Buff)
End Sub
Private Function GetPath(ByRef Num As Integer) As String
Dim Result As Integer
Dim Buff As String
Dim test As String
Dim idl As ITEMIDLIST
Result = SHGetSpecialFolderLocation(Me.Handle.ToInt32, Num, idl)
If Result = NOERROR Then
Buff = Space(512)
Result = SHGetPathFromIDList(idl.mkid.cb, Buff)
If Result Then GetPath = Trim(Buff)
End If
test = Dir(GetPath & "\GA", FileAttribute.Volume)
Label1.Text = CStr(Result)
End Function