Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to run multiple lines in a batch file

Posted on 2016-09-27
4
Medium Priority
?
186 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 57

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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 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