PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/yekki/3rdparty/native/win/shell/AUTORUN.KSH

http://soulmates.googlecode.com/
Korn Shell | 311 lines | 194 code | 14 blank | 103 comment | 12 complexity | 6a074f58788abce2159916d2177e1282 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, BSD-3-Clause-No-Nuclear-License-2014, AGPL-1.0
  1. #
  2. # Set up the registry to do an automatic run of a command/set of commands
  3. # at either the next boot, or the next user login. It can also be set
  4. # to run once, or run every time.
  5. #
  6. # Note that this program simply manipulates the registry, actual implementation
  7. # of the running of the commands is the responsibility of the operating system.
  8. # Note that this is fully implemented in Windows 95; not all versions of
  9. # Windows NT yet support the running of these entries. In future, it is
  10. # assumed that this will become standard, and all Win32 based systems will
  11. # support these entries.
  12. #
  13. #
  14. # Good programming practice to set shell variables for each control id.
  15. # The resource editors usually generate a C header file with #defines
  16. # for each control ID. They must be manually converted at this point.
  17. #
  18. # Generic ids, found normally in windows header files.
  19. IDOK=1
  20. IDCANCEL=2
  21. IDHELP=9
  22. # For the main dialog
  23. IDD_AUTORUN=101 # The dialog number
  24. IDC_MACHINE_ONCE=1000
  25. IDC_MACHINE_EVERY=1001
  26. IDC_USER_ONCE=1002
  27. IDC_USER_EVERY=1003
  28. IDC_LIST=1004
  29. IDC_ADD=1005
  30. IDC_DELETE=1006
  31. IDC_MODIFY=1007
  32. # For the add dialog
  33. IDD_ADD=102 # The dialog number
  34. IDC_AID=1008
  35. IDC_CMDLINE=1009
  36. AUTORUN_CID=1005 # Help Context id to the autorun page.
  37. reg='\Software\Microsoft\Windows\CurrentVersion\'
  38. #
  39. # Find out where this shell script is executing from, since the shell script
  40. # includes the dialog resources that we display.
  41. #
  42. RESFILE=$(whence $0)
  43. if ! dlg load -x -1 -y -1 -r h $RESFILE $IDD_AUTORUN # Create the dialog box
  44. then
  45. exit # Should have been an error from dlg in a msgbox
  46. fi
  47. # Setup the listview columns
  48. dlg columns -c $IDC_LIST "Application Identifier" 130 "Command Line" 240
  49. #
  50. # Save the current list back into the registry, by deleting all current
  51. # registry entries, and then replacing them with the contents of our listbox.
  52. #
  53. function SaveList {
  54. # Key may not exist at all, discard error
  55. registry -d -k "$registry" 2>nul
  56. i=0
  57. while dlg gettext -d $h -c $IDC_LIST -i $i aid cmdline
  58. do
  59. registry -s -k "$registry" -n "$aid" -v "$cmdline"
  60. let i=i+1
  61. done
  62. }
  63. #
  64. # Given the current settings of the radio buttons, load up the listbox
  65. # with the current registry values.
  66. #
  67. function LoadList {
  68. if [ "$modified" -ne 0 ]
  69. then
  70. msgbox -b yesno -f -i question -q "AutoRun" "Current list has changed, do you want to save it now?"
  71. if [ $? -eq 6 ]
  72. then
  73. SaveList
  74. fi
  75. fi
  76. if { dlg isbuttonchecked -d $h -c $IDC_USER_ONCE val; test val -eq 1; }
  77. then
  78. registry=HKEY_CURRENT_USER${reg}RunOnce
  79. elif { dlg isbuttonchecked -d $h -c $IDC_USER_EVERY val; test val -eq 1; }
  80. then
  81. registry=HKEY_CURRENT_USER${reg}Run
  82. elif { dlg isbuttonchecked -d $h -c $IDC_MACHINE_ONCE val; test val -eq 1; }
  83. then
  84. registry=HKEY_LOCAL_MACHINE${reg}RunOnce
  85. else
  86. registry=HKEY_LOCAL_MACHINE${reg}Run
  87. fi
  88. dlg clear -d $h -c $IDC_LIST
  89. #
  90. # Note: the following registry command may give an error
  91. # that the key doesn't exist, since there may not be (probably aren't)
  92. # any Run entries
  93. #
  94. # Note: This should be: registry | while read
  95. # but the `dlg set' when operating on a ListView control must not
  96. # be in a forked sub-shell. (Why it works if using a normal listbox
  97. # control is probably due to the fact that Listbox controls are part
  98. # of windows 3.1 and have to be shared for compatability purposes.)
  99. #
  100. v=$(registry -p -k "$registry" 2>nul)
  101. [ ! -z "$v" ] && while IFS=" " read -r key aid cmdline
  102. do
  103. # Note that cmdline has a " at the beginning and end
  104. cmdline="${cmdline#?}"
  105. dlg addtext -d $h -c $IDC_LIST "$aid" "${cmdline%?}"
  106. done <<EOF
  107. $v
  108. EOF
  109. modified=0
  110. }
  111. #
  112. # Add/Edit single entry dialog box.
  113. # Either called with no args, in which case its an add,
  114. # or called with $1=index of line to edit
  115. #
  116. function RunAddDlg {
  117. if ! dlg load -m $h -x -1 -y -1 -r add $RESFILE $IDD_ADD
  118. then
  119. exit # Fatal error!!!
  120. fi
  121. if [ $# -eq 0 ]
  122. then
  123. dlg settext -d $add "Add New Run Command"
  124. else
  125. dlg settext -d $add "Edit Run Command"
  126. dlg gettext -d $h -c $IDC_LIST -i $index aid cmdline
  127. dlg settext -d $add -c $IDC_CMDLINE "$cmdline"
  128. dlg settext -d $add -c $IDC_AID "$aid"
  129. fi
  130. while dlg event -d $add msg control
  131. do
  132. case "$msg $control" in
  133. "command $IDOK")
  134. dlg gettext -d $add -c $IDC_CMDLINE cmdline
  135. dlg gettext -d $add -c $IDC_AID aid
  136. if [ -z "$cmdline" -o -z "$aid" ]
  137. then
  138. continue
  139. fi
  140. if [ $# -ne 0 ] # This was an edit, replace it
  141. then
  142. dlg replacerow -d $h -c $IDC_LIST -i $1 "$aid" "$cmdline"
  143. else
  144. dlg addtext -d $h -c $IDC_LIST "$aid" "$cmdline"
  145. fi
  146. modified=1
  147. break # out of while loop
  148. ;;
  149. "command $IDCANCEL")
  150. break
  151. ;;
  152. esac
  153. done
  154. dlg close -d $add
  155. }
  156. #
  157. # Set up the defaults: load the per-user, run once registry entries.
  158. #
  159. dlg checkbutton -d $h -c $IDC_USER_ONCE 1 # Default is the user, once
  160. modified=0
  161. LoadList
  162. #
  163. # Standard dlg event loop: Get the user's actions
  164. # We will exit this loop automatically if the user selects the Close system
  165. # menu; the message will be `close', but the exit status will be non-zero.
  166. #
  167. while dlg event -d $h msg control
  168. do
  169. case "$msg $control" in
  170. "command $IDHELP"|"help "*)
  171. dlg winhelp -C $AUTORUN_CID $ROOTDIR/etc/toolkit.hlp
  172. ;;
  173. "command $IDOK")
  174. break
  175. ;;
  176. "command $IDCANCEL")
  177. dlg winhelp -q $ROOTDIR/etc/toolkit.hlp
  178. dlg close -d $h
  179. exit
  180. ;;
  181. "command $IDC_USER_ONCE"|
  182. "command $IDC_USER_EVERY"|
  183. "command $IDC_MACHINE_ONCE"|
  184. "command $IDC_MACHINE_EVERY")
  185. # Radio button selecting which type of startup list is to
  186. # be shown. Reload.
  187. LoadList
  188. ;;
  189. "command $IDC_ADD")
  190. RunAddDlg
  191. ;;
  192. "command $IDC_DELETE")
  193. dlg getcursel -d $h -c $IDC_LIST index
  194. if [ $index -eq -1 ]
  195. then
  196. continue # Ignore, nothing selected
  197. fi
  198. dlg gettext -d $h -c $IDC_LIST -i $index cur
  199. msgbox -b okcancel -f -i question -q "AutoRun" "Ok to delete entry "$cur
  200. if [ $? -eq 2 ]
  201. then
  202. continue # Ignore, cancel selected
  203. fi
  204. dlg delete -d $h -c $IDC_LIST -i $index
  205. modified=1
  206. ;;
  207. "command $IDC_MODIFY")
  208. dlg getcursel -d $h -c $IDC_LIST index
  209. if [ $index = -1 ]
  210. then
  211. continue # Ignore, nothing selected
  212. fi
  213. RunAddDlg $index
  214. ;;
  215. "double $IDC_LIST")
  216. dlg getcursel -d $h -c $IDC_LIST index
  217. if [ $index = -1 ]
  218. then
  219. continue # Better be, we got a dblclk
  220. fi
  221. RunAddDlg $index
  222. ;;
  223. esac
  224. done
  225. # Now save it all...
  226. SaveList
  227. # Close out the winhelp: this is ignored if we didn't start up a winhelp;
  228. # or if the winhelp was started by somebody other than this process.
  229. dlg winhelp -q $ROOTDIR/etc/toolkit.hlp
  230. dlg close -d $h
  231. #[]mks internal resource : dialog : \101
  232. #[ ]begin : size 700
  233. #[ ]MP #(D + #D *0 $$ =0!T &\ ;0!A '0 :0!C " 0P!O
  234. #[ ]M &T ;0!A &X 9 @ %( =0!N " !- %, ( !3 &$ ;@!S " 4P!E '(
  235. #[ ]M:0!F 0 !4 "K < ,@ . $ __^ $\ 2P %0
  236. #[ ]M *L & R X @#__X 0P!A &X 8P!E &P "0 4 ' <
  237. #[ ]M?P , .@#__^ $\ ;@ @ &T 80 F &, : !I &X 90 @ &( ;P!O '0 =0!P
  238. #[ ]M "P ( !O &X 8P!E D % !P 3 '\ # #I ___@ !/ &X
  239. #[ ]M( !M &$ 8P!H "8 :0!N &4 ( !B &\ ;P!T '4 < L " 90!V &4 <@!Y
  240. #[ ]M " = !I &T 90 ) !0 < 'P!_ P Z@/__X 3P!N "
  241. #[ ]M)@!U ', 90!R " ; !O &< :0!N "P ( !O &X 8P!E D %
  242. #[ ]M !P K '\ # #K ___@ !/ &X ( !U "8 <P!E '( ( !L &\ 9P!I &X
  243. #[ ]M+ @ &4 =@!E '( >0 @ '0 :0!M &4 !4 9 (X )0 +
  244. #[ ]M .T#__^ "8 00!D &0 !4 !? (X )0 + .X#__^ "8
  245. #[ ]M1 !E &P 90!T &4 5 I0". "4 "P#O ___@ F $T ;P!D
  246. #[ ]M &D 9@!Y % (%0 < .0#6 $X [ -3 'D <P!, &D <P!T %8
  247. #[ ]M:0!E '< ,P R 3 !I ', = !V &D 90!W #$ 5 JP I
  248. #[ ]9 #( #@ ) /__@ F $@ 90!L '
  249. #[ ]end
  250. #[]mks internal resource : dialog : \102
  251. #[ ]begin : size 342
  252. #[ ]MP #(D & #T &P $$ 9 !D " 3@!E '< ( !2 '4 ;@ @
  253. #[ ]M $, ;P!M &T 80!N &0 ( $T 4P @ %, 80!N ', ( !3 &4 <@!I &8
  254. #[ ]M ! %0 +L !P R X 0#__X 3P!+ 5 NP 8
  255. #[ ]M #( #@ " /__@ !# &$ ;@!C &4 ; )0 < $P"* D
  256. #[ ]M_____X( 00!P ' ; !I &, 80!T &D ;P!N " 20!D &4 ;@!T &D 9@!I
  257. #[ ]M &4 <@ " (%0 < (0"? T \ /__X$ "4
  258. #[ ]M ' #L ;@ * /____^" $, ;P!M &T 80!N &0 ( !, &D ;@!E
  259. #[ ]; ( @5 !P!* .8 #@#Q ___@0
  260. #[ ]end
  261. #[]mks internal resource : icon : \0 : width 32 height 32 colors 16
  262. #[ ]begin : size 744
  263. #[ ]M* " ! 0 $ " @
  264. #[ ]M ( ( " @ " @ " (" # P, @(" _P _P /__ /\
  265. #[ ]M #_ /\ __\ /___P#,S,S,S +N_"9N[FY$#L S,S,S,P "[OP&9N9L9 [
  266. #[ ]M ,S,S,S, ___P&;F;D0,S/,S,S,S / S,S,S,P #_#NX)D1
  267. #[ ]M$0S. \S,S,S, O_#N"?$1$,X##,S,S,S +O_#@GQ$1#@, S,S,S,P "[O_
  268. #[ ]M )\1$0 [ ,S,S,S, N[O_"?$1$#NP #PGQ$1
  269. #[ ]M \)\1$0 /"?$1$ "9F9F9F0 *JJKPGQ$1 JH F9F9
  270. #[ ]MF9D "JJJ\)\1$0*J )F9F9F9 JJJO"?$1$"J@"9F9F9F0 *JJKPGQ$1 JH
  271. #[ ]MF9F9F9D "JJJ\)\1$0*J )F9F9F9 JJJO"?$1$"J@"9F9F9F0 *JJKPGQ$1
  272. #[ ]M JH F9F9F9D "JJJ\)\1$0*J )F9F9F9 JJJO"?$1$"J@"9F9F9F0 *JJKP
  273. #[ ]MGQ$1 JH F9F9F9D "JJJ\)D1$0*J )F9F9F9 JJJO *J@"9F9F9F0 *
  274. #[ ]MJJK_"9$0*JH F9F9F9D "JJJKPGQ$"JJ \)\1
  275. #[ ]M /"9$0 #P \0@
  276. #[ ]M /$(
  277. #[ ]M
  278. #[ ]M
  279. #[ ]8 ___X/___^#____S_
  280. #[ ]end
  281. #[]mks internal resource : icon : \1 : width 16 height 16 colors 16
  282. #[ ]begin : size 296
  283. #[ ]M* ! @ 0 $ #
  284. #[ ]M ( ( " @ " @ " (" # P, @(" _P _P /__ /\
  285. #[ ]M #_ /\ __\ /___P#,S,#_D;.1B,S,P, ,S,S _$GQ!,C,S, _R?$,
  286. #[ ]MB$1$0#/Y\0@P /GQ" "9F9 J^?$(H)F9D"KY\0B@F9F0*OGQ"*"9F9 J
  287. #[ ]M^?$(H)F9D"KY\0B@F9F0*OGQ"J 1$1 B_Y&"( /D8 "1
  288. #[ ]M 6 4 )D0
  289. #[ ]: #Q _\\ \?__ "9
  290. #[ ]end