common.nsh 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /***************************************************************************
  2. * Copyright (C) 2014 Jeffery Jiang. <china_jeffery@163.com>
  3. *
  4. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  5. * copies of the Software, and permit persons to whom the Software is
  6. * furnished to do so.
  7. *
  8. * HOWEVER YOU CAN NOT REMOVE/MODIFY THESE COMMENTS.
  9. *
  10. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  11. * KIND, either express or implied.
  12. ***************************************************************************/
  13. # ============================
  14. # �Զ��庯�����ߺ�
  15. # ============================
  16. !include "nsProcess.nsh"
  17. !include "LogicLib.nsh"
  18. !include "FileFunc.nsh"
  19. !insertmacro GetParameters
  20. !insertmacro GetOptions
  21. !macro Trace msg
  22. MessageBox MB_ICONINFORMATION|MB_OK "${msg}" /SD IDOK
  23. !macroend
  24. !define MAX_RETRY 10
  25. Var RetryTimes
  26. # ��ֹ����
  27. Function TerminateProcess
  28. # ʹ��RtlAdjustPrivilege���������������̵�ϵͳȨ��
  29. System::Call ntdll::RtlAdjustPrivilege(i20,i1,i0,*i)
  30. StrCpy $RetryTimes 0
  31. loop__:
  32. nsProcess::_FindProcess /NOUNLOAD "$R0"
  33. Pop $R1
  34. StrCmp $R1 "0" +1 TerminateProcessOver
  35. nsProcess::_KillProcess /NOUNLOAD "$R0"
  36. Pop $R1
  37. IntOp $RetryTimes $RetryTimes + 1
  38. ${If} $RetryTimes > ${MAX_RETRY}
  39. Goto TerminateProcessOver
  40. ${EndIf}
  41. Sleep 200
  42. Goto loop__
  43. TerminateProcessOver:
  44. FunctionEnd
  45. Function un.TerminateProcess4Uninstall
  46. # ʹ��RtlAdjustPrivilege���������������̵�ϵͳȨ��
  47. System::Call ntdll::RtlAdjustPrivilege(i20,i1,i0,*i)
  48. StrCpy $RetryTimes 0
  49. loop__:
  50. nsProcess::_FindProcess /NOUNLOAD "$R0"
  51. Pop $R1
  52. StrCmp $R1 "0" +1 TerminateProcessOver
  53. nsProcess::_KillProcess /NOUNLOAD "$R0"
  54. Pop $R1
  55. IntOp $RetryTimes $RetryTimes + 1
  56. ${If} $RetryTimes > ${MAX_RETRY}
  57. Goto TerminateProcessOver
  58. ${EndIf}
  59. Sleep 200
  60. Goto loop__
  61. TerminateProcessOver:
  62. FunctionEnd
  63. # �����Զ�����ʱĿ¼,ʹ�ò��chngvrbl.dll��
  64. # �ú������.onInit�е��á�
  65. !macro ChangeTempDir dirPath
  66. StrCmp "${dirPath}" "" ChangeTempDirOver +1
  67. CreateDirectory "${dirPath}"
  68. File /oname=${dirPath}\chngvrbl.dll "chngvrbl.dll"
  69. Push "${dirPath}"
  70. Push 25 ;$TEMP
  71. CallInstDLL "${dirPath}\chngvrbl.dll" changeVariable
  72. Delete "${dirPath}\chngvrbl.dll"
  73. ChangeTempDirOver:
  74. !macroend
  75. !macro DeleteTempDir
  76. RMDir /r "$TEMP"
  77. !macroend
  78. # ������������
  79. # foo.exe /S /USERNAME Bar /D C:\Program Files\Foo
  80. !macro ParseParameters paramName paramValue
  81. ${GetParameters} $R0
  82. ${GetOptions} $R0 "${paramName}" ${paramValue}
  83. !macroend
  84. # ȷ��VALUE��END_WITH����
  85. !macro EnsureEndsWith VALUE END_WITH
  86. StrLen $R7 "${END_WITH}"
  87. IntOp $R8 0 - $R7
  88. StrCpy $R9 "${VALUE}" $R7 $R8
  89. StrCmp $R9 ${END_WITH} +2
  90. StrCpy ${VALUE} "${VALUE}${END_WITH}"
  91. !macroend
  92. # ���尲װ
  93. !macro InstallFont fontFilePath fontFilename fontShowName
  94. IfFileExists "$FONTS\${fontFilename}" InstallFontOver
  95. System::Call "ntdll::RtlAdjustPrivilege(i20,i1,i0,*i) i.s"
  96. Pop $R9
  97. #${If} $R9 <> 0
  98. # ����Ȩ��ʧ��
  99. #MessageBox MB_ICONINFORMATION|MB_OK "����Ȩ��ʧ��!" /SD IDOK
  100. #${EndIf}
  101. File /oname=$FONTS\${fontFilename} ${fontFilePath}
  102. WriteRegStr HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" "${fontShowName}" "$FONTS\${fontFilename}"
  103. System::Call "GDI32::AddFontResource(t'$FONTS\${fontFilename}') i.s"
  104. Pop $R9
  105. ${If} $R9 == 0
  106. MessageBox MB_ICONINFORMATION|MB_OK "��װ����ʧ��!" /SD IDOK
  107. ${EndIf}
  108. !macroend
  109. # ��ȡ�ؼ�λ��
  110. !macro GetWindowPos parentHwnd ctrlHwnd l t r b
  111. System::Call "*(i0,i0,i0,i0) i.r11"
  112. System::Call "User32::GetWindowRect(i${ctrlHwnd}, i$R1)"
  113. System::Call "*$R1(i.r16,i.r17,i.r18,i.r19)"
  114. System::Call "*(i$R6,i$R7) i.r12)" # ����
  115. System::Call "*(i$R8,i$R9) i.r13)" # ����
  116. System::Call "User32::ScreenToClient(i${parentHwnd}, i$R2)"
  117. System::Call "User32::ScreenToClient(i${parentHwnd}, i$R3)"
  118. System::Call "*$R2(i.r14,i.r15)"
  119. System::Call "*$R3(i.r16,i.r17)"
  120. IntOp ${l} $R4 + 0
  121. IntOp ${t} $R5 + 0
  122. IntOp ${r} $R6 + 0
  123. IntOp ${b} $R7 + 0
  124. System::Free $R1
  125. System::Free $R2
  126. System::Free $R3
  127. !macroend
  128. # �ؼ�����͸����
  129. !macro SetTransparent HWND IDC fontClr
  130. GetDlgItem $R0 ${HWND} ${IDC}
  131. SetCtlColors $R0 ${fontClr} transparent
  132. !macroend