CreateObject("WScript.Network")

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use the below code to get the Network Places items. However, this requires
"Late Binding". I read that you can avoid late binding by adding a reference
to the Com Types in your application. Does anyone know what reference to add
and what to import?

Dim drives() As String
Dim ob As Object = CreateObject("WScript.Network")
Dim odrives As Object = ob.EnumNetworkDrives
dim k as integer
If odrives.count > 0 Then
ReDim drives(CInt(odrives.Count / 2))
For i = 0 To odrives.Count - 1 Step 2
k = k + 1
drives(k) = odrives.Item(i + 1).ToString.ToLower
Next
End If
 
Never mind...I've got it figured out:

Imports IWshRuntimeLibrary

Dim drives() As String
Dim o As IWshNetwork2 = CType(CreateObject("WScript.Network"), IWshNetwork2)
Dim odrives As WshCollection = CType(o.EnumNetworkDrives, WshCollection)
If odrives.count > 0 Then
ReDim drives(CInt(odrives.Count / 2))
For i = 0 To odrives.Count - 1 Step 2
k = k + 1
drives(k) = odrives.Item(i + 1).ToString.ToLower
Next
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top