2

I've recently started to port a project to C# from VB, so I apologize if this is a noob-ish question. I can't seem to get this process to work for the life of me:

Process p = default(Process);
try
{
    p.Start("powershell", 
            "-ExecutionPolicy ByPass -windowstyle hidden -file .\\scripts\Excel.ps1");
}
catch(Exception ex)
{
}

I'm getting several errors:

  • Unrecognized escape sequence

  • Member Process.Start(string, string) cannot be accessed with an instance reference; qualify it with a type name instead.

Any help would be appreciated.

EDIT: I'm moving from VB.net to C# because I prefer the syntax of C#, (coming from a java background) but I don't know a ton of C# visual studio workings.

EDIT2: Fixed the quotes with an @, still getting the

  • Member Process.Start(string, string) cannot be accessed with an instance reference; qualify it with a type name instead

error.

gman5500
  • 63
  • 2
  • 12

1 Answers1

2

You need to use the double slash in your Verbatim strings

p.Start("powershell", "-ExecutionPolicy ByPass -windowstyle hidden -file .\\scripts\\Excel.ps1");

The other option is to use the @ symbol before it.

For the second error:

The error message says that: Member Process.Start(string, string) cannot be accessed with an instance reference; qualify it with a type name instead. So you need to call it like a static method:

System.Diagnostics.Process.Start( "powershell", "-ExecutionPolicy ByPass -windowstyle hidden -file .\\scripts\\Excel.ps1");
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331