例:用vb生成一个123.exe 在程序里写入命令行方式假设命令为S为某一特定功能得出: 123.exe /s
2楼的意思是
[CODE]Dim cmdParas As String
cmdParas=Command()[/CODE]
如果还不够强大(那不晓得你要做什么了),就用下面这个
[CODE]Option Explicit
' mFunctions.bas
' Written by multiple1902
' 2007.5.8
' Last Edited By multiple1902
' 2007.6.5
' QQ 395273243
' Live multiple1902@hotmail.com
' Mail multiple001@gmail.com
Public Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" () As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As String, ByVal Source As Long, ByVal Length As Long)
Function sGetCommandLine() As String
' 获取本程序启动完整命令行
' 拓扑关系: 被 FUNC sGetAppExePathName()和 FUNC bArgExists() 依赖
Dim lRet As Long, sCmd As String
lRet = GetCommandLine
If lRet > 0 Then
sCmd = String(256, 32)
CopyMemory sCmd, lRet, Len(sCmd)
sCmd = Mid(sCmd, 1, InStr(1, sCmd, Chr(0)) - 1)
End If
sGetCommandLine = sCmd
' 关于API GetCommandLine() 的使用说明
' MSDN:
' The return value is a pointer to the command-line string for the current process.
' 返回字符串指针(指向当前命令行缓冲区的一个指针),并非字符串,API Viewer的声明是错误的。
' References:
' http://topic.csdn.net/t/20020410/17/636954.html
End Function
Function sGetAppExePathName() As String
' 得到应用程序完整路径
' 拓扑关系:依赖于 sGetCommandLine()
Dim sBufCmd As String, sResponse As String
sBufCmd = sGetCommandLine()
' 若完整命令行以半角双引号开始
If """" = Left(sBufCmd, 1) Then
Dim iPosPairQuot As Integer
iPosPairQuot = InStr(2, sBufCmd, """")
sResponse = Mid(sBufCmd, 2, iPosPairQuot - 2)
Else
' 若不存在半角双引号则路径中不包含空格,无需考虑空格的情形
Dim iPosSpace As Integer
iPosSpace = InStr(2, sBufCmd, " ")
sResponse = Left(sBufCmd, iPosSpace - 1)
End If
sGetAppExePathName = sResponse
End Function
Function bArgExists(sArg As String) As Boolean
' 返回布尔值:程序启动参数中是否包含指定字符串
' 拓扑关系:依赖于 sGetCommandLine()
Dim sBufCmd As String, bResponse As Boolean
sBufCmd = sGetCommandLine()
If """" = Left(sBufCmd, 1) Then
Dim iPosPairQuot As Integer
iPosPairQuot = InStr(2, sBufCmd, """")
bResponse = (InStr(1, Right(sBufCmd, Len(sBufCmd) - iPosPairQuot - 1), sArg) > 0)
Else
Dim iPosSpace As Integer
iPosSpace = InStr(2, sBufCmd, " ")
bResponse = (InStr(1, Right(sBufCmd, Len(bResponse) - iPosSpace), sArg) > 0)
End If
bArgExists = bResponse
End Function[/CODE]