Solved

Add a user to all shares in the machine

Posted on 2007-12-03
32
370 Views
Last Modified: 2012-05-05
Hi,

I need a way to add a user to the share and NTFS permissions on all shares in the machine with read permissions.Is there a way to do this.

Regards
Sharath
0
Comment
Question by:bsharath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 15
32 Comments
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20404014
How many shared drive are there?
0
 
LVL 11

Author Comment

by:bsharath
ID: 20404148
More than 1000
0
 
LVL 11

Author Comment

by:bsharath
ID: 20404158
there are 6 drives and 100 folders.This is a NAS box with windows 2000 OS
0
Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

 
LVL 12

Expert Comment

by:chandru_sol
ID: 20404290
I think what we can do is list all the shares in the server and put that in a text file and then use setacl to set the permission for all the folders

regards
Chandru
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20404293
Have you used shareenumerator from sysinternals
0
 
LVL 11

Author Comment

by:bsharath
ID: 20404309
Yes...
Does this have any option?
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20404332
What option are you referring to? using this we can just pull out the shares
0
 
LVL 11

Author Comment

by:bsharath
ID: 20404333
I have the list of shares taken from shareenum.Now what i the next step?
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20409266
Did you manage to get the list from the particular server?

Try this script......

regards
Chandru
Option Explicit 
Dim objFs, objShare 
Dim strServer
 
' The section sets the variables 
strServer = "servername"
 
' Connects to the operating system's file system
set objFs = GetObject("WinNT://" _
& strServer & "/LanmanServer,FileService")
 
' Loops through each share
For Each objShare In objFs
WScript.Echo objShare.path
Next

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 20409300
I managed to get all the shares to a file.
Now need a way to add a user to all shares.
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20409436
try this script........
Make sure you have the setacl in c:\windows\system32

regards
Chandru
Option Explicit 
Dim objFs, objShare 
Dim strServer
Dim StrFolder
Dim objshell
 
' The section sets the variables 
strServer = "servername"
 
' Connects to the operating system's file system
set objFs = GetObject("WinNT://" _
& strServer & "/LanmanServer,FileService")
 
' Loops through each share
For Each objShare In objFs
 
StrFolder = objShare.path
 
wscript.echo objshare.path
 
'SetACL to set permissions
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /c Setacl -on " & strFolder & " -ot file -actn ace -ace n:username;p:read;m:grant;"
wscript.sleep (10000)
 
Next
 
'Quit
Wscript.quit

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 20409448
What will the script do..>Will it add a user to all folders.(Shared folders)
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20409461
yes. I have added wscript.echo so that you can check after a folder whether the permission is applied

regards
Chandru
0
 
LVL 11

Author Comment

by:bsharath
ID: 20409507
I saved the code to a vbs file and ran it...Nothing changed.Is there any where i need to add the username.Or is there something i am missing
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20409869
yes. change the username in the script to suit your needs and make sure setacl.exe is there from the location where the script is run or %systemroot%\system32

regards
Chandru
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20409872
You need to change the servername aswell

regards
Chandru
0
 
LVL 11

Author Comment

by:bsharath
ID: 20409890
Should i change this part
n:username;p:read;m:grant
      ^Myname
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20409903
only the username as bsharath
0
 
LVL 11

Author Comment

by:bsharath
ID: 20409925
Excellent Chandru...
Was wanting a script like this from 2yrs...

One more thing can you get the results to a file on what it has added and to what folders.
If the user is already there what happens.In the results we can see all...
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20410069
Hope you didn't post the question in EE.

It doesn't make any difference if the user is already there.

I think if you can redirect the result using cscript
0
 
LVL 11

Author Comment

by:bsharath
ID: 20410096
I tried this
C:\>cscript addpermissions.vbs > c:\re.txt

Re,txt file has just this...
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

F:\Softwares\VPN
F:\c9934e862e22ff853c05cfghf

Any way to get the details...
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20410103
Hope you removed the wscript.echo
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20410107
Can you be more specific about what details?
0
 
LVL 11

Author Comment

by:bsharath
ID: 20410164
If i remove wscript.echo
I get this.

C:\>cscript addpermissions.vbs > c:\re.txt
C:\addpermissions.vbs(19, 2) Microsoft VBScript runtime error: Object doesn't su
pport this property or method: 'path'

For details i mean. Which shares has it updated and which it sould not update.
Success/Failures.

As for a folder VPN there was sharath already as member as Full access so when i run the script nothing happened...So if i can get a results file that says
Added Sharath to share "VPN"
It would be easy when i use this script to give permissions for 1000 folders
0
 
LVL 12

Accepted Solution

by:
chandru_sol earned 500 total points
ID: 20411791
Try this with the log file

Change the username and the servername. Log file will be in C:\logs.txt

regards
Chandru
Option Explicit 
Dim objFs, objShare 
Dim strServer
Dim StrFolder
Dim objshell, Command
 
' The section sets the variables 
strServer = "servername"
 
' Connects to the operating system's file system
set objFs = GetObject("WinNT://" _
& strServer & "/LanmanServer,FileService")
 
' Loops through each share
For Each objShare In objFs
 
StrFolder = objShare.path
 
'SetACL to set permissions
Set objShell = CreateObject("WScript.Shell")
 
Command = "Setacl.exe -on " & strFolder & " -ot file -actn ace -ace n:Username;p:read;m:grant -log c:\logs.txt -silent"
 
ObjShell.run Command, 0, True
 
Next
 
'Quit
Wscript.quit

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 20411880
I get the results file like this...

Processing ACL of: <\\?\F:\Softwares\VPN>

SetACL finished successfully.
Processing ACL of: <\\?\F:\c9934e862e22ff853c05cfghf>

SetACL finished successfully.
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20411968
That is the results file created by the setacl

Do you need anything else?
0
 
LVL 11

Author Comment

by:bsharath
ID: 20412032
No that would be fine.Thanks a lot Chandru...
0
 
LVL 11

Author Closing Comment

by:bsharath
ID: 31412537
Excellent Chandru Thanks....
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20412401
Glad i helped you in a script which you were searching for a long time

Hope this solved your purpose

regards
Chandru
0
 
LVL 11

Author Comment

by:bsharath
ID: 20412483
Yes Chandru thanks a lot...
You saved hrs of my manual work with this script.Which can do the job in Minutes.

0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20412562
No worries!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question