How to limit the number of text box characters in NSIS - nsis

I want to limit the number of characters in each text box to 4 digits.
It can be implemented in C # Winform, but it is not familiar with how to use it in NSIS.
Attempted action:
I put the label and I am guiding the input to four digits.
But that's not good.
I tried to find information through the NSIS forum, but I could not find it.
Attach text box image :
text box
NSIS code:
Function Test
!insertmacro MUI_INSTALLOPTIONS_READ $0 "pageInputLicenseInfo.ini" "Settings" "State"
${If} $0 == 9 # btton
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "pageInputLicenseInfo.ini" "Field 1" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "pageInputLicenseInfo.ini" "Field 2" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $R2 "pageInputLicenseInfo.ini" "Field 3" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $R3 "pageInputLicenseInfo.ini" "Field 4" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $R4 "pageInputLicenseInfo.ini" "Field 5" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $R5 "pageInputLicenseInfo.ini" "Field 6" "State"
nsExec::ExecToStack '$INSTDIR\ParamterTestConsole.exe ${PRODUCT_NAME} $R0 $R1$R2$R3$R4$R5'
Pop $2 ; Exit code
Pop $3 ; console OUTPUT
Blah blah..........
FunctionEnd
NSIS INI File:
; Ini file generated by the HM NIS Edit IO designer.
[Settings]
NumFields=14
Title=test
[Field 1]
Type=Text
Text=1
Left=29
Right=275
Top=46
Bottom=57
[Field 2]
Type=Text
Text=123
Left=30
Right=60
Top=67
Bottom=78
[Field 3]
Type=Text
Text=123
Left=74
Right=103
Top=67
Bottom=78
[Field 4]
Type=Text
Text=123
Left=121
Right=149
Top=67
Bottom=78
[Field 5]
Type=Text
Text=123
Left=164
Right=193
Top=67
Bottom=78
[Field 6]
Type=Text
Text=123
Left=206
Right=236
Top=67
Bottom=78
[Field 7]
Type=Label
Text=IP
Left=1
Right=15
Top=48
Bottom=56
[Field 8]
Type=Label
Text=Key
Left=1
Right=20
Top=70
Bottom=78
[Field 9]
Type=Button
Text=enter
Flags=NOTIFY
Left=225
Right=275
Top=92
Bottom=105
[Field 10]
Type=Label
Text=※
Enter four digits.
Left=0
Right=152
Top=26
Bottom=43
[Field 11]
Type=Label
Text=-
Left=154
Right=160
Top=68
Bottom=80
[Field 12]
Type=Label
Text=-
Left=199
Right=205
Top=68
Bottom=76
[Field 13]
Type=Label
Text=-
Left=110
Right=116
Top=68
Bottom=76
[Field 14]
Type=Label
Text=-
Left=64
Right=70
Top=68
Bottom=76
Please help me.

As mentioned in the documentation, you can make use of the MaxLen option.
Example:
[Field 1]
Type=Text
Text=1
Left=29
Right=275
Top=46
Bottom=57
MaxLen=4

Related

NSIS not displaying new control after change ui

