Web页面中可以用以下用读取epass1000锁的硬件号.可是现在我想在WindowsForm中用C#读出锁的原件号,怎么写啦?<script id="Script1" language="vbscript">
<!--
Function GetClientSerial(epass1,sjs)
Dim ErrCode,ErrPin
Dim serial,buf,sPin
On Error Resume Next
'创建对象
Set epsCtx=CreateObject("epsmodu.epsCtx")
If(err<>0) Then
If len(sjs)<8 Then MsgBox "您的身份认证锁安装的不正确,不能进行验证。"&vbnewline,,"提示"
GetClientSerial=""
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
Exit Function
End If
'打开加密锁
ErrCode=epass1.OpenDevice (1)
If ErrCode<>0 Then
If len(sjs)<8 Then MsgBox "您没有插好身份认证锁或者它正被别的程序占用!",,"提示"
GetClientSerial=""
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
Exit Function
End If
'读取序列号
If len(sjs)<8 Then
'MsgBox epsCtx.SerialNumber(1),,"提示"
'MsgBox epsCtx.SerialNumber(0),,"提示"
serial=Hex(epsCtx.SerialNumber(1))+""+Hex(epsCtx.SerialNumber(0))
'返回值
GetClientSerial=serial
Else
'设置缓冲
For i=0 To Len(sjs)-1
str=mid(Cstr(sjs),i+1,1)
'MsgBox str,,"提示"
epass1.TextBuf(i)=asc(str)
Next
'sPin = InputBox("请输入身份认证锁密码:","输入密码")
sPin = "12345678"
'sPin="&h"+sPin
ErrPin=epass1.VerifyPin(Clng(sPin))
'MsgBox EPS_SUCCESS,,EPS_SUCCESS
If ErrPin<>EPS_SUCCESS Or ErrPin="" Then
'MsgBox "输入加密锁用户密码错误!",,"警告"
GetClientSerial=""
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
Exit Function
Else
'取得客户端代码
ErrCode = epass1.HmacMd5(0,1,0,2, len(sjs))
If (ErrCode <> ITK_SUCCESS) Then
MsgBox "无权限,不能进行客户端身份校验!",,"警告"
GetClientSerial=""
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
Exit Function
Else
buf=""
For i = 0 To 15
if (epass1.DigestBuf(i)<16) then
buf=buf & "0" & Hex(epass1.DigestBuf(i))
else
buf = buf & Hex(epass1.DigestBuf(i))
end if
Next '返回值
GetClientSerial=buf
End If
End If
End If
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
End Function
'-------------------------------------------
Function GetInsideSerial(epass1,sjs)
Dim ErrorCode
Dim ePassCtx,ePass
Dim SerialNum,CharBuf
On Error Resume Next
Set ePassCtx=CreateObject("epsmodu.epsCtx")
If(err<>0) Then
If len(sjs)<8 Then MsgBox "您的身份认证锁安装的不正确,不能进行验证。"&vbnewline,,"提示"
GetInsideSerial=""
'关闭设备
epass1.CloseDevice
Set ePassCtx=Nothing
Exit Function
End If
ErrorCode=epass1.OpenDevice(1)
If ErrorCode<>0 Then
If len(sjs)<8 Then MsgBox "您没有插好身份认证锁或者它正被别的程序占用!",,"提示"
'关闭设备
epass1.CloseDevice
Set ePassCtx=Nothing
GetInsideSerial=""
Exit Function
End If
ErrorCode = epass1.SelectFile(6,1) '打开根目录下Id为10(即16进制0A)的文件 If (ErrorCode <> 0) Then
'MsgBox "选择目录6下1文件出错。",,"提示"
epass1.CloseDevice
Set ePassCtx=Nothing
GetInsideSerial=""
Exit Function
End If
Dim i,sBuf,sText
ErrorCode = epass1.ReadFile(0,16) '从起点开始读,读5个字节
If (ErrorCode <> 0) Then
'MsgBox "读目录6下1文件出错。",,"提示"
epass1.CloseDevice
Set ePassCtx=Nothing
GetInsideSerial=""
Exit Function
Else
For i = 0 To epass1.FileBufLen - 1 'FileBufLen属性中将包含际读出的字节数
sText = sText + Chr(epass1.FileBuf(i)) 'FileBuf中则包含实际读出的内容
'sBuf = sBuf + Str(epass1.FileBuf(i))
Next
GetInsideSerial=sText
End If
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
End Function
-->
</script>
<!--
Function GetClientSerial(epass1,sjs)
Dim ErrCode,ErrPin
Dim serial,buf,sPin
On Error Resume Next
'创建对象
Set epsCtx=CreateObject("epsmodu.epsCtx")
If(err<>0) Then
If len(sjs)<8 Then MsgBox "您的身份认证锁安装的不正确,不能进行验证。"&vbnewline,,"提示"
GetClientSerial=""
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
Exit Function
End If
'打开加密锁
ErrCode=epass1.OpenDevice (1)
If ErrCode<>0 Then
If len(sjs)<8 Then MsgBox "您没有插好身份认证锁或者它正被别的程序占用!",,"提示"
GetClientSerial=""
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
Exit Function
End If
'读取序列号
If len(sjs)<8 Then
'MsgBox epsCtx.SerialNumber(1),,"提示"
'MsgBox epsCtx.SerialNumber(0),,"提示"
serial=Hex(epsCtx.SerialNumber(1))+""+Hex(epsCtx.SerialNumber(0))
'返回值
GetClientSerial=serial
Else
'设置缓冲
For i=0 To Len(sjs)-1
str=mid(Cstr(sjs),i+1,1)
'MsgBox str,,"提示"
epass1.TextBuf(i)=asc(str)
Next
'sPin = InputBox("请输入身份认证锁密码:","输入密码")
sPin = "12345678"
'sPin="&h"+sPin
ErrPin=epass1.VerifyPin(Clng(sPin))
'MsgBox EPS_SUCCESS,,EPS_SUCCESS
If ErrPin<>EPS_SUCCESS Or ErrPin="" Then
'MsgBox "输入加密锁用户密码错误!",,"警告"
GetClientSerial=""
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
Exit Function
Else
'取得客户端代码
ErrCode = epass1.HmacMd5(0,1,0,2, len(sjs))
If (ErrCode <> ITK_SUCCESS) Then
MsgBox "无权限,不能进行客户端身份校验!",,"警告"
GetClientSerial=""
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
Exit Function
Else
buf=""
For i = 0 To 15
if (epass1.DigestBuf(i)<16) then
buf=buf & "0" & Hex(epass1.DigestBuf(i))
else
buf = buf & Hex(epass1.DigestBuf(i))
end if
Next '返回值
GetClientSerial=buf
End If
End If
End If
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
End Function
'-------------------------------------------
Function GetInsideSerial(epass1,sjs)
Dim ErrorCode
Dim ePassCtx,ePass
Dim SerialNum,CharBuf
On Error Resume Next
Set ePassCtx=CreateObject("epsmodu.epsCtx")
If(err<>0) Then
If len(sjs)<8 Then MsgBox "您的身份认证锁安装的不正确,不能进行验证。"&vbnewline,,"提示"
GetInsideSerial=""
'关闭设备
epass1.CloseDevice
Set ePassCtx=Nothing
Exit Function
End If
ErrorCode=epass1.OpenDevice(1)
If ErrorCode<>0 Then
If len(sjs)<8 Then MsgBox "您没有插好身份认证锁或者它正被别的程序占用!",,"提示"
'关闭设备
epass1.CloseDevice
Set ePassCtx=Nothing
GetInsideSerial=""
Exit Function
End If
ErrorCode = epass1.SelectFile(6,1) '打开根目录下Id为10(即16进制0A)的文件 If (ErrorCode <> 0) Then
'MsgBox "选择目录6下1文件出错。",,"提示"
epass1.CloseDevice
Set ePassCtx=Nothing
GetInsideSerial=""
Exit Function
End If
Dim i,sBuf,sText
ErrorCode = epass1.ReadFile(0,16) '从起点开始读,读5个字节
If (ErrorCode <> 0) Then
'MsgBox "读目录6下1文件出错。",,"提示"
epass1.CloseDevice
Set ePassCtx=Nothing
GetInsideSerial=""
Exit Function
Else
For i = 0 To epass1.FileBufLen - 1 'FileBufLen属性中将包含际读出的字节数
sText = sText + Chr(epass1.FileBuf(i)) 'FileBuf中则包含实际读出的内容
'sBuf = sBuf + Str(epass1.FileBuf(i))
Next
GetInsideSerial=sText
End If
'关闭设备
epass1.CloseDevice
Set epsCtx=Nothing
End Function
-->
</script>
解决方案 »
- 神啊~~一個邏輯問題 難死我了!
- C#读取word
- Winform怎样判断点击了DataGridView的标题栏Header?
- WinFrom 图片由另一进程使用,因此该进程无法访问改文件 ?
- 请问:怎么能 避免重复触发DataBindingComplete事件?
- 如何从一个com对象中的控件句柄(handle)返回控件,并放在winform上!
- 哪位给段使用正则表达式从一字符串中提取出所需部分的源码例子?
- C#想要实现在别的程序中打开那个程序的文件,如何实现(拜托了,在线等ing)
- 求公交线路最佳算法
- VS IDE使用问题??
- C# 向控制台程序发送 ctrl+C 命令
- 链接数据库,显示提示
System.Type CreateObj = System.Type.GetTypeFromProgID("epsmodu.epsCtx");
object _EpsCtx= System.Activator.CreateInstance(CreateObj);
你看下 _EpsCtx是否为null 如果不为null 可以通过反射来解决
不过这个工具是vb.net转换成c#.net的,不知道楼主说的vb可不可以转换。
试一下吧
还有其他转的方法。
当然如果程序不是很大的话,你直接看着vb翻译成c#也是可以的。
再从网上下载一个sharp develop软件可以任意转为.net的任何代码。。
sharp develp才3M,功能虽然比不上vs2005,但用起来超爽。。
oText = " Serial Number : ";
oText = oText + props + "";
System.Console.WriteLine(oText + "");