Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Recommended Posts

Hey

 

I am a general computer admin managing 10+ pcs. I tried writing a batch to install and update new programs but it keeps exiting at the if statement. Please help

@echo offffox29.exe -msccsetup.exe /Sklite.exe /verysilent /norestart(THE PROBLEM IS HERE)If NOT exist "C:\Users"( echo Installing Internet Explorer 8 IE8-WindowsXP-x86-ENU.exe /passive /update-no /no-default /norestart)ELSE( Echo Internet Explorer 8 Not Required)SET /p AVG=Do you want to Install AVG(Y/N)IF %AVG% EQU y( IF %PROCESSOR_ARCHITECTURE% EQU x64 ( echo Installing AVG x64 avg x64 /UILevel=silent /InstallToolbar=0 /ChangeBrowserSearchProvider=0 /SelectedLanguage=1033 /InstallSidebar=0 /ParticipateProductImprovement=0 /DontRestart /KillProcessesIfNeeded ) ELSE ( echo Installing AVG x86 avg x86 /UILevel=silent /InstallToolbar=0 /ChangeBrowserSearchProvider=0 /SelectedLanguage=1033 /InstallSidebar=0 /ParticipateProductImprovement=0 /DontRestart /KillProcessesIfNeeded ))Else( echo AVG Installation Skipped)SET /p LIBRE=Do you want to Install Libre Office(Y/N)IF %LIBRE% EQU y( Echo Installing Libre Office LibreOffice_4.2.3_Win_x86.msi ALLUSERS=1 /q /norestart)Echo Renaming Icons...Ren "%USERPROFILE%\Desktop\CCleaner.lnk" "Run Weekly.lnk"Ren "%USERPROFILE%\Desktop\Mozilla Firefox.lnk" "Internet.lnk"Echo Renaming DoneEcho Disabling Hibernationif exists C:\users( cmd.exe /c powercfg.exe -h off)echo Deleting Files del ffox29.exe del ccsetup.exe del klite.exe del Install V1.1.bat del avg x64.exe del avg x86.exe del LibreOffice_4.2.3_Win_x86.msiecho Operation Completeexit /b
Edited by Yzöwl
code transferred to built-in code box

Share this post


Link to post
Share on other sites

The opening bracket NEEDS to be on the same line of the IF, example:

IF NOT EXIST "C:\Users" (ECHO Doing something) ELSE (ECHO Doing something else.)

Usually, the "safe" way to check for the existence of a directory is to use a final backslash, i.e.

IF NOT EXIST "C:\Users\" (

 

because if a file "users" for any reason exists it may "trigger" the batch wrongly.

 

Also, the "usual" way of writing:

 

SET /p AVG=Do you want to Install AVG(Y/N)
IF %AVG% EQU y

 

Is:

SET AVG=N

SET /p AVG=Do you want to Install AVG(Y/N)

IF /I %AVG%.==Y. 

 

Because this way the Y or N is case insensitive and if nothing is provided, i.e. the user just presses Enter, it is assumed a "default" (of N in this example).

 

jaclaz

Share this post


Link to post
Share on other sites

Initial comment, whilst it may be okay in your ten workstation environment, searching for a static path C:\Users is most certainly not a good idea for determining Operating System.

 

Are you aware that your AVG executables contain file-name spaces?

 

Is one of the installations enabling hibernation? if not why are you disabling it as part of a software installation script?

 

What is Install V1.1.bat? how is it relevant? and are you expecting to delete it from this script?

Share this post


Link to post
Share on other sites

@Yzowl

 

The only operating system that does not use  c:\users\ is xp which is "Documents and Settings" and we do not use anything lower than xp. 

 

I did notice the AVG mistake and fixed it.

 

I disable hibernation due to the network setup i have so id rather set the pc's so sleep in 30 minutes than shutdown down to hibernation and hibernation takes longer to startup. This script is intended for setting up a new pc.

 

Once the script is done running, i want it to delete itself (thus the del Install V1.1.bat) and the installation files.

 

@jaclaz

 

Thanks for the speedy reply. I will reply if it fixed the problem.

 

 

Share this post


Link to post
Share on other sites