I took ui.cpp and default.rc from the svn, compiled it, used changeui ---> works!
I can't display new controls. This is a section from the new default.rc
IDD_LICENSE DIALOGEX 0, 0, 266, 130 STYLE DS_FIXEDSYS | DS_CONTROL | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
ICON IDR_MAINFRAME,IDR_MAINFRAME,0,0,22,20
LTEXT "pppppppppppppppppppppp",507,25,0,241,23
LTEXT "email user",508, 172, 106, 233, 31
CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL |
WS_TABSTOP | 0x804,0,24,266,105
END
In the nsh script, on create function of a page I tried:
GetDlgItem $MyHandle $HWNDPARENT507
MessageBox MB_OK $MyHandle //this is always 0 no matter what I tried in the previous line!!!
EnableWindow $MyHandle 1
I also tried editing the original defalt.exe with resource hacker but nsis wouldn't display new text/control.
How can I display the new text and control???
The NSIS GUI is actually one dialog window with another dialog window inside it.
You first need to find the inner dialog before you can find the controls in it:
FindWindow $0 "#32770" "" $HWNDPARENT ; Find the inner dialog (See attached picture)
GetDlgItem $MyHandle $0 507 ; Find the control
Complete example:
!define ResHacker "$%localappdata%\Programs\ResHacker.exe" ; TODO: Adjust this path
!define myui "${__FILE__}\..\mytempui.exe"
!tempfile res
!tempfile rc
!delfile "${rc}"
!delfile "${res}"
!define /redef rc "${res}.rc"
!define /redef res "${res}.res"
!appendfile "${rc}" '#define IDD_LICENSE 102$\r$\n'
!appendfile "${rc}" '#define IDC_EDIT1 1000$\r$\n'
!appendfile "${rc}" '#define RICHEDIT_CLASS "RichEdit20W"$\r$\n'
!appendfile "${rc}" 'LANGUAGE 0x09, 0x01$\r$\n'
!appendfile "${rc}" 'IDD_LICENSE DIALOGEX 0, 0, 266, 130$\r$\n STYLE DS_FIXEDSYS | DS_CONTROL | WS_CHILD$\r$\n'
!appendfile "${rc}" 'FONT 8, "MS Shell Dlg", 0, 0, 0x1$\r$\n'
!appendfile "${rc}" 'BEGIN$\r$\n'
!appendfile "${rc}" ' LTEXT "pppppppppppppppppppppp",507,25,0,241,23,SS_LEFT|WS_VISIBLE$\r$\n'
!appendfile "${rc}" ' LTEXT "email user",508, 172, 106, 233, 31,SS_LEFT|WS_VISIBLE$\r$\n'
!appendfile "${rc}" ' CONTROL "",IDC_EDIT1,RICHEDIT_CLASS,WS_BORDER | WS_VSCROLL | WS_TABSTOP|WS_VISIBLE | 0x804,0,24,266,55$\r$\n'
!appendfile "${rc}" 'END$\r$\n'
!system '"${ResHacker}" -open "${rc}" -save "${res}" -action compile -log CON' = 0
!delfile "${rc}"
!system '"${ResHacker}" -open "${NSISDIR}\Contrib\UIs\default.exe" -save "${myui}" -action addoverwrite -res "${res}" -mask DIALOG,102,1033 -log CON' = 0
!delfile "${res}"
ChangeUI IDD_LICENSE "${myui}"
Page License "" MyLicShow
Page InstFiles
!include WinMessages.nsh
Var MyHandle
Function MyLicShow
FindWindow $0 "#32770" "" $HWNDPARENT ; Find the inner dialog (See attached picture)
GetDlgItem $MyHandle $0 507 ; Find the control
SendMessage $MyHandle ${WM_SETTEXT} "" "STR:New control text"
SetCtlColors $MyHandle ff0000 transparent
FunctionEnd

Whats wrong with my 2nd call to ReadINIStr?

I am a newbiew to NSIS. Trying to build a little sample that help to understand the techniques that I'd like to use in the production-installer that's build eventually...
I'd like to build a silent-installer that gets its parameter from an .INI-File with multiple section. Want to specific the section the command-line of the installer.
So, I have this NSIS-TEST.INI-File:
[PROD]
PATHONE=c:\Folder\Foo
AppName=My little stupid app
The idea is to have command-line like this:
FooSetup config=prod
The actual setup NSIS-TEST.NSI is:
; Script generated by the HM NIS Edit Script Wizard.
var /global REGAPPKEY
var /global PRODUCT_DIR_REGKEY
; HM NIS Edit Wizard helper defines
!define REG_APPKEY ""
!define config "PROD"
!define PATHONE ""
!define PRODUCT_NAME "foo"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "foo"
!define PRODUCT_WEB_SITE "http://www.example.com"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "FooSetup.exe"
InstallDir "c:\foo-goo"
Icon "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
;SilentInstall silent
;SilentUninstall silent
;InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
Section -aHauptgruppe SEC01
ReadINIStr $REGAPPKEY $INSTDIR\nsis-test.ini ${config} "AppName"
ReadINIStr $PATHONE $INSTDIR\nsis-test.ini ${config} "PATHONE"
;MessageBox MB_ICONINFORMATION|MB_OK "config=${config}"
;SetOutPath "$INSTDIR"
;SetOverwrite ifnewer
; File "..\..\..\pfad\zur\datei\AppMainExe.exe"
; CreateDirectory "$SMPROGRAMS\foo"
; CreateShortCut "$SMPROGRAMS\foo\foo.lnk" "$INSTDIR\AppMainExe.exe"
; CreateShortCut "$DESKTOP\foo.lnk" "$INSTDIR\AppMainExe.exe"
; File "..\..\..\path\to\file\Example.file"
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\foo\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\foo\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
;WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\AppMainExe.exe"
;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\AppMainExe.exe"
;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd
Function un.onUninstSuccess
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) wurde erfolgreich deinstalliert."
FunctionEnd
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "M�chten Sie $(^Name) und alle seinen Komponenten deinstallieren?" IDYES +2
Abort
FunctionEnd
Section Uninstall
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\Example.file"
Delete "$INSTDIR\AppMainExe.exe"
Delete "$SMPROGRAMS\foo\Uninstall.lnk"
Delete "$SMPROGRAMS\foo\Website.lnk"
Delete "$DESKTOP\foo.lnk"
Delete "$SMPROGRAMS\foo\foo.lnk"
RMDir "$SMPROGRAMS\foo"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
;DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
FooSetup config=prod
If I compile this, the last lines of the output are:
Section: "-aHauptgruppe" ->(SEC01)
ReadINIStr $REGAPPKEY [PROD]:AppName from $INSTDIR\nsis-test.ini
Usage: ReadINIStr $(user_var: output) ini_file section entry_name
Error in script "c:\blabla\setup2019\nsis-test.nsi" on line 29 -- aborting creation process
So it has processed the first of my ReadINIStr-Instructions and barfed on the second one. I have looked at this code for hours, have injected line-feed etc., but I can't see what's so different about the 2nd instruction...
$PATHONE is not a variable. You're missing:
Var PATHONE
Note you do have:
!define PATHONE ""
So be careful not getting the two confused.

