0

I know how to run a vbscript file which has its file extension i.e. vbscript.vbs but how do you run a vbscript file without the file extension. I'm trying the following:

Process process = new Process();
process.StartInfo.FileName = @"vbscript"; //No extension
process.StartInfo.UseShellExecute  = false;
process.Start();
p deman
  • 75
  • 3
  • 11
  • Possible duplicate of [How to call a VBScript file in a C# application?](http://stackoverflow.com/questions/200422/how-to-call-a-vbscript-file-in-a-c-sharp-application) – user692942 Mar 14 '17 at 16:00
  • Related: [How to run VBScript from command line without Cscript/Wscript](http://stackoverflow.com/q/23074430/692942) – user692942 Mar 14 '17 at 16:01
  • Possible duplicate of [how can I run a script without an extension?](http://stackoverflow.com/q/29301043/692942) – user692942 Mar 14 '17 at 16:06
  • This is definitely not the first time this question has been answered. – user692942 Mar 14 '17 at 16:07

2 Answers2

1

You can use the MSScriptControl to execute VBSCript code. So you could read in your file and then execute the code with the MSScriptControl.

Here you can find an example and change it so it fit your needs: C# run VBScript with MSScriptControl AddObject with string failed

Community
  • 1
  • 1
user743414
  • 936
  • 10
  • 23
1

When you directly call a .vbs file, the system checks the registry to see what executable should handle the task. Instead of leaving it to the system, invoke the scripting host with the adecuated information

cscript.exe //e:vbscript noExtensionFile

or

wscript.exe //e:vbscript noExtensionFile

The //e: switch allows you to indicate the scripting engine that will be used to process the noExtensionFile file

MC ND
  • 69,615
  • 8
  • 84
  • 126