Share Information between C# and VBScript with Registry


VBScript is widely used to write automation and system scripts. It is more powerful within Windows Script Host (WSH). With the introduction of C# and .Net framework, people may start to use VBScript and C# in the mixed environment. As an obvious example, C# can be used to write a graphic user interface (GUI) to provide runtime information for VBScript.

There are many ways to share information between a C# program and VBScript. It an be achieved from a configuration or initialization file, from arguments and from registry. This article contains sample functions to work with registry in both C# and VBScript.

To run the demo your self, just copy into your local directory and unzip it.  Run VBScript from command line wth CScript.exe. RegDemo.exe can be compiled from RegDemo.cs by running build.bat. Visual Studio.Net is not used in this article.

Both VBScript and C# program can set and get registry key at HKEY_LOCAL_MACHINE\HKEY_LOCAL_MACHINE\SOFTWARE\SunShine\RegDemo. For demo purpose you are restricted to get and set values for three keys named UserName, Department and Application. All keys are of type REG_SZ.


  1. You may need to set the value before you can retrieve it back. Otherwise, you get error message.
  2. It might be a good idea to launch RegEdit to have a look at the real localtion of these keys.
  3. Set a value with one application and then retrieve it from another, and that is the point of this article.