Solved

How to run multiple lines in a batch file

Posted on 2016-09-27
4
62 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 18

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

815 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

8 Experts available now in Live!

Get 1:1 Help Now