1

All what I am trying to do is to be able to run VBS script from code behind but I am getting this error: “The system cannot find the file specified”. I know the path name and I only need to execute that .vbs script but it is giving me hard time and I am not able to figure out. Please help. Thanks here is my code

System.Diagnostics.Process.Start(@"cscript  //B //Nologo \\loc1\test\myfolder\test1.vbs");

i have updated the code as shown below but i am getting a security warning asking me if i want to open it. Is there a way to not get those kind of warning and just run script without any warnings? here is the updated code:

  Process proc = null;
        try
        {
            string targetDir = string.Format(@"\\loc1\test\myfolder");//this is where mybatch.bat lies
            proc = new Process();
            proc.StartInfo.WorkingDirectory = targetDir;
            proc.StartInfo.FileName = "test1.vbs";
            proc.StartInfo.Arguments = string.Format("10");//this is argument
            proc.StartInfo.CreateNoWindow = false;
            proc.Start();
            proc.WaitForExit();
        }
        catch (Exception ex)
        {
           // Console.WriteLine("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString());
        }

2 Answers 2

3

Your code working fine for me, I think the error was in your File Path,

Better Confirm the File Path you given is valid or Not..

You can run that file like below also..

Process scriptProc = new Process();
scriptProc.StartInfo.FileName = @"cscript"; 
scriptProc.StartInfo.Arguments ="//B //Nologo \\loc1\test\myfolder\test1.vbs";
scriptProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
scriptProc.Start();
scriptProc.WaitForExit();
scriptProc.Close();

But check your File Path you given..

Sign up to request clarification or add additional context in comments.

2 Comments

i think this worked fine with no problem but if you could tell me if i want to run vbs script that is located on another server how would i do this? i am assuming i have to provide user name and password but don't name how to modify this code? thanks
@moe - Newer versions of Windows require you to authorize running script files like this. Update your question to reflect this information.
3

The parameters have to be included separately. There is an arguments field you use to pass arguments to the process.

You can use this as a guide for executing programs with command line from an application.

2 Comments

kevin i just updated my initial post please see above. i am getting a warnings before i am able to execute the script. thanks
For kicks, try moving the vbs script to a local drive, and see if that gets rid of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.