Folder Security
Moderators: JRL, Dorian (MJT support)
Folder Security
I am looking for a way to see if a folder is shared. The folder could be on the local machine, a mapped drive or have a UNC Path pointing to the folder.
What I am trying to do is not allow the user to use a shared folder, so the script would find a way to see if it is shared and if it is display a message saying the input folder may not be shared.
Now is where is gets a little tricky, ideally anyone logged into the local machine would be able to use the folder. So, if it was called "C:\temp processing" anyone logged on to the local machine would have access to it but there would be no access to it from an outside machine. So, if a quest was logged on or an administrator they would both have access to it.
This maybe really easy to do if you are a security expert, however, I am not.
What I am trying to do is not allow the user to use a shared folder, so the script would find a way to see if it is shared and if it is display a message saying the input folder may not be shared.
Now is where is gets a little tricky, ideally anyone logged into the local machine would be able to use the folder. So, if it was called "C:\temp processing" anyone logged on to the local machine would have access to it but there would be no access to it from an outside machine. So, if a quest was logged on or an administrator they would both have access to it.
This maybe really easy to do if you are a security expert, however, I am not.
I don't know any way to do what I think you're asking. What you might try is adding a dollar sign to the end of the share name. If there is a dollar sign at the end of the share name other computers can't see the share. They can still get to it if they know its there and know the name but if they can't see it, how would they know? This means you could script a UNC path to go to the shared folder from any computer and users could not detect the path or use it themselves.
Share Folder
JRL
I am looking at it the other way. I have a utility that monitors a file folder and I don't want files being placed in this monitored folder unless they come from the same PC that the folder is on.
I realize a work around would be place a share on the local machine and then copy them into the monitored folder but I am not worried about that happening.
Does it make more sense explained like this?
I am looking at it the other way. I have a utility that monitors a file folder and I don't want files being placed in this monitored folder unless they come from the same PC that the folder is on.
I realize a work around would be place a share on the local machine and then copy them into the monitored folder but I am not worried about that happening.
Does it make more sense explained like this?
Still not sure I understand. This is what I think you're saying.
Computer "A" has a shared folder and files are being placed in that folder.
Computer "B" has a utility that is checking the files in computer "A"s shared folder.
You don't want users on computer "B" to be able to place any files into computer "A"s shared folder.
Is this correct?
Computer "A" has a shared folder and files are being placed in that folder.
Computer "B" has a utility that is checking the files in computer "A"s shared folder.
You don't want users on computer "B" to be able to place any files into computer "A"s shared folder.
Is this correct?
Close
Another way to explain it would be:
I have a folder on Machine A called "C:\tempfiles" and I want to make sure this folder is not shared. I do not want someone on another machine (Machine B, C or D etc) to be able to place files in this folder. So, I need a method of seeing if it is shared.
So the script would check to see if the folder "C:\tempfiles" is shared, if it is shared it displays a message cannot process files that are in a shared folder. If it is not shared it processes the files.
I have a folder on Machine A called "C:\tempfiles" and I want to make sure this folder is not shared. I do not want someone on another machine (Machine B, C or D etc) to be able to place files in this folder. So, I need a method of seeing if it is shared.
So the script would check to see if the folder "C:\tempfiles" is shared, if it is shared it displays a message cannot process files that are in a shared folder. If it is not shared it processes the files.
Try this
Edit 1- Added case sensitivity test
Code: Select all
Let>FolderToTest=C:\tempfiles
UpperCase>FolderToTest,FolderToTest
Let>RP_WINDOWMODE=0
Let>RP_WAIT=1
Run>cmd /c wmic share get path > %temp_dir%paths.txt
ReadFile>temp_dir%paths.txt,data
UpperCase>data,data
Separate>data,FolderToTest,Ans
If>Ans_count>1
MDL>folder %FolderToTest% is shared
EndIf
Last edited by JRL on Wed May 25, 2011 4:09 pm, edited 1 time in total.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
IsFolderShared:
Code: Select all
VBSTART
Function IsFolderShared(folder)
IsFolderShared = false
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
For each objShare in colShares
if UCase(objShare.Path) = UCase(folder) Then
IsFolderShared = true
exit for
End if
Next
End Function
VBEND
//Usage:
VBEval>IsFolderShared("c:\intel"),Sh1
VBEval>IsFolderShared("c:\temp"),Sh2
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Thanks it works
First off, thanks to both of you.
I used the VBScript example and it worked. So the only thing left would be to see if it is a mapped drive. The VBScript worked on the folders on the local machine then I mapped a shared folder on another machine to the drive letter T:, dropped that in and it said False.
So it works on a local folder but not on one mapped to a drive letter. So if there is a way to get a UNC path that should at least tell me that the folder is mapped to a drive and then I could assume that it is shared as well.
Is there a way to see if a drive letter is mapped to another machine? Or a way to see what the UNC path is to a drive letter as that would tell what machine?
I used the VBScript example and it worked. So the only thing left would be to see if it is a mapped drive. The VBScript worked on the folders on the local machine then I mapped a shared folder on another machine to the drive letter T:, dropped that in and it said False.
So it works on a local folder but not on one mapped to a drive letter. So if there is a way to get a UNC path that should at least tell me that the folder is mapped to a drive and then I could assume that it is shared as well.
Is there a way to see if a drive letter is mapped to another machine? Or a way to see what the UNC path is to a drive letter as that would tell what machine?