Solved

DOS Batch file command - inserting data

Posted on 2010-09-02
4
306 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ost file to pst 10 136
file size 9 51
Recursively Delete Files 5 83
Windows updates batch files 7 44
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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…
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…
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…

777 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