What happens in Windows XP if you type the following at a console window prompt:

If Not Exist %SystemDrive%\Users MD %SystemDrive%\Users
Does it magically become a new version of Windows?

 

When you fix a mistake in a script it helps if you post the updated version in order that those who wish to help are furnished with the same information as yourself.

 

So when you say that you were installing and updating new programs, did you mean that you were setting up new PC's from a network!

 

So in answer to my question the script itself is named Install V1.1.bat, and you were hoping for a self delete function! Which suggests to me that the script is being run locally on each PC and not part of the network set up you mentioned

 

I would suggest that OS changes / customisation are performed from a different script than program / application updates and installations.

 

When are you setting the PC's to sleep after 30 minutes? Would that not be done at the same time as the disabling of hibernation?

Share this post


Link to post
Share on other sites

@Wise Owl

 

C:\Users\ does not exist on Windows XP unless it is manually created. Easy way to identify Type of OS. This is my way of identifying the OS. I do java coding , but this is my first time creating a batch.

 

As the owner buys the new components. i do the assembly , windows installation etc do basicly im creating a script so that i can just copy the folder over to the pc and run the script. i am still getting to the power settings for sleep as i am getting the time.

 

Updated Version

@echo offecho Installing Firefoxffox29.exe -msecho Installing Ashampooashampoo.exe /sp- /verysilent /norestartecho Installing C-Cleanerccsetup.exe /Secho Installing K-liteklite.exe /verysilent /norestartEcho Adding Reg Key for No AutorunNOAUTORUN.regEcho Installing Adobe Readeradobe11.exe  /sPB /sAll /msi /norestart ALLUSERS=1 EULA_ACCEPT=YESEcho Installing Adobe Reader UpdateAdbeRdrUpd11006_MUI.msp /qp /norestartIF NOT EXIST "C:\Users\" ( echo Installing Internet Explorer 8 IE8-WindowsXP-x86-ENU.exe /passive /update-no /no-default /norestart) ELSE ( Echo Internet Explorer 8 Not Required)SET AVG=NSET /p AVG=Do you want to Install AVG(Y/N)IF /i %AVG% == Y ( IF %PROCESSOR_ARCHITECTURE% EQU x64 ( echo Installing AVG x64 avgx64 /UILevel=silent /InstallToolbar=0 /ChangeBrowserSearchProvider=0 /SelectedLanguage=1033 /InstallSidebar=0 /ParticipateProductImprovement=0 /DontRestart /KillProcessesIfNeeded ) ELSE ( echo Installing AVG x86 avgx86 /UILevel=silent /InstallToolbar=0 /ChangeBrowserSearchProvider=0 /SelectedLanguage=1033 /InstallSidebar=0 /ParticipateProductImprovement=0 /DontRestart /KillProcessesIfNeeded )) Else ( echo AVG Installation Skipped)IF EXIST "%PROGRAMFILES%\Microsoft Office\" ( ECHO Microsoft Office Detected!!) ELSE ( SET LIBRE=N SET /p LIBRE=Do you want to Install Libre Office(Y/N) IF /i %LIBRE% == Y(  Echo Installing Libre Office  LibreOffice_4.2.3_Win_x86.msi ALLUSERS=1 /q /norestart ))Echo Renaming Icons...Ren "%USERPROFILE%\Desktop\CCleaner.lnk" "Run Weekly.lnk"Ren "%USERPROFILE%\Desktop\Mozilla Firefox.lnk" "Internet.lnk"Echo Renaming DoneEcho Disabling Hibernationif exists "C:\users\" ( cmd.exe /c powercfg.exe -h off)echo Disabling System RestoreReg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" /v DisableSR /t REG_DWORD /d 1 /fsc config srservice start= disablednet stop srserviceecho Deleting Files del ffox29.exe del ccsetup.exe del adobe11.exe del klite.exe del IE8-WindowsXP-x86-ENU.exe del NOAUTORUN.reg del Install V1.1.bat del ashampoo.exe del avgx64.exe del avgx86.exe del LibreOffice_4.2.3_Win_x86.msi del AdbeRdrUpd11006_MUI.mspecho Operation Completeexit /b

