By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

How to send data to a C# App from VBScript

P: n/a
Hello all,

I've been working on an application for a while now and have now come
to a standstill.

I have an application that I intend to have stored on a file server
(developed in C#), which is where the application will be directly ran
from. While running, the application will run a various assortment of
VBScripts (also located on the file server) to which I would like the
vbscripts to be able to pass data back to the currently running
application.

There will never be more than one instance of the application running,
and the scripts will never be ran w/o the application.

I have looked into making the executable a COM Server but then I found
out when publishing public functions form an Executable to COM, only
makes a new object when instantiating it. In other words, in my
VBScript if I can CreateObject() It literally creates a new instance
of the executable. Im trying to pass data to the currently running
instance. I basically want to send status and such from the vbscript
to the running executable. The running executable will be the calling
process to run these scripts.

Does anyone have any ideas on how I can do this?

I'd like to avoid the registry to do this, unless its just a one time
addition to the registry.

Thanks so much in advance for your help!

Feb 19 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a


<Sh**********@gmail.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
Hello all,

I've been working on an application for a while now and have now come
to a standstill.

I have an application that I intend to have stored on a file server
(developed in C#), which is where the application will be directly ran
from. While running, the application will run a various assortment of
VBScripts (also located on the file server) to which I would like the
vbscripts to be able to pass data back to the currently running
application.

There will never be more than one instance of the application running,
and the scripts will never be ran w/o the application.

I have looked into making the executable a COM Server but then I found
out when publishing public functions form an Executable to COM, only
makes a new object when instantiating it. In other words, in my
VBScript if I can CreateObject() It literally creates a new instance
of the executable. Im trying to pass data to the currently running
instance. I basically want to send status and such from the vbscript
to the running executable. The running executable will be the calling
process to run these scripts.

Does anyone have any ideas on how I can do this?

I'd like to avoid the registry to do this, unless its just a one time
addition to the registry.

Thanks so much in advance for your help!
I would just shell out (using System.Diagnostics.Process) to cscript.exe,
passing it the name of the vbscript file and redirect standard output. Then
in the script use WScript.Echo to write to the output.

Like this:
string scriptName = "foo.vbs";
ProcessStartInfo si = new
ProcessStartInfo("cscript.exe",scriptName);
si.RedirectStandardOutput = true;
si.UseShellExecute = false;

Process p = Process.Start(si);
while (true)
{
string s = p.StandardOutput.ReadLine();
if (s == null)
{
break;
}
Console.WriteLine("VBScript output:" + s);
}
David

Feb 19 '07 #2

P: n/a
<Sh**********@gmail.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
Hello all,

I've been working on an application for a while now and have now come
to a standstill.

I have an application that I intend to have stored on a file server
(developed in C#), which is where the application will be directly ran
from. While running, the application will run a various assortment of
VBScripts (also located on the file server) to which I would like the
vbscripts to be able to pass data back to the currently running
application.

There will never be more than one instance of the application running,
and the scripts will never be ran w/o the application.

I have looked into making the executable a COM Server but then I found
out when publishing public functions form an Executable to COM, only
makes a new object when instantiating it. In other words, in my
VBScript if I can CreateObject() It literally creates a new instance
of the executable. Im trying to pass data to the currently running
instance. I basically want to send status and such from the vbscript
to the running executable. The running executable will be the calling
process to run these scripts.

Does anyone have any ideas on how I can do this?

I'd like to avoid the registry to do this, unless its just a one time
addition to the registry.

Thanks so much in advance for your help!

Both C# and your VBScript run in separate processes, that means that you'll have to start
the script from C# using System.Diagnostics.Process, all you can do to "communicate back" to
the parent process is by redirecting the standard output of the scripting engine.
This is quite limiting, all you can do is send text back using WScript.Echo, but maybe it
suits your needs.

Willy.
Feb 19 '07 #3

P: n/a
On Feb 19, 5:08 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
<ShieldsJa...@gmail.comwrote in message

news:11**********************@a75g2000cwd.googlegr oups.com...


Hello all,
I've been working on an application for a while now and have now come
to a standstill.
I have an application that I intend to have stored on a file server
(developed in C#), which is where the application will be directly ran
from. While running, the application will run a various assortment of
VBScripts (also located on the file server) to which I would like the
vbscripts to be able to pass data back to the currently running
application.
There will never be more than one instance of the application running,
and the scripts will never be ran w/o the application.
I have looked into making the executable a COM Server but then I found
out when publishing public functions form an Executable to COM, only
makes a new object when instantiating it. In other words, in my
VBScript if I can CreateObject() It literally creates a new instance
of the executable. Im trying to pass data to the currently running
instance. I basically want to send status and such from the vbscript
to the running executable. The running executable will be the calling
process to run these scripts.
Does anyone have any ideas on how I can do this?
I'd like to avoid the registry to do this, unless its just a one time
addition to the registry.
Thanks so much in advance for your help!

Both C# and your VBScript run in separate processes, that means that you'll have to start
the script from C# using System.Diagnostics.Process, all you can do to "communicate back" to
the parent process is by redirecting the standard output of the scripting engine.
This is quite limiting, all you can do is send text back using WScript.Echo, but maybe it
suits your needs.

Willy.- Hide quoted text -

- Show quoted text -
Im familar w/ wscript.echo, but my goal is to have the output
displayed within the gui I am creating. I basically want to create a
library vb script function foo(string) that passes the string to the
external application....

I am aware of how to call the vbscripts....

Feb 20 '07 #4

P: n/a


<Sh**********@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
On Feb 19, 5:08 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
><ShieldsJa...@gmail.comwrote in message

news:11**********************@a75g2000cwd.googleg roups.com...


Hello all,
I've been working on an application for a while now and have now come
to a standstill.
I have an application that I intend to have stored on a file server
(developed in C#), which is where the application will be directly ran
from. While running, the application will run a various assortment of
VBScripts (also located on the file server) to which I would like the
vbscripts to be able to pass data back to the currently running
application.
There will never be more than one instance of the application running,
and the scripts will never be ran w/o the application.
I have looked into making the executable a COM Server but then I found
out when publishing public functions form an Executable to COM, only
makes a new object when instantiating it. In other words, in my
VBScript if I can CreateObject() It literally creates a new instance
of the executable. Im trying to pass data to the currently running
instance. I basically want to send status and such from the vbscript
to the running executable. The running executable will be the calling
process to run these scripts.
Does anyone have any ideas on how I can do this?
I'd like to avoid the registry to do this, unless its just a one time
addition to the registry.
Thanks so much in advance for your help!

Both C# and your VBScript run in separate processes, that means that
you'll have to start
the script from C# using System.Diagnostics.Process, all you can do to
"communicate back" to
the parent process is by redirecting the standard output of the scripting
engine.
This is quite limiting, all you can do is send text back using
WScript.Echo, but maybe it
suits your needs.

Willy.- Hide quoted text -

- Show quoted text -

Im familar w/ wscript.echo, but my goal is to have the output
displayed within the gui I am creating. I basically want to create a
library vb script function foo(string) that passes the string to the
external application....
If you use CScript for your script host then

sub foo(string)
Wscript.Echo(string)
end sub

will write the string to the process's standard output. When you spawn a
process from C#, you can redirect the child process's standard output and
read it from C#.

David

Feb 20 '07 #5

P: n/a
On Feb 20, 9:35 am, "David Browne" <davidbaxterbrowne no potted
m...@hotmail.comwrote:
<ShieldsJa...@gmail.comwrote in message

news:11**********************@m58g2000cwm.googlegr oups.com...


On Feb 19, 5:08 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
<ShieldsJa...@gmail.comwrote in message
>news:11**********************@a75g2000cwd.googleg roups.com...
Hello all,
I've been working on an application for a while now and have now come
to a standstill.
I have an application that I intend to have stored on a file server
(developed in C#), which is where the application will be directly ran
from. While running, the application will run a various assortment of
VBScripts (also located on the file server) to which I would like the
vbscripts to be able to pass data back to the currently running
application.
There will never be more than one instance of the application running,
and the scripts will never be ran w/o the application.
I have looked into making the executable a COM Server but then I found
out when publishing public functions form an Executable to COM, only
makes a new object when instantiating it. In other words, in my
VBScript if I can CreateObject() It literally creates a new instance
of the executable. Im trying to pass data to the currently running
instance. I basically want to send status and such from the vbscript
to the running executable. The running executable will be the calling
process to run these scripts.
Does anyone have any ideas on how I can do this?
I'd like to avoid the registry to do this, unless its just a one time
addition to the registry.
Thanks so much in advance for your help!
Both C# and your VBScript run in separate processes, that means that
you'll have to start
the script from C# using System.Diagnostics.Process, all you can do to
"communicate back" to
the parent process is by redirecting the standard output of the scripting
engine.
This is quite limiting, all you can do is send text back using
WScript.Echo, but maybe it
suits your needs.
Willy.- Hide quoted text -
- Show quoted text -
Im familar w/ wscript.echo, but my goal is to have the output
displayed within the gui I am creating. I basically want to create a
library vb script function foo(string) that passes the string to the
external application....

If you use CScript for your script host then

sub foo(string)
Wscript.Echo(string)
end sub

will write the string to the process's standard output. When you spawn a
process from C#, you can redirect the child process's standard output and
read it from C#.

David- Hide quoted text -

- Show quoted text -
Oh really??

How would I go about redirecting the output so that I can read it in
C#?

That sounds perfect!

Feb 20 '07 #6

P: n/a
On Feb 20, 9:35 am, "David Browne" <davidbaxterbrowne no potted
m...@hotmail.comwrote:
<ShieldsJa...@gmail.comwrote in message

news:11**********************@m58g2000cwm.googlegr oups.com...


On Feb 19, 5:08 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
<ShieldsJa...@gmail.comwrote in message
>news:11**********************@a75g2000cwd.googleg roups.com...
Hello all,
I've been working on an application for a while now and have now come
to a standstill.
I have an application that I intend to have stored on a file server
(developed in C#), which is where the application will be directly ran
from. While running, the application will run a various assortment of
VBScripts (also located on the file server) to which I would like the
vbscripts to be able to pass data back to the currently running
application.
There will never be more than one instance of the application running,
and the scripts will never be ran w/o the application.
I have looked into making the executable a COM Server but then I found
out when publishing public functions form an Executable to COM, only
makes a new object when instantiating it. In other words, in my
VBScript if I can CreateObject() It literally creates a new instance
of the executable. Im trying to pass data to the currently running
instance. I basically want to send status and such from the vbscript
to the running executable. The running executable will be the calling
process to run these scripts.
Does anyone have any ideas on how I can do this?
I'd like to avoid the registry to do this, unless its just a one time
addition to the registry.
Thanks so much in advance for your help!
Both C# and your VBScript run in separate processes, that means that
you'll have to start
the script from C# using System.Diagnostics.Process, all you can do to
"communicate back" to
the parent process is by redirecting the standard output of the scripting
engine.
This is quite limiting, all you can do is send text back using
WScript.Echo, but maybe it
suits your needs.
Willy.- Hide quoted text -
- Show quoted text -
Im familar w/ wscript.echo, but my goal is to have the output
displayed within the gui I am creating. I basically want to create a
library vb script function foo(string) that passes the string to the
external application....

If you use CScript for your script host then

sub foo(string)
Wscript.Echo(string)
end sub

will write the string to the process's standard output. When you spawn a
process from C#, you can redirect the child process's standard output and
read it from C#.

David- Hide quoted text -

- Show quoted text -
NM, I found it! Yall are awesome and this is so much easier!!!

Thanks!!!

Feb 20 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.