Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 23rd September 2009, 03:30   #1
Panarchy
Member
 
Join Date: Nov 2008
Posts: 72
Question Scheduled Tasks - How to create some with if & else?

Hello

I'm trying to implement some Scheduled Tasks.

These are for backups, and link to .bat scripts.

There are two kind of Batch scripts in-use;[list=1][*]One that backs-up data to the I:\ drive[*]One that backs up data to the N:\ drive[/list=1]
I'll include both scripts within the one NSIS installer. All servers have an I:\ drive, however only about half of them have the N:\ drive. Here is an idiosyncratic-programming way of showing you what I'd like;
code:
If N:\ exists, extract nDrive-Script.bat to the Backup-Scripts directory
code:
else extract iDrive-Script.bat to the Backup-Scripts directory.

Can you please give me an example script which;
  • Extracts the batch files based on existing directories
  • Installs them as Scheduled Tasks which run at a certain specified time & date
Thanks in advance,

Panarchy

BTW: Backup-Scripts folder is located in T:\Backup-Scripts
Panarchy is offline   Reply With Quote
Old 23rd September 2009, 06:50   #2
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 546
To check if the drive exist, you can use IfFileExists, or ${If} ${FileExists} with the LogicLib header.
For scheduled tasks:
http://nsis.sourceforge.net/Scheduled_Tasks
jpderuiter is offline   Reply With Quote
Old 23rd September 2009, 21:54   #3
Panarchy
Member
 
Join Date: Nov 2008
Posts: 72
Arrow

I have written some code, below which SHOULD do the first part (everything but install the new Scheduled Tasks).

http://pastebin.com/f9bcd502

I can't get the aforementioned code to compile correctly.

Here is the output of the compiler;

http://codepad.org/YuaKjt4o

Please help me fix the script.

Thanks in advance,

Panarchy
Panarchy is offline   Reply With Quote
Old 24th September 2009, 05:51   #4
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,841
Err... The compiler is already telling you what is wrong.
'Error: could not resolve label "PastIBackupsCheck" in function ".onInit"'

You tell it to go to a label that doesn't exist.
MSG is offline   Reply With Quote
Old 25th September 2009, 01:54   #5
Panarchy
Member
 
Join Date: Nov 2008
Posts: 72
Problem solved!

Thanks, I found a better example online, and it is now this;

code:
Function .onInit
IfFileExists "I:\Backups" 0 continue
MessageBox MB_YESNO|MB_ICONQUESTION "Does I:\Backups exist?" IDYES true IDNO continue
true:
!macro ExtractiBackupScripts ToDir
SetOutPath `${ToDir}`
File "Contig.exe"
File "Defrag.cmd"
File "NTBackup.cmd"
!macroend
!insertmacro ExtractiBackupScripts "T:\Backup-Scripts\"

continue:
!macro ExtractnBackupScripts ToDir
SetOutPath `${ToDir}`
File "Contig.exe"
File "NTBackup-2009.cmd"
!macroend
!insertmacro ExtractnBackupScripts "T:\Backup-Scripts\"

FunctionEnd



Which seems to work fine... however I'd like to remove the prompt, and make it continue automatically based on existence of the drive letter/directory.

Also I'll need to add the Scheduled Tasks... which from the looks of things is very confusing. Hopefully I won't have to end up with "ExecWait"ing a Batch!!!

Please tell me how I can fix up my function.

Thanks in advance,

Panarchy

EDIT;

Might of fixed it with:

code:
Section /o "N:\Backups detected" nBackups_detected
nBackupsExists:
SectionGetFlags "${nBackups_detected}" $0
IntOp $0 $0 | ${SF_SELECTED}
SectionSetFlags "${nBackups_detected}" $0
MessageBox MB_OK nBackups
!macro ExtractnBackupscripts ToDir
SetOutPath `${ToDir}`
File "Contig.exe"
File "Defrag.cmd"
File "NTBackup.cmd"
!macroend
!insertmacro ExtractnBackupscripts "T:\Backup-Scripts"