Do you see any room for coding improvements?

Edited by Yzöwl
once again putting code into the buil-in code box

Share this post


Link to post
Share on other sites

.... but this is my first time creating a batch.

....

Do you see any room for coding improvements?

Yes :yes: (but this is "normal" since it is your first time you write a batch).

 

The base assumption however, as pointed out by  Yzöwl, is "wrong" and however is not in line with asking for improvements.

 

IF you want to check for the installed Operating System AND you want to improve your batch scripting abilities, you should start considering doing this in a proper way.

 

Mind you, "good enough" is - obviously - "good enough", but then you should not seek to improve the code, you go binary: either it works (for you) or it doesn't (and you need to fix it), but there no sense in asking for "coding improvements".

 

Also, you are perfectly free to NOT follow the advice that is given, but following some of it (but not all of it) makes IMHO little sense.

What I suggested you:

 

 

 

SET AVG=N

SET /p AVG=Do you want to Install AVG(Y/N)

IF /I %AVG%.==Y

Because this way the Y or N is case insensitive and if nothing is provided, i.e. the user just presses Enter, it is assumed a "default" (of N in this example).
The dots are there for a reason ;). (What would happen if the user hits the [sPACE] bar at the prompt before pressing [ENTER]?)

 

As well, there are documented, "proper" ways to detect the OS, see (examples):

http://www.robvanderwoude.com/files/appcompat_w7.txt

 

IF NOT "%OS%"=="Windows_NT" GOTO Syntax

SETLOCAL ENABLEDELAYEDEXPANSION

IF "%~2"=="" GOTO Syntax

:: Check Windows version (abort if not Vista or later)

FOR /F "tokens=*" %%A IN ('VER') DO (

FOR %%B IN (%%A) DO (

FOR /F "delims=[]." %%C IN ("%%~B") DO (

SET Winver=%%C

)

)

)

IF %WinVer% LSS 6 GOTO Syntax

Personally, as another example, I would write this:

echo Deleting Files

del ffox29.exe

del ccsetup.exe

del adobe11.exe

del klite.exe

del IE8-WindowsXP-x86-ENU.exe

del NOAUTORUN.reg

del Install V1.1.bat

del ashampoo.exe

del avgx64.exe

del avgx86.exe

del LibreOffice_4.2.3_Win_x86.msi

del AdbeRdrUpd11006_MUI.msp

echo Operation Complete

As:

FOR %%A IN (

ffox29.exe

ccsetup.exe

adobe11.exe

klite.exe

IE8-WindowsXP-x86-ENU.exe

NOAUTORUN.reg

Install V1.1.bat

ashampoo.exe

avgx64.exe

avgx86.exe

LibreOffice_4.2.3_Win_x86.msi

AdbeRdrUpd11006_MUI.msp

) DO (

ECHO Deleting file %%A .....

DEL %%A

)

echo Operation Complete

The suggested extension for batch files under NT systems is .cmd instead of .bat (rare nowadays, but especially with a "flawed" or "missing" OS version check they may be run accidentally in DOS or Win9x/Me if they are .bat)

jaclaz

Edited by jaclaz

Share this post


Link to post
Share on other sites

My idea of an improvement is to ask the questions at the very start of the script so you do not need to wait for installs to be done before waiting for the next prompt to happen.

 

This shows an example of how it can be done.

