Solved

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

Posted on 2016-10-11
5
64 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 84

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 84

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article will help you understand what HashTables are and how to use them in PowerShell.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

860 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