Solved

DOS Batch file command - inserting data

Posted on 2010-09-02
4
287 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
  • 2
4 Comments
 
LVL 95

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 100 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 95

Accepted Solution

by:
Lee W, MVP earned 400 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article covers how to install the Microsoft Windows Operating System (OS). What is covered in this article:  > Different Versions and Editions of the Windows OS  > Upgrading versus Fresh Installation of the OS           - Steps to take pr…
This article describes how to set permissions to allow a limited-permissions user to start and stop a particular System Service.   It is always best to give users only the permissions that they need to perform their job, so tweaking particular permi…
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 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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now