source nsis setup have virus

I Have nsis source setup ajax file and clean the internet explorer becose sameone use file dll to block me
the file when i go to virustotal i get to virus i don't know where the problem can anyone help me
this is the source
; saudivoice NSIS Installer Script File
; khaild Winston <babh532#gmail.com>
;--------------------------------
;Include some predefined NSIS libraries
!include "WinMessages.nsh"
; --------------------
XPStyle on
; LANG: 1033
LangString LSTR_43 1033 "Show &details"
LangString LSTR_44 1033 Completed
; --------------------
;General
;Name and file
Name "SaudiVoice"
;Default installation folder
InstallDir "$PROGRAMFILES\SaudiVoice"
; --------------------
; PAGES: 3
; Page 0
Page license /ENABLECANCEL
LicenseText "Welcome to the Saudivoice Voice Setup." Next
LicenseData [LICENSE].txt
; Page 1
Page instfiles
CompletedText $(LSTR_44) ; Completed
DetailsButtonText $(LSTR_43) ; "Show &details"
/*
; Page 2
Page COMPLETED
*/
; --------------------
; --------------------
; SECTIONS: 1
;Installer Sections
Section "Install saudivoice"
SetOutPath "$INSTDIR"
; Copy all of the required files (note the /r switch to recursively copy directories)
File chat5.ocx
File chat5.dll
File chat5.inf
File setup.bat
File IMSVoiceStarter.exe
File npIMSChatStarter.dll
File Readme.htm
; Register the COM server
ClearErrors
RegDLL $INSTDIR\chat5.ocx
RegDLL $INSTDIR\npIMSChatStarter.dll
Exec $INSTDIR\setup.bat
Exec "$PROGRAMFILES\KSAChatControl2017\Firewall\Uninstall.exe /S"
DetailPrint "unInstalling the Block..."
Exec "$PROGRAMFILES\KSAChatControl2017\Firewall14\Uninstall.exe /S"
DetailPrint "unInstalling the Block..."
Exec "$PROGRAMFILES\KSAChatControl2017\2.11.0.0\Uninstall.exe /S"
DetailPrint "unInstalling the Block..."
CreateDirectory $SMPROGRAMS\SaudiVoice
CreateShortCut "$SMPROGRAMS\SaudiVoice\Read Me.lnk" $INSTDIR\Readme.htm
CreateShortCut "$SMPROGRAMS\SaudiVoice\Uninstall SaudiVoice.lnk" $INSTDIR\Uninstall.exe
WriteRegStr HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\SaudiVoice DisplayName "SaudiVoice 1.0.0.1"
WriteRegStr HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\SaudiVoice DisplayVersion 1.0.0.1
WriteRegStr HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\SaudiVoice UninstallString $\"$INSTDIR\Uninstall.exe$\"
WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\SaudiVoice NoModify 1
DeleteRegKey HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\SaudiVoice
WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\SaudiVoice NoRepair 1
DeleteRegKey HKLM "SOFTWARE\Wow6432Node\Microsoft\Code Store Database\Distribution Units\{EB938183-780F-48FD-89ED-50686F7F7259}"
DeleteRegKey HKLM "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\ModuleUsage"
DeleteRegKey HKLM "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\SharedDlls"
DeleteRegKey HKLM "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains"
DeleteRegKey HKLM "SOFTWARE\Microsoft\Code Store Database\Distribution Units\{EB938183-780F-48FD-89ED-50686F7F7259}"
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\ModuleUsage"
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls"
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains"
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges"
DeleteRegKey HKEY_CURRENT_USER "Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges"
DeleteRegKey HKEY_USERS ".DEFAULT\Software\Microsoft\Windows Firewall"
WriteUninstaller $INSTDIR\Uninstall.exe ; $INSTDIR\$INSTDIR\Uninst.exe
SectionEnd
; --------------------
;Uninstaller Section
Section "Uninstall"
Delete "$INSTDIR\Uninstall.exe"
; Unregister the COM server
UnRegDLL "$INSTDIR\chat5.ocx"
Delete "$INSTDIR\chat5.ocx"
Delete "$INSTDIR\chat5.dll"
Delete "$INSTDIR\chat5.inf"
Delete "$INSTDIR\IMSVoiceStarter.exe"
Delete "$INSTDIR\npIMSChatStarter.dll"
Delete "$INSTDIR\Readme.htm"
; Delete all installed files
RMDir "$INSTDIR"
; And registry entries
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SaudiVoice"
Delete "$SMPROGRAMS\SaudiVoice\Read Me.lnk"
Delete "$SMPROGRAMS\SaudiVoice\Uninstall SaudiVoice.lnk"
RMDir $SMPROGRAMS\SaudiVoice
SectionEnd
and this is the file
http://saudidos.com/fix.exe
Please help me for that
The VirusTotal results have a detection ratio of 2 / 55 and the two are Bkav and Invincea and I would go out on a limb and say that these are not well known companies and this is probably a false positive. You could try reporting the false positives...
This isn't the first time this happened to nsis or some related plugins. Just inform those companies or virustotal (chapter "Information we share") will also do that for you (which only may take a while longer)...

