run vbs script file using C# code
Asked Answered
S

1

0

I am trying to execute a vbs file using C# code. The vbs file has the code to invoke an application on my machine. I am able to run the vbs script file when i run the C# code locally, but when i deploy my code to SharePoint environment it looks like it is not even executing the file. I dont receive any error message or any message i added in the vbs script file. Below is the C# code i am using to run the vbs script file. Can someone please tell me if i am missing anything here?

C# Code:

  Process scriptProc = new Process();
    scriptProc.StartInfo.FileName = @"cscript";
    scriptProc.StartInfo.Arguments = @"//B //Nologo C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\template\layouts\segmentationtools\test1.vbs";
    scriptProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    scriptProc.Start();
    scriptProc.WaitForExit();
    scriptProc.Close();

VBS Code:

Dim qtApp 
Set qtApp = CreateObject("QuickTest.Application","Server IP address")
MsgBox("Hello world")
qtApp.Launch
qtApp.Visible = True 
Schade answered 2/7, 2013 at 23:41 Comment(7)
"asp.net" in sense of trying to run application that shows UI from under service account?Crackerbarrel
Hi Alexei, Sorry i dint follow your question. Can you please brief what you are asking here?Schade
Where do you try to run that C# code? Console app/from some random service/IIS/... and what account this code runs under?Crackerbarrel
I am running this code on SharePoint web application. Normally i deploy the aspx pages in _layouts folder and .dll related to the code is deployed in the bin folder of web application. I am not sure whether the code is running on system account or any other account because i do not have the permissions to the server and we have been given access to the deployment folder on server.Can you please let me know if there is any way to see on which account the code is running and does it really matter to see on what account the code is running? Sorry i am new to this vbs file running. ThanksSchade
Your sample script obviously not going to do anything sane as it tries to show UI, but launching command line tools/scripts that only output to console should be ok. You may need to use RunWithElevatePrivileges method to be able to run anything/access file system... Configuring you local SharePoint properly and accessing with non-admin/non-local account will go long way in helping to debug the issue.Crackerbarrel
Thanks for your response. If i am understanding it correct, do you want me to run my C# code with RunWithElevatePrivilages method so that it will run my code with full control permissions on SharePoint Server?Schade
No, it is so your code runs under local app pool's account, not some other "random" impersonated account (which is somewhat side effect of getting full control). I also recommend searching for other similar questions on "how to run exe from service/IIS process for more details.Crackerbarrel
T
1

If what you are trying to do is start a UFT/QTP test using a C# application, then the following example will help you:

http://www.codeproject.com/Answers/288214/How-to-Automate-Qtp-with-C-sharp#answer4

It is a bit different way from what you tried to do in your code (Run a C# app that runs a vbs file that runs a QTP test), the following code is directly running a QTP test straight from the C# application.

I used that code to develop an app that is scheduling and control QTP tests.

Tyrr answered 10/11, 2013 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.