Solved

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

Posted on 2016-10-11
5
53 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 83

Expert Comment

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

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 83

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
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). …
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

932 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

10 Experts available now in Live!

Get 1:1 Help Now