怎样在Exe间传递参数

原文地址:http://www.vbdotnetheaven.com/UploadFile/pragati2478/HowtoPassParameterinEXE04052006084011AM/HowtoPassParameterinEXE.aspx
作者:Pragati  April 05, 2006

有时开发人员需要从一个exe中调用另一个exe。当调用exe是可能是需要传递参数的。

 

用下面的代码在全局模块中建立一个用来被调用的exe。设置启动项为Submain()函数。

 

在例子中有两个参数是通过exe传递过来的。参数是以” ”分割而被传递的。

None.gif Imports  System.Windows.Forms 
None.gif
ExpandedBlockStart.gifContractedBlock.gif
Module Module1 Module Module1
InBlock.gif
InBlock.gif 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Public Sub main()Sub main()
InBlock.gif
InBlock.gif            
Dim frm As New Form1
InBlock.gif
InBlock.gif            
Dim str() As String
InBlock.gif
InBlock.gif            
str = GetCommandLineArgs()
InBlock.gif
InBlock.gif            
If (UBound(str>= 0Then
InBlock.gif
InBlock.gif                a 
= str(0).ToString
InBlock.gif
InBlock.gif                b 
= str(1).ToString
InBlock.gif
InBlock.gif            
End If
InBlock.gif
InBlock.gif            Application.Run(frm)
InBlock.gif
ExpandedSubBlockEnd.gif        
End Sub

InBlock.gif
InBlock.gif 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
Function GetCommandLineArgs()Function GetCommandLineArgs() As String()
InBlock.gif
InBlock.gif            
' Declare variables.
InBlock.gif

InBlock.gif            
Dim separators As String = " "
InBlock.gif
InBlock.gif            
Dim commands As String = Microsoft.VisualBasic.Command()
InBlock.gif
InBlock.gif            
Dim args() As String = commands.Split(separators.ToCharArray)
InBlock.gif
InBlock.gif            
Return args
InBlock.gif
ExpandedSubBlockEnd.gif        
End Function

InBlock.gif
InBlock.gif 
InBlock.gif
ExpandedBlockEnd.gif
End Module

None.gif

 

将下面的代码写道调用的exe中,这里两个参数,”1””M”被传递过去了。

proc.Start(Application.StartupPath & "\Sambandh.exe", "1 M")

转载于:https://www.cnblogs.com/c-delight/archive/2006/04/06/368249.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值