Solved

How to run multiple lines in a batch file

Posted on 2016-09-27
4
128 Views
Last Modified: 2016-09-27
So i create a batch called Idle.bat and i save all that 3 lines and run them as administrator,my question is can i add 50-60 lines?will have affect all 60 ?with no pause etc etc??
thank you

REG ADD "HKCU\Control Panel\Desktop" /v "ScreenSaverIsSecure" /t REG_SZ /d 0 /f
REG ADD "HKCU\Control Panel\Desktop" /v "ScreenSaveActive" /t REG_SZ /d 0 /f
REG ADD "HKCU\Control Panel\Desktop" /v "ScreenSavetimeOut" /t REG_SZ /d 0 /f

Open in new window


or can i run this script adding all lines,this script have UAC run as administrator automatic:

@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------
REG ADD "HKCU\Control Panel\Desktop" /v "ScreenSaverIsSecure" /t REG_SZ /d 0 /f
REG ADD "HKCU\Control Panel\Desktop" /v "ScreenSaveActive" /t REG_SZ /d 0 /f
REG ADD "HKCU\Control Panel\Desktop" /v "ScreenSavetimeOut" /t REG_SZ /d 0 /f

Open in new window

0
Comment
Question by:john lambert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 56

Expert Comment

by:Bill Prew
ID: 41818655
You can do as you indicated adding the commands you want to execute in administrative mode at the end of that BAT file, and you can include as many as you need.

~bp
1
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 41818657
"my question is can i add 50-60 lines?"
Yes, you can.

"will have affect all 60 ?"
No, the script will run fine with however many lines you put in it.  Each line executes once the one before it is done, so there may be a pause, but not because of the number of lines.
1
 
LVL 19

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 41818870
The code lines one by one until there are errors in that line and then it keeps executing the lines until end of batch file.

it means it gives error for the invalid command but keeps running the next lines (ie commands)
so does not effect your script.You just add like you did in your script posted (which have UAC run as administrator automatic:)
1
 

Author Closing Comment

by:john lambert
ID: 41819173
thanks to all......
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

630 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