@echo offecho Choose optional installs by typing Y for Yes or N for Noset AVG=Nset /p AVG="AVG ? "set LIBRE=Nif exist "%PROGRAMFILES%\Microsoft Office\" ( set LIBRE=MS_OFFICE_EXISTS) else ( set /p LIBRE="Libre Office ? ")echo Thankyou! Starting installations nowecho Installing Firefoxffox29.exe -msecho Installing Ashampooashampoo.exe /sp- /verysilent /norestartecho Installing C-Cleanerccsetup.exe /Secho Installing K-liteklite.exe /verysilent /norestartecho Adding Reg Key for No AutorunNOAUTORUN.regecho Installing Adobe Readeradobe11.exe /sPB /sAll /msi /norestart ALLUSERS=1 EULA_ACCEPT=YESecho Installing Adobe Reader UpdateAdbeRdrUpd11006_MUI.msp /qp /norestartif not exist "C:\Users\" ( echo Installing Internet Explorer 8 IE8-WindowsXP-x86-ENU.exe /passive /update-no /no-default /norestart) else ( echo Internet Explorer 8 Not Required)if /i "%AVG%" == "Y" ( if %PROCESSOR_ARCHITECTURE% EQU x64 (  echo Installing AVG x64  avgx64 /UILevel=silent /InstallToolbar=0 /ChangeBrowserSearchProvider=0 /SelectedLanguage=1033 /InstallSidebar=0 /ParticipateProductImprovement=0 /DontRestart /KillProcessesIfNeeded ) else (  echo Installing AVG x86  avgx86 /UILevel=silent /InstallToolbar=0 /ChangeBrowserSearchProvider=0 /SelectedLanguage=1033 /InstallSidebar=0 /ParticipateProductImprovement=0 /DontRestart /KillProcessesIfNeeded )) else ( echo AVG Installation Skipped)if "%LIBRE%" == "MS_OFFICE_EXISTS" ( echo Microsoft Office Detected!) else if /i "%LIBRE%" == "Y" ( echo Installing Libre Office LibreOffice_4.2.3_Win_x86.msi ALLUSERS=1 /q /norestart) else ( echo Libre Office Installation Skipped)echo Renaming Icons...ren "%USERPROFILE%\Desktop\CCleaner.lnk" "Run Weekly.lnk"ren "%USERPROFILE%\Desktop\Mozilla Firefox.lnk" "Internet.lnk"echo Renaming Doneif exists "C:\users\" ( echo Disabling Hibernation cmd.exe /c powercfg.exe -h off)echo Disabling System Restorereg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" /v DisableSR /t REG_DWORD /d 1 /fsc config srservice start= disablednet stop srserviceecho Deleting Files del ffox29.exe del ccsetup.exe del adobe11.exe del klite.exe del IE8-WindowsXP-x86-ENU.exe del NOAUTORUN.reg del Install V1.1.bat del ashampoo.exe del avgx64.exe del avgx86.exe del LibreOffice_4.2.3_Win_x86.msi del AdbeRdrUpd11006_MUI.mspecho Operation Completeexit /b

Share this post


Link to post
Share on other sites
<SNIP />IF NOT EXIST "C:\Users\" ( echo Installing Internet Explorer 8 IE8-WindowsXP-x86-ENU.exe /passive /update-no /no-default /norestart) ELSE ( Echo Internet Explorer 8 Not Required)<SNIP />Echo Disabling Hibernationif exists "C:\users\" ( cmd.exe /c powercfg.exe -h off)<SNIP />
Do you see any room for coding improvements?

 

replacing the above with:

SET "_OSV="FOR /F "TOKENS=1* DELIMS=[" %%A IN ('VER') DO (SET "_OSV=%%B"	CALL SET "_OSV=%%_OSV:* =%%" & CALL SET "_OSV=%%_OSV:~,3%%")IF %_OSV% LSS 5.1 GOTO :EOFIF %_OSV% LSS 6.0 (ECHO= Installing Internet Explorer 8	IE8-WindowsXP-x86-ENU.exe /passive /update-no /no-default /norestart) ELSE (	ECHO= Internet Explorer 8 Not Required & ECHO= Disabling Hibernation	POWERCFG -h off)

Share this post


Link to post
Share on other sites

I have another problem with the batch. In windows vista or later the batch file requires administrative rights to disable hibernation , rename icons and install certain software and it still ends suddenly past a certain point...

