启动Windows程序自动运行(放入到注册表的Run)。Option Explicit
'---------------处理注册表的函数-----------------------
Private Declare Function RegCreateKey& Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey&, ByVal lpszSubKey$, lphKey&)
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As LongConst HKEY_LOCAL_MACHINE = &H80000002
Const REG_SZ = 1'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
Private Sub Command1_Click()
    '声明变量
    Dim sKeyName As String, sKeyValue As String, sKeyValueIcon As String
    Dim Ret As Integer, lphKey As Long    sKeyName = "Software\Microsoft\Windows\CurrentVersion\Run"
    sKeyValue = App.Path & IIf(Len(App.Path) > 3, "\" & "form1.exe", "form1.exe")
    Ret = RegCreateKey&(HKEY_LOCAL_MACHINE, sKeyName, lphKey)
    Ret = RegSetValue&(lphKey&, "", REG_SZ, sKeyValue, 0&)End Sub

解决方案 »

  1.   

    开机运行你的exe,在exe里写上 shell "ping 192.168.0.1 -t" 这不就是运行命令行了? 或者写 shell "cmd" 就能出命令行窗口还有办法就是开机会运行c:\autoexec.bat 文件,即批处理文件,在里面写dos命令
      

  2.   

    Command 函数返回命令行的参数部分,该命令行用于装入 Microsoft Visual Basic 或 Visual Basic 开发的可执行程序。语法Command说明当从命令行装入 Visual Basic 时,/cmd 之后的命令行的任何部分作为命令行的参数传递给程序。下面的示例中,cmdlineargs 代表 Command 函数返回的参数信息。VB /cmd cmdlineargs对于使用 Visual Basic 开发并编译为 .exe 文件的应用程序,Command 返回出现在命令行中应用程序名之后的任何参数。例如:MyApp cmdlineargs想知道如何在正在使用的应用程序的用户界面中改变命令行参数,请搜寻关于“命令行参数”的帮助。Command 函数示例本示例在某个函数中用 Command 函数获得命令行参数,并将命令行参数以 Variant 类型之数组返回。Function GetCommandLine(Optional MaxArgs)
    '声明变量。
    Dim C, CmdLine, CmdLnLen, InArg, I, NumArgs
    '检查是否提供了 MaxArgs 参数。
    If IsMissing(MaxArgs) Then MaxArgs = 10
    ' 使数组的大小合适。
    ReDim ArgArray(MaxArgs)
    NumArgs = 0: InArg = False
    '取得命令行参数。
    CmdLine = Command()
    CmdLnLen = Len(CmdLine)
    '以一次一个字符的方式取出命令行参数。
    For I = 1 To CmdLnLen
    C = Mid(CmdLine, I, 1)'检测是否为 space 或 tab。
    If (C <> " " And C <> vbTab) Then
    '若既不是 space 键,也不是 tab 键,
    '则检测是否为参数内含之字符。
    If Not InArg Then
    '新的参数。
    '检测参数是否过多。
    If NumArgs = MaxArgs Then Exit For
    NumArgs = NumArgs + 1
    InArg = True
    End If
    '将字符加到当前参数中。
    ArgArray(NumArgs) = ArgArray(NumArgs) + CElse
    '找到 space 或 tab。
    '将 InArg 标志设置成 False。
    InArg = False
    End If
    Next I
    '调整数组大小使其刚好符合参数个数。
    ReDim Preserve ArgArray(NumArgs)
    '将数组返回。
    GetCommandLine = ArgArray()
    End Function