?
Solved

Batch File issue

Posted on 2005-05-11
11
Medium Priority
?
199 Views
Last Modified: 2008-03-10
I am trying to create a batch file that pulls a series of names to create directories, set permissions and share out a folder.  So far I have the basics using the following.  What I cannot figure out is how to have the script go through a list of names instead of copying this 80K times.

C:
CD\
CD Users
MD %USERNAME%
XCALCS D:\Users\%USERNAME% /E /G DOMAIN\%USERNAME%:RC
NET SHARE %USERNAME%$=D:\Users\%USERNAME% /GRANT:Administrators,FULL /GRANT:DOMAIN\%USERNAME%,CHANGE /USERS:5

Any help would be great
0
Comment
Question by:kix1979
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 472 total points
ID: 13981881
maybe you can name your batch file:  process.bat, and a little modifications:
C:
CD\
CD Users
MD %1
XCALCS D:\Users%1 /E /G DOMAIN%1:RC
NET SHARE %1$=D:\Users%1 /GRANT:Administrators,FULL /GRANT:DOMAIN%1,CHANGE /USERS:5
(review because I think it is lacking some signs like backspace)


Then export your list of usernames to a text file and put the word process at the beginning of each line.
Rename this textfile to proc-all.bat

proc-all.bat must look like this:

PROCESS JohnDoe
PROCESS AnnSmith
PROCESS PaulMiller
.....etcetera...
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13981916
Sorry I meant:
(review because I think it is lacking some signs like backslash)

0
 
LVL 25

Assisted Solution

by:InteractiveMind
InteractiveMind earned 464 total points
ID: 13982057
Hi.

Firstly, you can replace these three lines:

   C:
   CD\
   CD Users

with:

   cd /d c:\Users

Now, as for the processing multiple names: If you store these names as a list in a text file, for example, create a text file called "names.txt", with the names you want to process, listed, like so:

Robert
Jaime
Kix
etc..

You can then process each of these lines, by using the following code instead:


@ECHO OFF
SET inputFile=names.txt

for /f "delims=" %%L in (%inputFile%) do call :process "%%L"
goto :eof

:process
set user=%~1
CD /d c:\Users
MD %USER%
XCALCS D:\Users\%USERNAME% /E /G DOMAIN\%USER%:RC
NET SHARE %USER%$=D:\Users\%USER% /GRANT:Administrators,FULL /GRANT:DOMAIN\%USER%,CHANGE /USERS:5
exit /b

:eof
echo complete


I kind of get the impression however that you wish to process all user accounts on the machine. If this is the case, then you can process all user accounts, with the following code:


@echo off
cd /d c:\Users

echo All Users Default User LocalService NetworkService Owner>t.txt
for /f "delims=" %%F in ('dir /b "c:\documents and settings\*" /a:d') do call :process "%%F"
goto :eof

:process
set user=%~1
find /i "%user%" "t.txt" >nul
if %errorlevel% equ 0 exit /b
CD /d c:\Users
MD %USER%
XCALCS D:\Users\%USERNAME% /E /G DOMAIN\%USER%:RC
NET SHARE %USER%$=D:\Users\%USER% /GRANT:Administrators,FULL /GRANT:DOMAIN\%USER%,CHANGE /USERS:5
exit /b

:eof
del "t.txt" /q>nul
echo complete

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13982076
The above code assumes that you're using Windows XP (and Win 2K/NT, if they store user folders in the "c:\documents and settings" directory ... I'm unfamiliar with most other OS's you see).  ^_^
0
 
LVL 60

Assisted Solution

by:Julian Hansen
Julian Hansen earned 464 total points
ID: 13982079
You can use VBScript as an alternative or try this

create a file called names.dat and put the users in here you want to run this for i.e.

james
john
mike
(etc)

Now run the following

FORr /F "tokens=1" %%i IN (names.dat)  DO (
C:
CD\
CD Users
MD %%i
XCALCS D:\Users\%%i /E /G DOMAIN\%%i:RC
NET SHARE %%i$=D:\Users\%%i /GRANT:Administrators,FULL /GRANT:DOMAIN\%%i,CHANGE /USERS:5
)
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 14212385
The question was answered - author just did not bother to close question.

Recommed split points
0
 
LVL 20

Expert Comment

by:Venabili
ID: 14213024
And I recommend answering to pings...

Mods,

Please leave it open for a second thought on this

Venabili
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

807 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