@echo offECHO PLease specify if the following programs needs to be installed. y for yes and n for noSET AVG=NSET /p AVG=Do you want to Install AVG(Y/N)IF EXIST "%PROGRAMFILES%\Microsoft Office\" ( ECHO Microsoft Office Detected!! SET LIBRE=N SET /p LIBRE=Do you want to Install Libre Office(Y/N))echo Installing Firefoxffox29.exe -msecho Installing Ashampooashampoo.exe /sp- /verysilent /norestartecho Installing C-Cleanerccsetup.exe /Secho Installing K-liteklite.exe /verysilent /norestartEcho Adding Reg Key for No AutorunNOAUTORUN.regEcho Installing Adobe Readeradobe11.exe  /sPB /sAll /msi /norestart ALLUSERS=1 EULA_ACCEPT=YESEcho Installing Adobe Reader UpdateAdbeRdrUpd11006_MUI.msp /qp /norestartSET "_OSV="FOR /F "TOKENS=1* DELIMS=[" %%A IN ('VER') DO (SET "_OSV=%%B" CALL SET "_OSV=%%_OSV:* =%%" & CALL SET "_OSV=%%_OSV:~,3%%")IF %_OSV% LSS 5.1 GOTO :EOFIF %_OSV% LSS 6.0 (ECHO= Installing Internet Explorer 8 IE8-WindowsXP-x86-ENU.exe /passive /update-no /no-default /norestart) ELSE ( ECHO= Internet Explorer 8 Not Required & ECHO= Disabling Hibernation POWERCFG -h off)(program ends after this)IF /i %AVG% == Y ( IF %PROCESSOR_ARCHITECTURE% EQU x64 ( echo Installing AVG x64 avgx64 /UILevel=silent /InstallToolbar=0 /ChangeBrowserSearchProvider=0 /SelectedLanguage=1033 /InstallSidebar=0 /ParticipateProductImprovement=0 /DontRestart /KillProcessesIfNeeded ) ELSE ( echo Installing AVG x86 avgx86 /UILevel=silent /InstallToolbar=0 /ChangeBrowserSearchProvider=0 /SelectedLanguage=1033 /InstallSidebar=0 /ParticipateProductImprovement=0 /DontRestart /KillProcessesIfNeeded )) Else ( echo AVG Installation Skipped)IF /i %LIBRE% == Y( Echo Installing Libre Office LibreOffice_4.2.3_Win_x86.msi ALLUSERS=1 /q /norestart)Echo Renaming Icons...Ren "%USERPROFILE%\Desktop\CCleaner.lnk" "Run Weekly.lnk"Ren "%USERPROFILE%\Desktop\Mozilla Firefox.lnk" "Internet.lnk"Echo Renaming Doneecho Disabling System RestoreReg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" /v DisableSR /t REG_DWORD /d 1 /fsc config srservice start= disablednet stop srserviceecho Deleting Files del ffox29.exe del ccsetup.exe del adobe11.exe del klite.exe del IE8-WindowsXP-x86-ENU.exe del NOAUTORUN.reg del Install V1.1.bat del ashampoo.exe del avgx64.exe del avgx86.exe del LibreOffice_4.2.3_Win_x86.msi del AdbeRdrUpd11006_MUI.mspecho Operation Completeexit /b
Edited by Yzöwl
too late, i've had to do it again!

Share this post


Link to post
Share on other sites

@ghosttracer, unless you want to risk Yzöwl's ire, PLEASE always surround your code with code tags, like so:

[ code ]
your code here
[ /code ]

but delete the extra spaces I included in the tags after the "[" and before the "]" so that you could see them here. Then it will look like this:


your code here

 
You can edit your post above to include them.

Cheers and Regards

Edited by bphlpt

Share this post


Link to post
Share on other sites

@ghosttracer,

 

Have you tried running the script 'as Administrator'

 

Please take note of bphlpt's post above, I shouldn't have to edit another of your posts for that reason again!

Share this post


Link to post
Share on other sites

This is what I suspect with the script coming to a halt. This part

(program ends after this)IF /i %AVG% == Y (

can leave %AVG% unprotected i.e. %AVG% could be a space as jaclaz warned in post #7. So the line evaluated by the interpreter could become

(program ends after this)IF /i == Y (

which would generate a syntax error. The comparison becomes invalid if %AVG% is interpreted to being nothing or some other reason that cause it to fail.

 

To know for sure, run the script from an already open administrator command prompt and repeat input you did to cause the failure. Redirect the stderr stream from the command to a file like below...

Installscript.cmd 2> stderr.txt

stderr.txt will contain the error output if a syntax error occured. You can skip the redirection if you like as the already open prompt should show the error as it will stay open after the error.

 

Also note that you are choosing the option to install Libre Office if MS Office is installed. This condition is opposite to your previous code.

Share this post


Link to post
Share on other sites

@Mhz

My guess is that the batch exits/terminates before that. :unsure:

 

@ghosttracer

I would also test this snippet:

SET "_OSV="FOR /F "TOKENS=1* DELIMS=[" %%A IN ('VER') DO (SET "_OSV=%%B"CALL SET "_OSV=%%_OSV:* =%%" & CALL SET "_OSV=%%_OSV:~,3%%")IF %_OSV% LSS 5.1 GOTO :EOFIF %_OSV% LSS 6.0 (ECHO= Installing Internet Explorer 8IE8-WindowsXP-x86-ENU.exe /passive /update-no /no-default /norestart) ELSE (ECHO= Internet Explorer 8 Not Required & ECHO= Disabling HibernationPOWERCFG -h off)

after having modified it in such a way that you understand what actually happens, like (example):

SET "_OSV="
FOR /F "TOKENS=1* DELIMS=[" %%A IN ('VER') DO (

SET "_OSV=%%B"
CALL SET "_OSV=%%_OSV:* =%%" & CALL SET "_OSV=%%_OSV:~,3%%"

)

SET _OSV&PAUSE
IF %_OSV% LSS 5.1 ECHO %_OSV% is LSS than 5.1&GOTO :EOF
IF %_OSV% LSS 6.0 (

ECHO %_OSV% is LSS than 6.0
) ELSE (
ECHO %_OSV% is NOT LSS than 6.0

)

 

 

And, I would start the batch with:

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS

 

 

jaclaz

Share this post


Link to post
Share on other sites

@ghosttracer, as a new batch programmer, you should absolutely thoroughly test each batch, and each line if necessary, until you understand what is happening and why as jaclaz suggests.

The beauty, and the curse, of batch, and most other programming languages for that matter, is that there are many, many different ways to accomplish the same thing.  For example, to find the OS version, these 3 lines give the exact same results for me running Win7x64:

:: from YzöwlSET "_OSV=" & FOR /F "TOKENS=1* DELIMS=[" %%A IN ('VER') DO SET "_OSV=%%B" & CALL SET "_OSV=%%_OSV:* =%%" & CALL SET "_OSV=%%_OSV:~,3%%"
:: from jaclaz from http://www.robvanderwoude.com/files/appcompat_w7.txtSET "_OSV=" & FOR /F "TOKENS=*" %%A IN ('VER') DO FOR %%B IN (%%A) DO FOR /F "TOKENS=1,2 DELIMS=[]." %%C IN ("%%~B") DO SET "_OSV=%%C.%%D"
:: my personal favoriteSET "_OSV=" & FOR /f "TOKENS=2 DELIMS=[]" %%A IN ('VER') DO FOR /f "TOKENS=2,3 DELIMS=. " %%B IN ("%%~A") DO SET "_OSV=%%B.%%C"

You should also do as Yzöwl asked and confirm if your script operates correctly if it is run as an administrator. If it does, then a solution something like this might work for you:
 

@ECHO OFF:: Ensure ADMIN Privileges - from http://www.robvanderwoude.com/clevertricks.php:: adaptation of https://sites.google.com/site/eneerge/home/BatchGotAdmin and http://stackoverflow.com/q/4054937:: Check for ADMIN Privileges >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"IF '%errorlevel%' NEQ '0' ( REM Get ADMIN Privileges    ECHO= Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"    ECHO= UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"    "%temp%\getadmin.vbs"    DEL "%temp%\getadmin.vbs"    EXIT /B) ELSE ( REM Got ADMIN Privileges    PUSHD "%CD%"    CD /D "%~dp0"):: END - Ensure ADMIN Privileges:: PrelimsSETLOCAL ENABLEDELAYEDEXPANSION  ENABLEEXTENSIONSSET "_OSV=" & FOR /f "TOKENS=2 DELIMS=[]" %%A IN ('VER') DO FOR /f "TOKENS=2,3 DELIMS=. " %%B IN ("%%~A") DO SET "_OSV=%%B.%%C"IF %_OSV% LSS 5.1 ECHO= This requires XP or greater & EXIT /bSET "_Arch=x64" & IF %PROCESSOR_ARCHITECTURE%==x86 IF NOT DEFINED PROCESSOR_ARCHITEW6432 SET "_Arch=x86"ECHO PLease specify if the following programs needs to be installed. y for yes and n for noSET "AVG=N" & SET /p AVG=Do you want to Install AVG(Y/N)SET "LIBRE=N" & IF EXIST "%PROGRAMFILES%\Microsoft Office\" (    ECHO Microsoft Office Detected & SET /p LIBRE=Do you want to Install Libre Office(Y/N)):: Begin work:: Installsecho Installing Firefox & ffox29.exe -msecho Installing Ashampoo & ashampoo.exe /sp- /verysilent /norestartecho Installing C-Cleaner & ccsetup.exe /Secho Installing K-lite & klite.exe /verysilent /norestartEcho Adding Reg Key for No Autorun & NOAUTORUN.regEcho Installing Adobe Reader & adobe11.exe  /sPB /sAll /msi /norestart ALLUSERS=1 EULA_ACCEPT=YESEcho Installing Adobe Reader Update & AdbeRdrUpd11006_MUI.msp /qp /norestartIF %_OSV% LSS 6.0 (    ECHO= Installing Internet Explorer 8 & IE8-WindowsXP-x86-ENU.exe /passive /update-no /no-default /norestart) ELSE (    ECHO= Internet Explorer 8 Not Required & ECHO= Disabling Hibernation & POWERCFG -h off)IF /i "%AVG:~,1%." == "Y." (    echo Installing AVG%_Arch% & avg%_Arch% /UILevel=silent /InstallToolbar=0 /ChangeBrowserSearchProvider=0 /SelectedLanguage=1033 /InstallSidebar=0 /ParticipateProductImprovement=0 /DontRestart /KillProcessesIfNeeded) Else (    echo AVG Installation Skipped)IF /i "%LIBRE:~,1%." == "Y."(    Echo Installing Libre Office & LibreOffice_4.2.3_Win_x86.msi ALLUSERS=1 /q /norestart) Else (     echo Libre Office Installation Skipped):: TweaksEcho Renaming Icons...Ren "%USERPROFILE%\Desktop\CCleaner.lnk" "Run Weekly.lnk"Ren "%USERPROFILE%\Desktop\Mozilla Firefox.lnk" "Internet.lnk"Echo Renaming Doneecho Disabling System RestoreReg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" /v DisableSR /t REG_DWORD /d 1 /fsc config srservice start= disablednet stop srservice:: CleanupFOR %%A IN (    ffox29.exe    ccsetup.exe    adobe11.exe    klite.exe    IE8-WindowsXP-x86-ENU.exe    NOAUTORUN.reg    Install V1.1.bat    ashampoo.exe    avgx64.exe    avgx86.exe    LibreOffice_4.2.3_Win_x86.msi    AdbeRdrUpd11006_MUI.msp  ) DO (    ECHO Deleting file %%A ..... & DEL %%A)echo Operation Completeexit /b

I tried to include everyone's suggestions up till now where I thought was appropriate. I also changed your detection of the OS architecture slightly to make it more robust and then utilized the result to simplify the AVG installation. I changed your AVG and LIBRE tests to only check for the first letter of the responses given so that any response that starts with the letter "Y" is interpreted as a "YES".

Other tips--
You should make the capitalization you use and the indentation and the rest of the program syntax consistent throughout the program to make reading it easier and make typo's stand out more when you make them, and you will make them. Also, you should probably rename "Install V1.1.bat" to "Install_V1.1.cmd" or something, because batch files are now usually named with a .cmd instead of .bat extension as jaclaz mentioned, and it is also a safer practice, especially when dealing with batch programs, to not have any whitespace in the file name or path. When you use pieces of code you get from someone else, you should be should be sure to give credit where credit is due. That will also give you someone else to blame if it doesn't work. :)

I have not tested the above code as a single unit, but only parts of it at a time, so be sure to test it thoroughly before use on a real system.

Cheers and Regards

Edited by bphlpt

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...