本文介绍了读取对vbs中com端口的访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望这是在正确的位置.

尝试从Serail端口,XP,管理员帐户读取.

如果缓冲区中有字符,则将引发以下错误:权限被拒绝,检查AtEndOfStream时代码为800A0046.

Hope this is in the right place.

Attempting to read from serail port, XP, admin accnt.

if there are chars in the buffer, then the following throws error: Permission denied, code: 800A0046 on the check of AtEndOfStream.

forRead=1
Set fso = CreateObject("Scripting.FileSystemObject")
Set comObj = fso.OpenTextFile("COM3:9600,N,8,1", for Read)
if not comObj.AtEndOfStream then
 msgbox comObj.ReadLine
end if
com.Close



另一方面,使用以下代码也可以正常工作:



Writing on the other hand works just fine with the following:

forWrite=2
Set fso = CreateObject("Scripting.FileSystemObject")
Set com = fso.OpenTextFile("COM4:9600,N,8,1", forWrite)
com.Write "Hello World"
com.Close



不确定其相关性,但我正在使用com0com连接两个端口(3和4)
我也许还应该补充一点,在VB6中使用MSCOMM obj可以读写没有问题.



Not sure its relevant but I''m using com0com to connect the two ports (3 & 4)
I should perhaps also add that using the MSCOMM obj in VB6 I can read and write no problem.

Any ideas why the permission denied for the read.

推荐答案


Dim comPort
Set comPort = CreateObject("MSCommLib.MSComm")



这篇关于读取对vbs中com端口的访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 00:08