Folder Security

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Folder Security

Post by kpassaur » Wed May 25, 2011 9:38 am

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.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 25, 2011 12:38 pm

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.

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Share Folder

Post by kpassaur » Wed May 25, 2011 12:44 pm

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?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 25, 2011 3:27 pm

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?

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Close

Post by kpassaur » Wed May 25, 2011 3:50 pm

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.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 25, 2011 4:00 pm

Try this

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
Edit 1- Added case sensitivity test
Last edited by JRL on Wed May 25, 2011 4:09 pm, edited 1 time in total.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 25, 2011 4:06 pm

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?

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Thanks it works

Post by kpassaur » Wed May 25, 2011 4:28 pm

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?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 25, 2011 5:41 pm

Open a DOS prompt, type "net use" and press Enter. Is that what you're looking for?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts