Close All Browser In Nsis - cross-browser

Making A Code Which Will Close All opened Browser in nsis.
var hadBrowsers
Function closeAllBrowsers
FindWindow $0 "IEFrame"
IntCmp $0 0 0 closeAll
FindWindow $0 "MozillaUIWindowClass"
IntCmp $0 0 0 closeAll
FindWindow $0 "Chrome_WidgetWin_0"
IntCmp $0 0 done closeAll
closeAll:
MessageBox MB_OK "Please close your browsers or press ok to close them all automatically"
;Closing all IE Windows
loop:
FindWindow $0 "IEFrame"
IntCmp $0 0 skipIE
IsWindow $0 0 skipIE
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_CLOSE},0,0)'
StrCpy $hadBrowsers "1"
skipIE:
FindWindow $0 "MozillaUIWindowClass"
IntCmp $0 0 skipFF
IsWindow $0 0 skipFF
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_CLOSE},0,0)'
StrCpy $hadBrowsers "1"
skipFF:
FindWindow $0 "Chrome_WidgetWin_0"
IntCmp $0 0 skipGC
IsWindow $0 0 skipGC
System::Call 'user32::PostMessageA(i,i,i,i) i($0,${WM_CLOSE},0,0)'
StrCpy $hadBrowsers "1"
skipGC:
FindWindow $0 "IEFrame"
IntCmp $0 0 0 wait
FindWindow $0 "MozillaUIWindowClass"
IntCmp $0 0 0 wait
FindWindow $0 "Chrome_WidgetWin_0"
IntCmp $0 0 done wait
wait:
Sleep 100
goto loop
done:
;MessageBox MB_OK $hadBrowsers
StrCmp $hadBrowsers "1" 0 +1
Sleep 2000
FunctionEnd
this is not working .
Giving me some error.
I am trying to make a code in nsis which will close all opened browser and reopen them.

I got Answer
Section
Execwait '"$SYSDIR\taskkill.exe" /F /IM chrome.exe /T'
SectionEnd
we can kill any task.

Related

expect script's puts is printing on wrong position

I am using below expect script on a linux machine, to run command(s) on a remote device via ssh, and printing its output back on the linux machine where script ran.
#!/usr/bin/expect -f
set fp [open "~/passwfile" r]
set data [read $fp]
set host [lindex $argv 0];
set prompt [lindex $argv 1];
set timeout 10
spawn ssh $host
while {1} {
expect \
{
"*(yes/no)? " {send "yes\r"}
"*assword:" {send "$data\r"}
"*$host*$prompt" {break}
timeout {exit 2}
eof {puts "\rBreaking - EOF\r"; exit 1}
}
}
for {set i 2} {$i <= [llength $argv]} {incr i 1} {
if {$i < [llength $argv]} {puts "";puts ""; puts "\r## command [expr {$i - 1}] start ##"}
send "\r"
expect \
{
"*$host*$prompt" {send "[lindex $argv $i]\r"}
timeout {exit 4}
eof {puts "\rBreaking - EOF\r"; exit 3}
}
while {1} {
expect \
{
"*$host*$prompt" {break}
"Press <SPACE> to continue or <Q> to quit:" {send " "}
"(more" {send " "}
"More-" {send " "}
"ESC->exit" {send "\x1b\r"}
timeout {exit 4}
eof {puts "\rBreaking - EOF\r"; exit 3}
}
}
if {$i < [llength $argv]} {puts "\r## command [expr {$i - 1}] finish ##"}
}
send "exit\r"
puts ""
exit 0
It takes hostname, prompt character and command(s), as parameters.
Example
$ ./expectssh bcr03a.dal10 "#" "sh int et1/8"
I need each command's output to be printed between its own start and finish lines. For above example this is the expected output:
.
.
.
bcr03a.dal10#
## command 1 start ##
bcr03a.dal10# sh int et1/8
Ethernet1/8 is up
admin state is up, Dedicated Interface
Belongs to Po106
Hardware: 40000/100000 Ethernet, address: 70d3.7962.898c (bia 70d3.7962.898c)
MTU 9216 bytes, BW 100000000 Kbit, DLY 10 usec
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, medium is broadcast
Port mode is trunk
full-duplex, 100 Gb/s, media type is 100G
Beacon is turned off
Auto-Negotiation is turned off
Input flow-control is off, output flow-control is off
Auto-mdix is turned off
Rate mode is dedicated
Switchport monitor is off
EtherType is 0x8100
EEE (efficient-ethernet) : n/a
admin fec state is auto, oper fec state is cl91
Last link flapped 59week(s) 4day(s)
Last clearing of "show interface" counters never
2 interface resets
Load-Interval #1: 30 seconds
30 seconds input rate 249767432 bits/sec, 25786 packets/sec
30 seconds output rate 178732832 bits/sec, 25343 packets/sec
input rate 249.77 Mbps, 25.79 Kpps; output rate 178.73 Mbps, 25.34 Kpps
Load-Interval #2: 5 minute (300 seconds)
300 seconds input rate 335318184 bits/sec, 24583 packets/sec
300 seconds output rate 197360256 bits/sec, 25510 packets/sec
input rate 335.32 Mbps, 24.58 Kpps; output rate 197.36 Mbps, 25.51 Kpps
RX
455840060118 unicast packets 436446550 multicast packets 87396954 broadcast packets
456363082369 input packets 585827288945618 bytes
37037870002 jumbo packets 0 storm suppression packets
0 runts 0 giants 0 CRC/FCS 0 no buffer
0 input error 0 short frame 0 overrun 0 underrun 0 ignored
0 watchdog 0 bad etype drop 0 bad proto drop 0 if down drop
0 input with dribble 0 input discard
0 Rx pause
TX
431362512003 unicast packets 2143469193 multicast packets 555138516 broadcast packets
434061134995 output packets 489379806337887 bytes
19176210395 jumbo packets
0 output error 0 collision 0 deferred 0 late collision
0 lost carrier 0 no carrier 0 babble 0 output discard
0 Tx pause
bcr03a.dal10#
## command 1 finish ##
Interesting part is I am receiving this expected output sometimes, but some other times the "## command 1 finish ##" line is being printed earlier. Usually 2 or 3 lines above the "RX" line, on above expected output snippet.
Can you please help me to fix this random behavior?

NSIS – Error MySql with Redirection using nsEXEC::ExecToStack --- Why is ExecToLog vs ExecToStack different errors

I have search forums over too many days the test results can be repeated.
[QUESTION]
What causes the MySQL failure and/or the CMD parsing error of directory name?
[NSIS Script follows]
importdbs:
DetailPrint "IMPORT SQL files to db=$dbname User=$login Pswd=$password"
StrCpy $1 "$folder\bin\mysql.exe"
StrCpy $2 "$srcepath$srcescript"
DetailPrint "MySqlDir: $1 input: $2"
ClearErrors
nsExec::ExecToStack /OEM '"$SYSDIR\cmd.exe" /C "$1" -u$root -p -v -D $dbname < "$2" > "c:\_temp-c\ckprnout.txt"'
Pop $3 # Get Results
StrCmp "error" $3 +1 +2
DetailPrint "IMPORT return-error: $3"
DetailPrint "IMPORT return-OK: $3"
[RESULTS (test01) from nsis log panel]:
IMPORT SQL files to db=demo User=root Pswd=
…. Password entered ….
MySqlDir: c:\PROGRA~1\MySQL\MySQL Server 5.7\bin\mysql.exe
input: c:_temp-c\dumps\dump-20170604-demo.sql
IMPORT return-OK: 1 <=error
[NOTE:]
changing nsExec::ExecToStack .... to nscExec::ExecToLog ....
Yields different Error
[RESULTS (test02) from nsis log panel]:
IMPORT SQL files to db=demo User=root Pswd=
…. Password entered ….
MySqlDir: c:\PROGRA~1\MySQL\MySQL Server 5.7\bin\mysql.exe
input: c:_temp-c\dumps\dump-20170604-demo.sql
'c:\PROGRA~1\MySQL\MySQL' is not recognized as an internal or external command, operable program or batch file.
Maybe this will help. Hope it works for you.
importdbs:
DetailPrint "IMPORT SQL files to db=$dbname User=$login Pswd=$password"
StrCpy $1 "$folder\bin\mysql.exe"
StrCpy $2 "$srcepath$srcescript"
System::Call 'kernel32::GetLongPathName(t r1, t .r3, i ${NSIS_MAX_STRLEN}) i .r4'
StrCmp $4 error +2
StrCpy $1 $3
DetailPrint "MySqlDir: $1 input: $2"
ClearErrors
ReadEnvStr $R0 COMSPEC
ExecDos::Exec /TOSTACK `"$R0" /c "$1" -u$root -p -v -D $dbname < "$2" > "c:\_temp-c\ckprnout.txt"`
Pop $5 # Get Results
StrCmp "error" $5 +1 +2
DetailPrint "IMPORT return-error: $5"
DetailPrint "IMPORT return-OK: $5"

getting exit code of an executed sipp with tcl

I'm trying to get the exit code " echo $? " after executing SIPp command with exec from tcl :
if { [catch { exec /usr/local/sipp-3.3.990/sipp -t "u1" -s $SERVICE \
-ap $PASSWORD \
-sf $SCRIPT_PATH1 \
-i $LOCAL_IP \
-m 1 -key path $str \
-key dnid *20 \
-timeout 10s\
-trace_err -trace_screen $CLIENT2 -nd | /bin/sh $str/return_code.sh } fid option] }
I have tried to do execute "echo $?" but that didn’t work so I tried to execute it from an other script called "return_code.sh"
#!/bin/sh
echo "exit code: $?"
echo "PPID: $PPID"
but this also didn't work the result is always 0 , any idea about how to get the exit code from tcl ?
Best regards ,
An exhaustive example is given at http://wiki.tcl.tk/1039#pagetoce3a5e27b
This might be easier
set status [catch {sipp ...} output option]
if {$status == 0} {
# sipp did not emit anything to stderr, and exited with status 0
} else {
# some error
set err_info [lassign [dict get $option -errorcode] err_type]
switch -exact -- $err_type {
NONE {
# sipp exited with status 0 but printed something to stderr
# which is captured in $output
}
CHILDSTATUS {
# non-zero exit status
set exit_status [lindex $err_info 1]
set process_id [lindex $err_info 0]
}
default {
puts "some other error: $option"
}
}
}
Ah I see what you're up to now (your supplied code is way too complicated to demonstrate clearly). You're doing sipp .... | sh -c 'echo exit code: $?'. That echo command will always be zero: it is running in a separate process that has not launched any commands. Example:
% set status [catch {exec sh -c {exit 42} | sh -c {echo "previous exit status: $?"}} output option]
1
% puts $output
previous exit status: 0
child process exited abnormally
% set option
-code 1 -level 0 -errorcode {CHILDSTATUS 25539 42} -errorinfo {previous exit status: 0
child process exited abnormally
while executing
"exec sh -c {exit 42} | sh -c {echo "previous exit status: $?"}"} -errorline 1
We see that the 2nd sh process's $? value is zero. However, the pipeline's exit status, as seen by Tcl, is 42.

NSIS AdvReplaceInFile is too slow to make changes to shared file

My installer needs to change one line in a rather large (500Kb, about 11k lines) json file. I'm using AdvReplaceInFile to find and replace the occurrence.
Problem is, it takes about 3~ seconds to finish the job. I can kill the application using the same file, but if it's restarted automatically within that time window, even though the replace is successful, the process will overwrite the file again later on.
I'm assuming the algorithm responsible for search & replace is what's causing the slowdown.
How can I make it go faster other than writing my own DLL plugin to do so?
NSIS code was never designed to be fast and any call to a Int* function involves at least 2 string to number conversions etc.
Using a slightly slower version of the function you can prevent other processes from opening the file for writing:
Function AdvReplaceInFile
Exch $0 ;file to replace in
Exch
Exch $1 ;number to replace after
Exch
Exch 2
Exch $2 ;replace and onwards
Exch 2
Exch 3
Exch $3 ;replace with
Exch 3
Exch 4
Exch $4 ;to replace
Exch 4
Push $5 ;minus count
Push $6 ;universal
Push $7 ;end string
Push $8 ;left string
Push $9 ;right string
Push $R0 ;file1
Push $R1 ;file2
Push $R2 ;read
Push $R3 ;universal
Push $R4 ;count (onwards)
Push $R5 ;count (after)
Push $R6 ;temp file name
GetTempFileName $R6
FileOpen $R1 $0 a ;file to search in
FileOpen $R0 $R6 a ;temp file
StrLen $R3 $4
StrCpy $R4 -1
StrCpy $R5 -1
loop_read:
ClearErrors
FileRead $R1 $R2 ;read line
IfErrors exit
StrCpy $5 0
StrCpy $7 $R2
loop_filter:
IntOp $5 $5 - 1
StrCpy $6 $7 $R3 $5 ;search
StrCmp $6 "" file_write1
StrCmp $6 $4 0 loop_filter
StrCpy $8 $7 $5 ;left part
IntOp $6 $5 + $R3
IntCmp $6 0 is0 not0
is0:
StrCpy $9 ""
Goto done
not0:
StrCpy $9 $7 "" $6 ;right part
done:
StrCpy $7 $8$3$9 ;re-join
IntOp $R4 $R4 + 1
StrCmp $2 all loop_filter
StrCmp $R4 $2 0 file_write2
IntOp $R4 $R4 - 1
IntOp $R5 $R5 + 1
StrCmp $1 all loop_filter
StrCmp $R5 $1 0 file_write1
IntOp $R5 $R5 - 1
Goto file_write2
file_write1:
FileWrite $R0 $7 ;write modified line
Goto loop_read
file_write2:
FileWrite $R0 $R2 ;write unmodified line
Goto loop_read
exit:
FileSeek $R1 0 SET
!if "${NSIS_PTR_SIZE}" > 4
System::Call 'kernel32::SetEndOfFile(p$R1)'
!else
System::Call 'kernel32::SetEndOfFile(i$R1)'
!endif
FileSeek $R0 0 SET
ClearErrors
mov_loop:
FileRead $R0 $R2
IfErrors mov_done
FileWrite $R1 $R2
Goto mov_loop
mov_done:
FileClose $R0
FileClose $R1
SetDetailsPrint none
Delete $R6
SetDetailsPrint lastused
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $9
Pop $8
Pop $7
Pop $6
Pop $5
;These values are stored in the stack in the reverse order they were pushed
Pop $0
Pop $1
Pop $2
Pop $3
Pop $4
FunctionEnd
The only way to actually make it faster would be to call a external program or write a plugin...

NSiS call a function to dump log file at the end of installation

im working on a project where im using NSI to create a setup myproject.exe,
everything works fine, but i want to dump the log that is displayed into a file, that also works fine, but my problem is i cant figure out when to call the log function
i have 12 sections in my script , i got the function to create the installation log from Dump log to file
!define PRODUCT_NAME "myApplication"
!define PRODUCT_VERSION "1.7.1"
!define LVM_GETITEMCOUNT 0x1004
!define LVM_GETITEMTEXT 0x102D
!include MUI2.nsh
Name "myExe"
OutFile "C:\myExe.exe"
InstallDir $PROGRAMFILES\myprojc
InstallDirRegKey HKCU "Software\myprojc" "Install_Dir"
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\Folder-Options.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\Banner.bmp"
; Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;Languages
!insertmacro MUI_LANGUAGE "English"
BrandingText "myProj version 1.7.1"
;Here My section are decribed.. 12 of them
Section "main program and components" section1
;main promgram files are copied
SectionEnd
Section "other DLL" section2
;copy the DLLs
SectionEnd
Section "Text files" section3
;copy the required txt files
SectionEnd
;-....
;...
Section "install BDE admin" section12
;copy install BDE admin
;Calling the Dumplog function to create the log file
StrCpy $0 "$INSTDIR\Query\Presleyinstall.log"
Push $0
Call DumpLog
SectionEnd
;The function dumps the to a log file
Function DumpLog
Exch $5
Push $0
Push $1
Push $2
Push $3
Push $4
Push $6
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1016
StrCmp $0 0 exit
FileOpen $5 $5 "w"
StrCmp $5 "" exit
SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6
System::Alloc ${NSIS_MAX_STRLEN}
Pop $3
StrCpy $2 0
System::Call "*(i, i, i, i, i, i, i, i, i) i \
(0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
loop: StrCmp $2 $6 done
System::Call "User32::SendMessageA(i, i, i, i) i \
($0, ${LVM_GETITEMTEXT}, $2, r1)"
System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
FileWrite $5 "$4$\r$\n"
IntOp $2 $2 + 1
Goto loop
done:
FileClose $5
System::Free $1
System::Free $3
exit:
Pop $6
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
Exch $5
FunctionEnd
Since i have called the dumplog function in section 12, the log file is only create when/if the section is selected by the user, if the section 12 is not selected then the dumplog function wont be called and log file will not be created,
so please tell me how do i call the dumplog function irrespective of the section is selected or not by the user, That is call the dumplog when the installation is complete.
EDIT
i can also try to create a section "Create installer log" and check it and disable like
Section "Create installer log" section13
SectionIn RO
StrCpy $0 "$INSTDIR\myinstall.log"
Push $0
Call DumpLog
SectionEnd
this
but is there a way to call the dumplog function without section, and at the end of the installation?
If you don't give the section a name (or start the name with -) then it will not be displayed on the components page:
Section "Foobar"
;Install the optional Foobar
SectionEnd
Section
;Hidden section
Section
You can even put it in callback functions.
Function .onInstSuccess
;..
Call DumpLog
;..
FunctionEnd
Function .onInstFail
;..
Call DumpLog
;..
FunctionEnd