Solved

How to run multiple lines in a batch file

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

Expert Comment

by:Bill Prew
Comment Utility
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 33

Expert Comment

by:paulmacd
Comment Utility
"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
Comment Utility
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
Comment Utility
thanks to all......
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

16 Experts available now in Live!

Get 1:1 Help Now