GFI
English Deutsch Français Italiano Nederlands Español
Products > GFI Network Server Monitor > Scripting > WMI > Samples > Remote WMI

List all shares on local computer using credentials of currently logged on user
List all shares on local or remote computer using credentials of currently logged on user
Impersonation sample: List all shares on a remote computer using different credentials than logged on user


List all shares on local computer using credentials of currently logged on user
Option Explicit

ListShares()
WScript.Echo vbCrlf & "Ready."

Sub ListShares()
    Dim strObject
    Dim colShares
    Dim objWMIService, objShare

    Set objWMIService = GetObject( "winmgmts:" )
    Set colShares = objWMIService.ExecQuery( "Select * from Win32_Share" )
    For Each objShare In colShares
        Wscript.Echo objShare.Name & " [" & objShare.Path & "]"
    Next
End Sub


List all shares on local or remote computer using credentials of currently logged on user
Option Explicit

Dim strComputer
Do
    strComputer = inputbox( "Please enter name of a computer (or . for local host)", "Input" )
Loop until strComputer <> ""
ListShares( strComputer )
WScript.Echo vbCrlf & "Ready."

Sub ListShares( strComputer )
    Dim strObject
    Dim colShares
    Dim objWMIService, objShare

    Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
    Set colShares = objWMIService.ExecQuery( "Select * from Win32_Share" )
    For Each objShare In colShares
        Wscript.Echo objShare.Name & " [" & objShare.Path & "]"
    Next
End Sub

Impersonation sample: List all shares on a remote computer using different credentials than logged on user
Option Explicit

Dim strComputer, strUser, strPassword
Do
    strComputer = inputbox( "Please enter computername (or . for local host)", "Input" )
Loop until strComputer <> ""
Do
    strUser = inputbox( "Please enter username", "Input" )
Loop until strUser <> ""
Do
    strPassword = inputbox( "Please enter password", "Input" )
Loop until strPassword <> ""
ListShares strComputer, strUser, strPassword

WScript.Echo vbCrlf & "Ready."


Sub ListShares( strComputer, strUser, strPassword )
    Dim strObject
    Dim objLocator, objWMIService, objShare
    Dim colShares

    Set objLocator = CreateObject( "WbemScripting.SWbemLocator" )
    Set objWMIService = objLocator.ConnectServer ( strComputer, "root/cimv2", strUser, strPassword )
    objWMIService.Security_.impersonationlevel = 3
    Set colShares = objWMIService.ExecQuery( "Select * from Win32_Share" )
        For Each objShare In colShares
            Wscript.Echo objShare.Name & " [" & objShare.Path & "]"
    Next
End Sub


   © 2009. All rights reserved. GFI Software Home Products Download trials Support Ordering Site map About us Contact us
GFI solutions: exchange anti spam filter - exchange anti virus - isa server - network vulnerability scanner - event log management - usb security software - exchange archiving - fax server software