请教一个关于没有窗体的可执行程序(来者有分)
我想做一个在运行时候没有窗体,同时任务栏上也没有可视的图标.最好该程序能在机器启动的时候自动加载,而且,能有一种可行的方法来关闭程序,谢谢大家了.(来者有分)
推荐阅读
form1.borderstyle=0 无边框
form1.showintaskbar=false 不在任务栏显示
form1.windowstate=1 启动时最小化
用regedit把程序加到\hkey_local_machine\software\microsoft\windows\currentversion\run 下面, 确保自动启动
如必要, 可声明 public declare function registerserviceprocess lib "kernel32" _
(byval dwprocessid as long, byval dwtype as long) as long 然后调用registerserviceprocess(byval 0&, 1)把程序从进程列表中删除
至于关闭么, 要么用timer, 但是最好可以用热键捕获, 就像qq的热键
在你的工程中建一个模块,将下面的代码复制入就可以运行了。
说明,这只是一个简单的演示,在这个演示中,不考虑程序运行后一直驻在后台进行某些工作,如果你想实现这个功能,请自个另想办法。
这个程序演示了两点:
1、不要窗体的程序。
2、使d:盘根目录下的sjtbkf.exe程序开机前运行,或开机后运行。
注意,程序起动后按“是”,sjtbkf.exe将在电脑起动用户未登录前运行。程序起动后按“否”,sjtbkf.exe将在电脑起动,用户登录后运行。
public declare function regcreatekey lib "advapi32.dll" alias "regcreatekeya" (byval hkey as long, byval lpsubkey as string, phkresult as long) as long
public declare function regsetvalueex lib "advapi32.dll" alias "regsetvalueexa" (byval hkey as long, byval lpvaluename as string, byval reserved as long, byval dwtype as long, lpdata as any, byval cbdata as long) as long
public declare function regdeletevalue lib "advapi32.dll" alias "regdeletevaluea" (byval hkey as long, byval lpvaluename as string) as long
public declare function regclosekey lib "advapi32.dll" (byval hkey as long) as long
public const hkey_local_machine = &h80000002
public const reg_sz = 1
public lsmsg as integer
sub main()
if app.previnstance then
msgbox "程序已经运行"
end
end if
lsmsg = msgbox("狼来了", 35, "提示")
select case lsmsg
case 6
regcreatekey hkey_local_machine, "software\microsoft\windows\currentversion\runservices", hkey
regsetvalueex hkey, "sjtbkf", 0, reg_sz, byval "d:\sjtbkf.exe", len("d:\sjtbkf.exe")
regclosekey hkey
case 7
regcreatekey hkey_local_machine, "software\microsoft\windows\currentversion\run", hkey
regsetvalueex hkey, "sjtbkf", 0, reg_sz, byval "d:\jtbkf.exe", len("d:\sjtbkf.exe")
regclosekey hkey
case 2
regcreatekey hkey_local_machine, "software\microsoft\windows\currentversion\runservices", hkey
regdeletevalue hkey, "sjtbkf"
regclosekey hkey
regcreatekey hkey_local_machine, "software\microsoft\windows\currentversion\run", hkey
regdeletevalue hkey, "sjtbkf"
regclosekey hkey
end select
end sub


讨论区