Windows 7 尝试使用VBScript创建命名管道时出错

Windows 7 尝试使用VBScript创建命名管道时出错,windows-7,vbscript,named-pipes,Windows 7,Vbscript,Named Pipes,我正在尝试在win7上使用VBScript创建命名管道。 这是我的代码(摘自): Set fs=CreateObject(“Scripting.FileSystemObject”) 设置a=fs.CreateTextFile(“\\.\pipe\PipeName”,True) a、 WriteLine(“这是一个测试。”) a、 接近 但我有一个错误(手动翻译,所以可能不准确): 与普通文本文件相同的代码可以正常工作: Set a=fs.CreateTextFile(“.\\PipeName”

我正在尝试在win7上使用VBScript创建命名管道。 这是我的代码(摘自):

Set fs=CreateObject(“Scripting.FileSystemObject”)
设置a=fs.CreateTextFile(“\\.\pipe\PipeName”,True)
a、 WriteLine(“这是一个测试。”)
a、 接近
但我有一个错误(手动翻译,所以可能不准确):

与普通文本文件相同的代码可以正常工作:

Set a=fs.CreateTextFile(“.\\PipeName”,True)
但是,当我试图逃避反斜杠时:

Set a=fs.CreateTextFile(“\\.\\pipe\\PipeName”,True)
我得到:

test.vbs(2, 1) Microsoft VBScript runtime error: Path not found
UPD:我以管理员身份运行脚本


UPD2:我找到了另一个解决问题的方法,不使用管道,所以我的问题有点过时,但我不知道该怎么办。

我尝试使用VBScript中的命名管道。我无法通过
fso.CreateTextFile(“\\.\pipe\MyPipe”)
创建命名管道

但我成功地从VBScript连接到经典应用程序创建的管道:

管道是由以下代码(pascal)创建的:

显示MessageBox时,我打开了VBScript

Set fso = CreateObject("Scripting.FileSystemObject")

MsgBox fso.OpenTextFile("\\.\pipe\test.htm",1).readLine

收到一条消息“你好”

您是否创建了名为“PipeName”的命名管道服务器?这段代码适用于我(我将我的管道命名为“HelloWorld”):

C#服务器:

static void Main(string[] args)
{
    using (var pipe = new NamedPipeServerStream("HelloWorld"))
    {
        pipe.WaitForConnection();
        StreamReader reader = new StreamReader(pipe);
        var line = reader.ReadLine();
        Console.WriteLine(line);
    }
    Console.ReadLine();
}
Dim fs, pipe
Set fs = CreateObject("Scripting.FileSystemObject")
Set pipe = fs.OpenTextFile("\\.\pipe\HelloWorld", 8, False, 0)
pipe.WriteLine("This is my message")
pipe.Close
VBScript客户端:

static void Main(string[] args)
{
    using (var pipe = new NamedPipeServerStream("HelloWorld"))
    {
        pipe.WaitForConnection();
        StreamReader reader = new StreamReader(pipe);
        var line = reader.ReadLine();
        Console.WriteLine(line);
    }
    Console.ReadLine();
}
Dim fs, pipe
Set fs = CreateObject("Scripting.FileSystemObject")
Set pipe = fs.OpenTextFile("\\.\pipe\HelloWorld", 8, False, 0)
pipe.WriteLine("This is my message")
pipe.Close

我想你提到的问题的答案是假设管道已经存在。我尝试了一些随机名称,但这没有帮助。谢谢你的想法,但我不想为wix编写二进制模块来实现这一点。是否需要从C/C#/pascal/等创建管道?我想使用管道重定向控制台应用程序的输入、输出和错误流,并假设我可以从VBS创建管道。是的,除非您能找到从VBScript创建管道的方法。不幸的是,我不能。