PastnBackupsCheck:
!macro ExtractiBackupScripts ToDir
SetOutPath `${ToDir}`
File "Contig.exe"
File "NTBackup-2009.cmd"
!macroend
!insertmacro ExtractiBackupScripts "T:\Backup-Scripts\c"

SectionEnd




EDIT2: Ended up fixing the issue, now just need to work out how to add Scheduled Tasks...

Last edited by Panarchy; 25th September 2009 at 02:32.
Panarchy is offline   Reply With Quote
Old 25th September 2009, 05:53   #6
Panarchy
Member
 
Join Date: Nov 2008
Posts: 72
They ended up not wanting it, so I've got a half-finished script here. Works perfectly, however doesn't install any Scheduled Tasks.

Enjoy

Panarchy

code:
!include Sections.nsh

Name Scheduled Backups
OutFile "Scheduled Backups.exe"
InstallDir "T:\Backup-Scripts"

XPStyle on

Page components

Page instfiles
ShowInstDetails show

Section "Backup Scripts"
!macro ExtractBackupScripts ToDir
SetOutPath `${ToDir}`
File "Contig.exe"
File "Defrag.cmd"
File "NTBackup-2009.cmd"
File "NTBackup.cmd"
!macroend
SectionEnd
; The following section removes old Scheduled Tasks
Section
!macro GetCleanDir INPUTDIR
; ATTENTION: USE ON YOUR OWN RISK!
; Please report bugs here: http://stefan.bertels.org/
!define Index_GetCleanDir 'GetCleanDir_Line${__LINE__}'
Push $R0
Push $R1
StrCpy $R0 "${INPUTDIR}"
StrCmp $R0 "" ${Index_GetCleanDir}-finish
StrCpy $R1 "$R0" "" -1
StrCmp "$R1" "\" ${Index_GetCleanDir}-finish
StrCpy $R0 "$R0\"
${Index_GetCleanDir}-finish:
Pop $R1
Exch $R0
!undef Index_GetCleanDir
!macroend

!macro RemoveFilesAndSubDirs DIRECTORY
!define Index_RemoveFilesAndSubDirs 'RemoveFilesAndSubDirs_${__LINE__}'

Push $R0
Push $R1
Push $R2

!insertmacro GetCleanDir "${DIRECTORY}"
Pop $R2
FindFirst $R0 $R1 "$R2*.*"
${Index_RemoveFilesAndSubDirs}-loop:
StrCmp $R1 "" ${Index_RemoveFilesAndSubDirs}-done
StrCmp $R1 "." ${Index_RemoveFilesAndSubDirs}-next
StrCmp $R1 ".." ${Index_RemoveFilesAndSubDirs}-next
IfFileExists "$R2$R1\*.*" ${Index_RemoveFilesAndSubDirs}-directory
; file
Delete "$R2$R1"
goto ${Index_RemoveFilesAndSubDirs}-next
${Index_RemoveFilesAndSubDirs}-directory:
; directory
RMDir /r "$R2$R1"
${Index_RemoveFilesAndSubDirs}-next:
FindNext $R0 $R1
Goto ${Index_RemoveFilesAndSubDirs}-loop
${Index_RemoveFilesAndSubDirs}-done:
FindClose $R0

Pop $R2
Pop $R1
Pop $R0
!undef Index_RemoveFilesAndSubDirs
!macroend
!insertmacro RemoveFilesAndSubDirs "$WINDIR\tasks\"
SectionEnd
; The above section removes all Scheduled Tasks

Function .onInit
IfFileExists "I:\" 0 continue
MessageBox MB_OKCANCEL|MB_ICONQUESTION "I've cheated the Message box with this, right?" IDOK true IDNO continue
true:
!macro ExtractiBackupScripts ToDir
SetOutPath `${ToDir}`
File "Contig.exe"
File "Defrag.cmd"
File "NTBackup.cmd"
!macroend
!insertmacro ExtractiBackupScripts "T:\Backup-Scripts"

continue:
!macro ExtractnBackupScripts ToDir
SetOutPath `${ToDir}`
File "Contig.exe"
File "NTBackup-2009.cmd"
!macroend
!insertmacro ExtractnBackupScripts "T:\Backup-Scripts"

FunctionEnd

Panarchy is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump