Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for zapvbs.kix

(view source code of zapvbs.kix as plain text)

  1. ? "ZapVbs.kix,  Version 1.00 for Windows 95/98/NT"
  2. ? "Written by Rob van der Woude"
  3. ? "http://www.robvanderwoude.com"
  4. ?
  5. ? "This Kix script can change the file associations for VBScript files to"
  6. ? "NotePad, as a " + chr(34) + "poor man's protection" + chr(34) + " against VBScript (e-mail) viruses."
  7. ? "Next time you see a Notepad window pop up after double-clicking an e-mail"
  8. ? "attachment (which you shouldn't have done!), it may have been an e-mail"
  9. ? "virus, stopped by this Kix script's safety precautions."
  10. ?
  11. ? "This script does not and will not fully protect you against viruses!"
  12. ? "It is only meant as a first line of defence. Buy, install and use recent"
  13. ? "anti-virus software and make sure you keep it up-to-date."
  14. ?
  15. ? "DISCLAIMER:"
  16. ? "This script changes registry settings."
  17. ? "Changing registry settings may cause system failure and/or loss of data."
  18. ? "The author of this script cannot be held responsible for any damage"
  19. ? "caused by use of this script, or by the inability to use it."
  20. ? "Use this script entirely at your own risk."
  21. ?
  22. ? 'Press "Y" if you accept these terms . . .'
  23.  
  24. ; Quit unless the terms are accepted
  25. Get $y
  26. If $y <> "Y"
  27. 	Quit 255
  28. EndIf
  29.  
  30. Cls
  31. ? "ZapVbs.kix,  Version 1.00 for Windows 95/98/NT"
  32. ? "Written by Rob van der Woude"
  33. ? "http://www.robvanderwoude.com"
  34. ?
  35.  
  36. ; Initialize variable
  37. $notepad = ""
  38.  
  39. ? "Checking current VBScript file associations:"
  40. ?
  41. $vbe = ReadValue ("HKEY_CLASSES_ROOT\.vbe", "")
  42. If @ERROR = 0
  43. 	? ".VBE file type   :  $vbe"
  44. 	$chgvbe  = 0
  45. 	$chgvbe2 = 0
  46. 	; Read the registry to find out which program
  47. 	; is used by default when a .VBE file is opened
  48. 	$vbecmd  = ReadValue ("HKEY_CLASSES_ROOT\$vbe\Shell\Open\Command", "")
  49. 	If @ERROR = 0
  50. 		? ".VBE association :  $vbecmd"
  51. 		; Check if NotePad is already associated with .VBE
  52. 		$pos = InStr($vbecmd, "notepad.exe")
  53. 		If $pos
  54. 			; Store the path to notepad, so we
  55. 			; won't need to search for it later
  56. 			$notepad = Substr($vbecmd, 1, $pos + 10)
  57. 		Else
  58. 			; Set variables to remember to change
  59. 			; the association for this extension
  60. 			$chgvbe = 1
  61. 			$chgstr = ".VBE"
  62. 		EndIf
  63. 	EndIf
  64. 	; Repeat the process for "Open2"
  65. 	$vbecm2 = ReadValue ("HKEY_CLASSES_ROOT\$vbe\Shell\Open2\Command", "")
  66. 	If @ERROR = 0
  67. 		? ".VBE association :  $vbecm2"
  68. 		$pos = InStr($vbecm2, "notepad.exe")
  69. 		If $pos
  70. 			$notepad = Substr($vbecm2, 1, $pos + 10)
  71. 		Else
  72. 			$chgvbe2 = 1
  73. 			$chgstr = ".VBE"
  74. 		EndIf
  75. 	EndIf
  76. EndIf
  77.  
  78. ?
  79. ; Repeat for .VBS extension
  80. $vbs = ReadValue ("HKEY_CLASSES_ROOT\.vbs", "")
  81. If @ERROR = 0
  82. 	? ".VBS file type   :  $vbs"
  83. 	$chgvbs  = 0
  84. 	$chgvbs2 = 0
  85. 	$vbscmd  = ReadValue ("HKEY_CLASSES_ROOT\$vbs\Shell\Open\Command", "")
  86. 	If @ERROR = 0
  87. 		? ".VBS association :  $vbscmd"
  88. 		$pos = InStr($vbscmd, "notepad.exe")
  89. 		If $pos
  90. 			$notepad = Substr($vbscmd, 1, $pos + 10)
  91. 		Else
  92. 			$chgvbs = 1
  93. 			If ($chgstr = ".VBE")
  94. 				$chgstr = ".VBE and .VBS"
  95. 			Else
  96. 				$chgstr = ".VBS"
  97. 			EndIf
  98. 		EndIf
  99. 	EndIf
  100. 	$vbscm2 = ReadValue ("HKEY_CLASSES_ROOT\$vbs\Shell\Open2\Command", "")
  101. 	If @ERROR = 0
  102. 		? ".VBS association :  $vbscm2"
  103. 		$pos = InStr($vbscm2, "notepad.exe")
  104. 		If $pos
  105. 			$notepad = Substr($vbscm2, 1, $pos + 10)
  106. 		Else
  107. 			$chgvbs2 = 1
  108. 			If InStr($chgstr, ".VBE")
  109. 				$chgstr = ".VBE and .VBS"
  110. 			Else
  111. 				$chgstr = ".VBS"
  112. 			EndIf
  113. 		EndIf
  114. 	EndIf
  115. EndIf
  116.  
  117. ; Check if any association needs to be changed
  118. ; according to the previous part of the script
  119. If ($chgvbe OR $chgvbe2 OR $chgvbs OR $chgvbs2)
  120. 	; If the path to NotePad wasn't found
  121. 	; in the registry settings we checked
  122. 	; before, we need to find it now
  123. 	If $notepad = ""
  124. 		; Check the WINDOWS or WINNT directory first
  125. 		$notepad = "%windir%\notepad.exe"
  126. 		If Dir($notepad) = "" OR @ERROR <> 0
  127. 			; If unsuccessful, check the
  128. 			; SYSTEM or SYSTEM32 directory
  129. 			$notepad = "@LANROOT\notepad.exe"
  130. 			If Dir("@LANROOT\notepad.exe") = "" OR @ERROR <> 0
  131. 				; If still unsuccessful, use the
  132. 				; TYPE command instead of NotePad
  133. 				$notepad = "%COMSPEC% /K TYPE"
  134. 			EndIf
  135. 		EndIf
  136. 	EndIf
  137. 	? ? "Suggested new association: = $notepad"
  138. 	; Wrap line if the path is too long to display on 1 single line
  139. 	If Len($notepad) > 23
  140. 		$crlf = chr(13) + chr(10)
  141. 	Else
  142. 		$crlf = ""
  143. 	EndIf
  144.  
  145. 	; Ask for confirmation
  146. 	?
  147. 	? "Do you want to change the default association for $chgstr"
  148. 	? 'files to $notepad "%%1" %%*? '
  149. 	?
  150. 	; Repeat question until valid answer is given
  151. 	$x = 0
  152. 	Do
  153. 		; Beep when invalid answer is given
  154. 		If $x
  155. 			Beep
  156. 		EndIf
  157. 		Get $answer
  158. 		$x = 1
  159. 	Until InStr("yn", $answer)
  160. 	; Quit unless confired
  161. 	If $answer <> "Y"
  162. 		?
  163. 		? "Associations for $chgstr left unchanged"
  164. 		Quit 0
  165. 	EndIf
  166.  
  167. 	; Build association string
  168. 	$assoc = '$notepad "%%1" %%*'
  169. 	; Change only the associations necessary
  170. 	; .VBE Open
  171. 	If $chgvbe
  172. 		?
  173. 		? "Changing default association for .VBE files to " + $crlf + $notepad + " " + chr(34) + "%%1" + chr(34) + " %%*"
  174. 		$key = "HKEY_CLASSES_ROOT\" + $vbe + "\Shell\Open\Command"
  175. 		$rc = WriteValue( $key, "", $assoc, "REG_SZ")
  176. 		If @ERROR
  177. 			? "Error writing to registry!"
  178. 			? "The error code is: @ERROR"
  179. 			? "Press any key to quit . . ."
  180. 			Get $dummy
  181. 			Quit 1
  182. 		EndIf
  183. 		$newval = ReadValue ($key, "")
  184. 		? "Checking new value: " + $crlf + $newval
  185. 	EndIf
  186. 	; Change only the associations necessary
  187. 	; .VBE Open2
  188. 	If $chgvbe2
  189. 		?
  190. 		? "Changing second  association for .VBE files to " + $crlf + $notepad + " " + chr(34) + "%%1" + chr(34) + " %%*"
  191. 		$key = "HKEY_CLASSES_ROOT\" + $vbe + "\Shell\Open2\Command"
  192. 		$rc = WriteValue( $key, "", $assoc, "REG_SZ")
  193. 		If @ERROR
  194. 			? "Error writing to registry!"
  195. 			? "The error code is: @ERROR"
  196. 			? "Press any key to quit . . ."
  197. 			Get $dummy
  198. 			Quit 2
  199. 		EndIf
  200. 		$newval = ReadValue ($key, "")
  201. 		? "Checking new value: " + $crlf + $newval
  202. 	EndIf
  203. 	; Change only the associations necessary
  204. 	; .VBS Open
  205. 	If $chgvbs
  206. 		?
  207. 		? "Changing default association for .VBS files to " + $crlf + $notepad + " " + chr(34) + "%%1" + chr(34) + " %%*"
  208. 		$key = "HKEY_CLASSES_ROOT\" + $vbs + "\Shell\Open\Command"
  209. 		$rc = WriteValue( $key, "", $assoc, "REG_SZ")
  210. 		If @ERROR
  211. 			? "Error writing to registry!"
  212. 			? "The error code is: @ERROR"
  213. 			? "Press any key to quit . . ."
  214. 			Get $dummy
  215. 			Quit 3
  216. 		EndIf
  217. 		$newval = ReadValue ($key, "")
  218. 		? "Checking new value: " + $crlf + $newval
  219. 	EndIf
  220. 	; Change only the associations necessary
  221. 	; .VBS Open2
  222. 	If $chgvbs2
  223. 		?
  224. 		? "Changing second  association for .VBS files to " + $crlf + $notepad + " " + chr(34) + "%%1" + chr(34) + " %%*"
  225. 		$key = "HKEY_CLASSES_ROOT\" + $vbs + "\Shell\Open2\Command"
  226. 		$rc = WriteValue( $key, "", $assoc, "REG_SZ")
  227. 		If @ERROR
  228. 			? "Error writing to registry!"
  229. 			? "The error code is: @ERROR"
  230. 			? "Press any key to quit . . ."
  231. 			Get $dummy
  232. 			Quit 4
  233. 		EndIf
  234. 		$newval = ReadValue ($key, "")
  235. 		? "Checking new value: " + $crlf + $newval
  236. 	EndIf
  237. Else
  238. 	?
  239. 	? "No change was necessary, VBScript files are already disabled on your system."
  240. EndIf
  241.  
  242. ?
  243. ? "Press any key to end this program  . . ."
  244. Get $dummy
  245.  

page last uploaded: 2017-08-21, 14:26