Solved

DOS Batch file command - inserting data

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
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…

792 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