Ways to update progress bar

I want to control progressbar in my nsis installer. Actually I'm using ThreadTimer plugin but I've got big problem with it. ThreadTimer runs function every 10 seconds to update progress bar (increace progress bar value by 1%). The problem is that it crashes stack (as I can see ThreadTimer is using the same stack as NSIS). Crashes stack means that when I want to get value from the stack the value is wrong because of ThreadTimer function action. Any ideas? Maybe there are some other ways to update progress bar?
Those are functions/macros which should update progress bar. Macro StartProgressBarIntervalUpdate starts updating progress bar, macro StopProgressBarIntervalUpdate stops doping it.
Var /GLOBAL ProgressBarPosition
Var /GLOBAL ProgressBarParentWindow
Var /GLOBAL ProgressBarItem
Function InitProgressBar
StrCpy $ProgressBarPosition "0"
FindWindow $ProgressBarParentWindow "#32770" "" $HWNDPARENT
GetDlgItem $ProgressBarItem $ProgressBarParentWindow 1004
FunctionEnd
Function UpdateProgressBarTimer
${If} $ProgressBarPosition >= 30000 ; 100% * 300
StrCpy $ProgressBarPosition "0"
${Endif}
IntOp $ProgressBarPosition $ProgressBarPosition + 300
SendMessage $ProgressBarItem ${PBM_SETPOS} $ProgressBarPosition 0
FunctionEnd
!define StartProgressBarIntervalUpdate "!insertmacro StartProgressBarIntervalUpdate"
!macro StartProgressBarIntervalUpdate
Call InitProgressBar
GetFunctionAddress $UpdateProgressBarTimerFunctionAddress UpdateProgressBarTimer
ThreadTimer::Start /NOUNLOAD 20 -1 $UpdateProgressBarTimerFunctionAddress
Sleep 1000
!macroend
!define StopProgressBarIntervalUpdate "!insertmacro StopProgressBarIntervalUpdate"
!macro StopProgressBarIntervalUpdate
ThreadTimer::Stop $UpdateProgressBarTimerFunctionAddress
Sleep 15000
!macroend
Here are sections which uses progressbar
Var /GLOBAL UpdateProgressBarTimerFunctionAddress
Section BeforeMoveData SEC01
${StartProgressBarIntervalUpdate}
Call core.UnpackExeData
SectionEnd
Section OnMoveData SEC02
Call InstallFiles
Call InstallRegistry
Call InstallShortcuts
${StopProgressBarIntervalUpdate}
...
SectionEnd

