Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DOS Batch file command - inserting data

Posted on 2010-09-02
4
Medium Priority
?
338 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

636 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