Solved

How to run multiple lines in a batch file

Posted on 2016-09-27
4
74 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
4 Comments
 
LVL 53

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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