NSIS: Task Scheduler: Run only if logged on checkbox

I am having issues with setting up a scheduled task with NSIS.
I will not know all of the passwords for the users I am setting up tasks for therefore I need the Run Only if Logged On checkbox checked to get around that.
I do not have access to install other pieces of software onto the computer other than setting up the task so I have to utilize the Windows Task Scheduler preferably.
The task below sets up the task, checks the checkbox however does not run the task set up. It will not run the task until I go and browse to the same file again and then click OK. Now the task wil run just fine. I asked about this behavior in another forum about JT.exe because it does the same thing and was told "It doesn't set the Log on as a batch job User Right that is set by schtasks.exe or the GUI."
I have attempted to create the task and then modify it via the command line. It still does not function.
The goal is to create a Windows XP scheduled task using NSIS (or anything for that matter) that executes properly and checks the Run Only if Logged On checkbox in Task Scheduler 1.0.
Can someone please help?
Here is the current NSIS Script
; Adds a scheduled task running as a different user than the one
; running the installer. Modified from a script by brainsucker
;
; (c) Justin Dearing <zippy1981#gmail.com>, 2006
; (c) brainsucker, 2002
Name "System Plugin Example"
OutFile "Sheduletask.exe"
; TASK_TRIGGER is the struct that sets when your task in run.
; Setting it via the NSIS System plugin is a healthy alternative to
; banging ones head against the wall.
;
; general TASK_TRIGGER structure arguments
; 1, 2 - skip
; 3,4,5 - BEGIN year, month, day
; 6,7,8 - END year, month, day (SHOULD be = 0, if 1 flag is skipped)
; 9, 10 - Start hour, minute
; 11, 12 - Duration and Interval of task in minutes. (duration - the whole
; time task will work, interval - time between runs. D = 120,
; I = 10: task will be runned every 10 minutes for 2 hours).
; 13 - flags (should be ored (|)):
; 1 - task has end date (6,7,8 defined)
; 2 - task will be killed at Duration end
; 4 - task trigger disabled
; 14 - trigger type: there are 7 different types, every one with it own
; structure
; 0 = ONCE task will be runned once
; 5 = On IDLE task will run on system IDLE (ITask->SetIdleWait)
; 6 = At System Startup
; 7 = At Logon
; these types use the following structure (so 7 means trigger at Logon):
; push "*(&l2, &i2 0, &i2 2003, &i2 9, &i2 4, &i2 0, &i2 0, &i2 0, &i2 14, &i2 20, i 0, i 0, i 0, i 7, i 0, &i2 0, i 0, &i2 0) i.s"
; 1 = DAILY - field 15 gives interval in days (here it 15)
; push "*(&l2, &i2 0, &i2 2003, &i2 9, &i2 3, &i2 0, &i2 0, &i2 0, &i2 13, &i2 10, i 0, i 0, i 0, i 1, &i2 15, i 0, i 0, &i2 0) i.s"
; 2 = WEEKLY - field 15 gives interval in weeks (here 17),
; field 16 - shows which days to run (OR them with |):
; Sunday-Saturday (0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40)
; in example monday and friday
; push "*(&l2, &i2 0, &i2 2003, &i2 9, &i2 3, &i2 0, &i2 0, &i2 0, &i2 13, &i2 10, i 0, i 0, i 0, i 2, &i2 13, &i2 0x2|0x20, &i2 0, i 0, &i2 0) i.s"
; 3 = MONTHLYDATE - field 15 bit field of days (OR them) to run
; (0x1-0x40000000),
; field 16 - bit field of month (OR them with |):
; January-December (0x1-0x800)
; in example (3 and 5 days of February and June)
; push "*(&l2, &i2 0, &i2 2003, &i2 9, &i2 3, &i2 0, &i2 0, &i2 0, &i2 13, &i2 10, i 0, i 0, i 0, i 3, i 0x4|0x20, &i2 0x2|0x20, i 0, &i2 0) i.s"
; 4 = MONTHLYDOW - field 15 week of month to run (1-5)
; field 16 - shows which days to run (OR them with |):
; Sunday-Saturday (0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40)
; field 17 - bit field of month (or them with |):
; January-December (0x1-0x800)
; in example (first week, monday and friday of February and June)
; push "*(&l2, &i2 0, &i2 2003, &i2 9, &i2 3, &i2 0, &i2 0, &i2 0, &i2 13, &i2 10, i 0, i 0, i 0, i 4, &i2 1, &i2 0x2|0x20, &i2 0x2|0x20, i 0, &i2 0) i.s"
Function CreateTask
!define GUIDTask "{148BD520-A2AB-11CE-B11F-00AA00530503}"
!define GUIDITask "{148BD524-A2AB-11CE-B11F-00AA00530503}"
!define GUIDTaskScheduler "{148BD52A-A2AB-11CE-B11F-00AA00530503}"
!define GUIDITaskScheduler "{148BD527-A2AB-11CE-B11F-00AA00530503}"
!define GUIDITaskTrigger "{148BD52B-A2AB-11CE-B11F-00AA00530503}"
!define GUIDIPersistFile "{0000010b-0000-0000-C000-000000000046}"
SetPluginUnload alwaysoff
; store registers and pop params
System::Store "S r8r7r5r4r3r2r1r0"
StrCpy $R0 "error" ; result
System::Call "ole32::CoCreateInstance(g '${GUIDTaskScheduler}', i 0, i 11, g '${GUIDITaskScheduler}', *i .R1) i.R9"
IntCmp $R9 0 0 End
; ITaskScheduler->NewWorkItem()
System::Call '$R1->8(w r0, g "${GUIDTask}", g "${GUIDITask}", *i .R2) i.R9'
; IUnknown->Release()
System::Call '$R1->2() i' ; release Task Scheduler object
IntCmp $R9 0 0 End
; ITask->SetComment()
System::Call '$R2->18(w r1)'
; ITask->SetApplicationName()
System::Call '$R2->32(w r2)'
; ITask->SetWorkingDir()
System::Call '$R2->36(w r3)'
; ITask->SetParameters()
System::Call '$R2->34(w r4)'
; ITask->CreateTrigger(trindex, ITaskTrigger)
System::Call '$R2->3(*i .R4, *i .R5)'
; ITask->SetFlags()
System::Call '$R2->28(i 0x2000)'
; allocate TASK_TRIGGER structure
System::Call '$5'
Pop $R6
; ITaskTrigger->SetTrigger
System::Call '$R5->3(i R6)'
; ITaskTrigger->Release
System::Call '$R5->2()'
; free TASK_TRIGGER structure
System::Free $R6
; ITask->SetAccountInformation
System::Call '$R2->30(w r7, w r8)'
; IUnknown->QueryInterface
System::Call '$R2->0(g "${GUIDIPersistFile}", *i .R3) i.R9' ; QueryInterface
; IUnknown->Release()
System::Call '$R2->2() i' ; release Task object
IntCmp $R9 0 0 End
; IPersistFile->Save
System::Call '$R3->6(i 0, i 1) i.R9'
; release IPersistFile
System::Call '$R3->2() i'
IntCmp $R9 0 0 End
StrCpy $R0 "ok"
End:
; restore registers and push result
System::Store "P0 l"
; last plugin call must not have /NOUNLOAD so NSIS will be able to delete the temporary DLL
SetPluginUnload manual
; do nothing
System::Free 0
FunctionEnd
Section "SiteSecureBackup"
SetOutPath $TEMP
push "Test Task"
push "Testing the Task"
push "C:\file.exe"
push "C:\"
push ""
push \
"*(&l2, &i2 0, \
&i2 2006, &i2 1, &i2 1, \
&i2 0, &i2 0, &i2 0, \
&i2 0, &i2 0, \
i 0, i 0, \
i 0, \
i 1, \
&i2 1, &i2 00, &i2 0, i 0, &i2 0) i.s"
push "Username"
push "Userpassword"
Call CreateTask
Pop $0
;MessageBox MB_OK "Scheduled task creation result: $0"
SectionEnd
; eof
WinXP Log on as a batch job documentation says "In Windows 2000 Server, Windows 2000 Professional, and Windows XP Professional, the Task Scheduler automatically grants this right as necessary"
After skimming the docs, the only thing that jumps out at me is "If you set the TASK_FLAG_RUN_ONLY_IF_LOGGED_ON flag, you may also set pwszPassword to NULL for local or domain user accounts. Use the IScheduledWorkItem::SetFlags method to set the flag" (This makes sense, if the user is logged on, there is no need for a password)
Doesn't the
; ITask->SetFlags()
System::Call '$R2->28(i 0x2000)'
does the job? the 28 is the SetFlags index and 0x2000 is the TASK_FLAG_RUN_ONLY_IF_LOGGED_ON.

Resources