In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use vbs to determine the local path of the shared folder, the article is very detailed, has a certain reference value, interested friends must read it!
Q:
If you have a UNC path (for example,\\ server1\ test), can you use a script to determine the local path to a shared folder (such as the C:\ Scripts\ Test folder)?
A:
Yes, you're right.
Oh, yes; we almost forgot. Can you use a script to determine the local path to a shared folder? Of course you can (although we don't know why people still have the leisure to do this during the baseball season). But if that's what you want to do, it tells you what to do:
The code is as follows:
StrPath = "\\ atl-fs-01\ public"
StrPath = Replace (strPath, "\", "")
ArrPath = Split (strPath, "\")
StrComputer = arrPath (0)
StrShare = arrPath (1)
Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\ root\ cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_Share Where Name ='" & strShare & "'")
For Each objItem in colItems
Wscript.Echo objItem.Path
Next
As you can see, we first used a typical UNC path:\\ atl-fs-01\ public. By the way, we store the path in a variable named strPath. With this path name, we must do two things. First, we must separate the computer name (atl-fs-01) from the share name (public). After that, we must connect to the computer atl-fs-01 and determine the local path to the public folder. How hard will that be? It's not hard at all.
Especially for us script writers who have just managed to defeat their "invincible" rivals. We haven't talked about it, have we? The final score was 4-2, even though we didn't play so well. The coach must be very good.
Let's get down to business. First, we have to remove the\\ before the UNC path. Although there are several other ways, we just need to use the Replace function to replace each occurrence of\\ with empty content:
StrPath = Replace (strPath, "\", "")
After this line of code is executed, the variable strPath will be equal to atl-fs-01\ public. This means that we can use the Split function to divide this value into an array:
ArrPath = Split (strPath, "\")
After separating according to\, we finally get an array of two pieces of data:
? Atl-fs-01
? Public
Needless to say, these are the two pieces of information we are looking for: the computer name and the shared folder name. Once this is clear, we assign the first item (item 0) in the array to the variable named strComputer and the second item (item 1) to the variable named strShare:
StrComputer = arrPath (0)
StrShare = arrPath (1)
So, are we now in the more difficult part? Believe it or not, this is the hard part; after that, we just need to use the standard WMI script. We first connect to the WMI service on the remote computer. Which remote computer? Is Atl-fs-01, and the name of the computer is stored in a variable named strComputer. Then we use the ExecQuery method to retrieve a collection of all shared folders on this computer:
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_Share Where Name ='" & strShare & "'")
Good idea: we didn't get all the shared folders, did we? Instead, we only get shared folders where the Name attribute is equal to the value of the strShare variable. (when you take a nap, strShare equals public, which is the name of the shared folder we want. The next thing to do is to set up a For Each loop to iterate through the collection (because the shared folder name must be unique on a computer, so there will be only one item in the collection), and then echo the value of the Path property. As you may have guessed, the Path property tells us the local path to the folder on atl-fs-01:
D:\ Scripts\ Public
The above is all the contents of the article "how to use vbs to determine the local path of a shared folder". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.