打印

[asp.net教程] 编写随windows启动运行的程序

编写随windows启动运行的程序

通过设置和读取注册表,可以实现我们的应用程序随windows的启动即可执行的功能。下面就是实现的代码:
   
  form1.vb
   
  imports microsoft.win32.registry
  public class form1
   inherits system.windows.forms.form
   
  #region " windows 窗体设计器生成的代码 "
   public sub new()
   mybase.new()
   '该调用是 windows 窗体设计器所必需的。
   initializecomponent()
   '在 initializecomponent() 调用之后添加任何初始化
   end sub
   
   '窗体重写处置以清理组件列表。
   protected overloads overrides sub dispose(byval disposing as boolean)
   if disposing then
   if not (components is nothing) then
   components.dispose()
   end if
   end if
   mybase.dispose(disposing)
   end sub
   
   'windows 窗体设计器所必需的
   private components as system.componentmodel.icontainer
   
   '注意:以下过程是 windows 窗体设计器所必需的
   '可以使用 windows 窗体设计器修改此过程。
   '不要使用代码编辑器修改它。
   friend withevents checkbox1 as system.windows.forms.checkbox
   friend withevents btnsave as system.windows.forms.button
   <system.diagnostics.debuggerstepthrough()> private sub initializecomponent()
   me.checkbox1 = new system.windows.forms.checkbox()
   me.btnsave = new system.windows.forms.button()
   me.suspendlayout()
   '
   'checkbox1
   '
   me.checkbox1.backcolor = system.drawing.systemcolors.control
   me.checkbox1.checked = true
   me.checkbox1.checkstate = system.windows.forms.checkstate.checked
   me.checkbox1.forecolor = system.drawing.systemcolors.controltext
   me.checkbox1.imemode = system.windows.forms.imemode.nocontrol
   me.checkbox1.name = "checkbox1"
   me.checkbox1.righttoleft = system.windows.forms.righttoleft.yes
   me.checkbox1.size = new system.drawing.size(142, 15)
   me.checkbox1.tabindex = 21
   me.checkbox1.text = "windows开机即运行"
   me.checkbox1.textalign = system.drawing.contentalignment.middleright
   '
   'btnsave
   '
   me.btnsave.backcolor = system.drawing.systemcolors.control
   me.btnsave.font = new system.drawing.font("宋体", 10.0!)
   me.btnsave.forecolor = system.drawing.systemcolors.controltext
   me.btnsave.imemode = system.windows.forms.imemode.nocontrol
   me.btnsave.location = new system.drawing.point(0, 16)
   me.btnsave.name = "btnsave"
   me.btnsave.size = new system.drawing.size(144, 24)

   me.btnsave.tabindex = 32
   me.btnsave.text = "保存设置"
   '
   'form1
   '
   me.autoscalebasesize = new system.drawing.size(5, 13)
   me.clientsize = new system.drawing.size(144, 40)
   me.controls.addrange(new system.windows.forms.control() {me.btnsave, me.checkbox1})
   me.formborderstyle = system.windows.forms.formborderstyle.fixedtoolwindow
   me.name = "form1"
   me.startposition = system.windows.forms.formstartposition.centerscreen
   me.text = "windows开机即运行"
   me.resumelayout(false)
   
   end sub
   
  #end region
   
   dim reg as microsoft.win32.registrykey
   private sub initvar()
   if btnsave.visible = true then
   
   end if
   reg = currentuser.opensubkey("software\microsoft\windows\currentversion\run", true)
   if reg.getvalue("mengxianhui") <> "" then
   checkbox1.checked = true
   else
   checkbox1.checked = false
   end if
   end sub
   private sub savesettings()
   if checkbox1.checked = true then
   reg = currentuser.opensubkey("software\microsoft\windows\currentversion\run", true)
   reg.setvalue("mengxianhui", application.executablepath)
   else
   reg = currentuser.opensubkey("software\microsoft\windows\currentversion\run", true)
   reg.setvalue("mengxianhui", "")
   end if
   initvar()
   messagebox.show("您已经设置了,请重新启动计算机看效果。", "提示", _
   messageboxbuttons.ok, messageboxicon.information)
   if checkbox1.checked = true then
   me.dispose(true)
   end if
   end sub
   
   private sub btnsave_click(byval sender as system.object, byval e as system.eventargs) _
   handles btnsave.click
   savesettings()
   end sub
  end class

TOP

返回顶部
AYBlue

Processed in 0.058890 second(s), 7 queries.

当前时区 GMT+8, 现在时间是 2009-1-10 10:50 京ICP备06054220号

清除 Cookies - 联系我们 - 163K.com - Archiver - WAP