Description
In this article, I am going write VBScript code to find and get list of Network Shares/Share Folders in Local Machine and Remote Server using VBScript by different methods.
Summary
VBScript to List Network Shares in Local Computer
1. Copy the below example VB Script code and paste it in notepad or a VBScript editor.
2. Save the file with a .vbs extension, for example: ListNetworkSharesinLocalComputer.vbs
3. Run usage in CMD:
C:> CScript <vbscript file path>
Example: CScript C:ScriptsListNetworkSharesinLocalComputer.vbs
Run the above command to list Network Share Folders with VBScript using WMI Service in Local Computer
Click to get VBScript source code as a file Download ListNetworkSharesinLocalComputer.vbs
' ListNetworkSharesinLocalComputer.vbs
' Sample VBScript code with WMI Service to find and list Network Shares .
' Author: https://www.morgantechspace.com/
' ------------------------------------------------------
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService= objSWbemLocator.ConnectServer(".", "rootcimv2")
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share Where Type=0")
For each objShare in colShares
Wscript.Echo "Name: " & objShare.Name & vbCrLf _
& "Path: " & objShare.Path & vbCrLf _
& "Type: " & objShare.Type & vbCrLf _
& "Allow Maximum: " & objShare.AllowMaximum & vbCrLf _
& "Maximum Allowed: " & objShare.MaximumAllowed & vbCrLf _
& "Caption: " & objShare.Caption
Wscript.Echo "---------------------------------"
Next
' Wscript.Echo "Network Share Folders in Local computer listed successfully"
WScript.Quit
Note: Here, I have filtered Win32_Share collections by its Type=0 to list only Share Folders. You can also filter by Type value other than 0 to get other shared items like Printers, Devices, IPC, and etc…Check the following Type values for corresponding Shared Items.
Shared Item |
Type |
Disk Drive |
0 (0x0) |
Print Queue |
1 (0x1) |
Device |
2 (0x2) |
IPC |
3 (0x3) |
Disk Drive Admin |
2147483648 (0x80000000) |
Print Queue Admin |
2147483649 (0x80000001) |
Device Admin |
2147483650 (0x80000002) |
IPC Admin |
2147483651 (0x80000003) |
VBScript to Get Network Shares/Share Folders in Remote Server
1. Copy the below example VB Script code and paste it in notepad or a VBScript editor.
2. Change the value of string variable ‘strComputer’ to your own Computer or Server name.
3. Save the file with a .vbs extension, for example: ListNetworkSharesinRemoteServer.vbs
3. Run usage in CMD:
C:> CScript <vbscript file path>
Example: CScript C:ScriptsListNetworkSharesinRemoteServer.vbs
Run this command from Command Prompt to get list of Network Shares with VBScript using WMI Service in Remote Server.
Click to get VBScript source code as a file Download ListNetworkSharesinRemoteServer.vbs
' ListNetworkSharesinRemoteServer.vbs
' Sample VBScript to find and list Network Shares in Remote Machine .
' Author: https://www.morgantechspace.com/
' ------------------------------------------------------
strComputer = "hp-PC"
' you can change your own Computer or Server.
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService= objSWbemLocator.ConnectServer(strComputer , "rootcimv2")
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share Where Type=0")
For each objShare in colShares
Wscript.Echo "Name: " & objShare.Name & vbCrLf _
& "Path: " & objShare.Path & vbCrLf _
& "Type: " & objShare.Type & vbCrLf _
& "Allow Maximum: " & objShare.AllowMaximum & vbCrLf _
& "Maximum Allowed: " & objShare.MaximumAllowed & vbCrLf _
& "Caption: " & objShare.Caption
Wscript.Echo "---------------------------------"
Next
' Wscript.Echo "Network Share Folders in Remote Computer listed successfully"
WScript.Quit
Find Network Share Folders in VBScript by using other User Credential
1. Copy the below example VB Script code and paste it in notepad or a VBScript editor.
2. Change the value of string variable ‘strComputer’ to your own Computer or Server name.
3. Change the user account ‘Administrator’ to your own user credential and give valid password.
4. Save the file with a .vbs extension, for example: ListNetworkSharesAsDiffUser.vbs
5. Run usage in CMD:
C:> CScript <vbscript file path>
Example: CScript C:ScriptsListNetworkSharesAsDiffUser.vbs
Run this command from Command Prompt to get list of Network Shares with VBScript using WMI Service by using different User Credential.
Hi.. when I tried too call objShare.Path I m getting an error
"Object doesn't support this property or method: 'objService.Path'" can you help me out
Hi
Thanks for sharing this info .I am a newbie to WMI and i need ur help to get the PC details using its sjared path. EG:\Pc123dtest is the shared path. I have to get details like C drive free space availablity and network info of "Pc123".Could you please guide me on this
All help are appreciated
Thanks again