Smaug
Smaug

Reputation: 2673

Needs to disable the cmd pop up when i call vbs through c#

I used the following lines in the vbs script, which called .vbs from the C#.

objShell.Run("net stop msdtc"),1,True
objShell.Run("net start msdtc"),1,True

In c$, the follwoing code used for calling .vbs with administrative privillage. Even though i set the WindowStyle to hidden the cmd pop up opens at runtime. I dont want to open pop up. please help me

ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + @"cscript.exe DTCSECURITY.vbs");
ProcessInfo.WindowStyle = ProcessWindowStyle.Hidden;                
ProcessInfo.UserName = @"administrator";
ProcessInfo.Password = StringToSecureString("password12$");
ProcessInfo.WindowStyle = ProcessWindowStyle.Hidden;

process = Process.Start(ProcessInfo);
process.WaitForExit();

Upvotes: 0

Views: 1584

Answers (2)

Grant Thomas
Grant Thomas

Reputation: 45083

You should specify CreateNoWindow = true; (see the documentation here).

ProcessWindowStyle dictates the state of the window (in terms of maximised, minimised, visible etc.) once it has been created.

Upvotes: 1

Moriya
Moriya

Reputation: 7906

ProcessInfo.CreateNoWindow = true;

CreateNoWindow:

Allows you to run a command line program silently. It does not flash a console window.

Upvotes: 1

Related Questions