Private Sub cmdTest_Click()
Dim obj As Object
Dim KFO As Object
Dim sK3Path As String
Dim sParm As String
Dim sBakSplit As String
Set KFO = CreateObject("KFO.Reg")
'获取K3ERP路径
sK3Path = KFO.GetKeyValue("HKEY_LOCAL_MACHINE\SOFTWARE\KINGDEE\KDPRODUCT", "Path", "")
'从注册表获主控台登录取命令参数分隔符,备份起来以便恢复
sBakSplit = KFO.GetKeyValue("HKEY_CURRENT_USER\SoftWare\KingDee\K3", "LoginParm", "")
'1 sLoginType String 登录方式:-LoginWin 域用户身份登录-LoginUser 命名用户身份登录
'2 sAcctNumber String 账套代码 例如帐套代码为:01.01
'3 sOrgPass String 组织机构密码,例如组织机构01的代码为:888888,无组织机构时传入空即可
'4 sUserName String 用户名,如果以域用户身份登录时传入空
'5 sUserPass String 用户密码,如果以域用户身份登录时传入空
'命令参数规则 sLoginType + " " + sAcctNumber + " " + sOrgPass + " " + sUserName + " " + sUserPass
'根据客户应用场景,选择以下任意一种登录方式
'第一种登录方式:以当前WINDOWS域用户身份无界面登录 -LoginWin
'比如:要登录帐套的代码为01.01 机构组织密码为888888,则命令参数应如下
sParm = "-LoginWin" & " " & "01.01" & " " & "888888" '各参数以空格符隔开
'第二种登录方式:以命名用户身份无界面登录 -LoginUser
'比如:要登录帐套的代码为01.01 机构组织密码为888888 用户名为Administrator,密码为123456,则命名参数如下:
sParm = "-LoginUser" & " " & "01.01" & " " & "888888" & " " & "Administrator" & " " & "123456" '各参数以空格符隔开
'将无界面登录命令参数分隔符号(空格)信息写到注册,以便Shell KDMain时读取分割命令参数
Call KFO.SetKeyValue("HKEY_CURRENT_USER\SoftWare\KingDee\K3", "LoginParm", " ")
Call Shell(sK3Path & "KDMain.exe " & sParm, vbNormalFocus) '打开K3主控台
'还原注册表信息
Call KFO.SetKeyValue("HKEY_CURRENT_USER\SoftWare\KingDee\K3", "LoginParm", sBakSplit)
Set KFO = Nothing
End Sub