?
Solved

DOS Batch file command - inserting data

Posted on 2010-09-02
4
Medium Priority
?
333 Views
Last Modified: 2012-05-10
I need to have a batch file run that will add a user to a specific local group. I know the cvommand line is

net localgroup "Groupname" "username" \add.

However, I need  to allow the user to add him or herself into the "username" area when the batch file runs.

This should be in a DOS command manner, or a script that can be called up when the batch file runs.

Any ideas out there?

Thanks in advance.
0
Comment
[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
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 33589470
Three options:
1.  Have the user specify the user name on the command line - MYBATCH USERNAME
Then in the batch file, in place of username, use %1

2.  Have the batch file prompt the user for the username -
SET /P Useraccount=Please Enter your username:
Then reference %Useraccount%

3.  Use the username automatically.
net localgroup "Groupname" "%username%"
0
 
LVL 3

Assisted Solution

by:swesluggo
swesluggo earned 400 total points
ID: 33589481
i think you could use set /p <yourvar>=Enter your name:
eg.

set usr=
set /p usr=Please enter your username:
net localgroup "Groupname" %usr" \add


it was a looong time since i did any batch-coding though..
0
 
LVL 8

Expert Comment

by:moonie42
ID: 33589503
you should be able to use the %USERNAME% variable in your batch file.
net localgroup "groupname" %username% /add
0
 
LVL 96

Accepted Solution

by:
Lee W, MVP earned 1600 total points
ID: 33589555
Or a combination:

@echo off
if "%1"=="" Goto SetUserName
Goto RunCommands
:SetUserName
Echo You are currently logged in as "%username%"
Set /p UseEnvVar=Use this username? (y/N)
If /i "%useenvvar%"=="y" (
   Set AcctName=%username%
   Goto RunCommands
)
:AskAgain
set /p AcctName=Enter username:
Rem If no name was entered, loop and ask again until one is entered.
if "%acctname%"=="" Goto AskAgain
:RunCommands
net localgroup "GroupName" "%AcctName%"
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Many times while working on a computer regardless of any Operating System, lag and crashes seem to creep in, hindering your working speed. Sometimes, it can also cause your work to be lost unexpectedly and as a result, you are unable to meet your de…
This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

800 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