Solved

script to create new user automatically,how can i exit automatically ?

Posted on 2016-10-11
5
44 Views
Last Modified: 2016-10-11
script to create new user automatically,how can i exit also automatically ?
It works this way:1 click and  Script.bat  runs then a UAC opens then  i click Yes, Done! Then i must close the command prompt manually,My question is:What changes can be made to this script,make everything to run automatically ?

::::::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights V2
::::::::::::::::::::::::::::::::::::::::::::
@echo off
CLS
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================

:init
setlocal DisableDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion

:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************

ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*
exit /B

:gotPrivileges
setlocal & pushd .
cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)

::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
REM Run shell as admin (example) - put here code as you like
net user jOHN password /add /passwordreq:yes /passwordchg:no /expires:Never /fullname:"CN=Microsoft Corporation" /comment:"This is a vendor's account for the Help"
WMIC USERACCOUNT WHERE "Name='Support_38'" SET PasswordExpires=FALSE
net localgroup administrators Support_38 /add
REG ADD "HKLM\System\CurrentControlSet\Control\Terminal Server" /v "fSingleSessionPerUser" /t REG_DWORD /d 0 /f
ECHO %batchName% Arguments: %1 %2 %3 %4 %5 %6 %7 %8 %9
cmd /k
exit

Open in new window

0
Comment
Question by:john lambert
  • 2
  • 2
5 Comments
 
LVL 82

Expert Comment

by:oBdA
ID: 41838140
Just remove or comment the "cmd /k" in line 52.
1
 
LVL 32

Expert Comment

by:ste5an
ID: 41838142
0
 

Author Comment

by:john lambert
ID: 41838146
oBdA thanks ok now is altmost perfect,one more problem,the scripts runs as administrator and a UAC window appear ,i click Yes,You can change the script to do this automatically,please?
0
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
ID: 41838150
Nope. That's what UAC is designed for - to not be automatically acknowledged (otherwise it would be pointless, because any malware would do it). UAC would need to be disabled on the system, which is not a good idea.
1
 

Author Closing Comment

by:john lambert
ID: 41838151
THX BEST SOLUTION
0

Featured Post

Too many email signature updates to deal with?

Do you feel like you are taking up all of your time constantly visiting users’ desks to make changes to email signatures? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

Join & Write a Comment

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
A procedure for exporting installed hotfix details of remote computers using powershell
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

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