0

Does anyone know if there is a way to use C# to detect if a user or process starts a script such as a .bat, .ps1, .vbs, etc script file?

I am aware of the System.Diagnostics.Process.GetProcesses(), however this does not seem to detect running a running script.

Thanks

Dave
  • 2,473
  • 2
  • 30
  • 55
  • Have you tried this?`var process = Process.Start(your bat here); process.WaitForExit();` http://stackoverflow.com/questions/5519328/executing-batch-file-in-c-sharp – Tomasz Juszczak Mar 07 '17 at 23:24
  • @TomaszJuszczak: That's not what the question is asking. Read it again. – Ken White Mar 07 '17 at 23:25
  • 4
    A .bat file is not run itself; it's run by cmd.exe. You can detect it (and all the others) by watching for their host process (cmd.exe, powershell, cscript/wscript). You can't monitor a script or batch file itself, because it never executes on its own. – Ken White Mar 07 '17 at 23:27
  • To add to @KenWhite's comment, you can find the arguments used to invoke those host processes [by looking at this answer](http://stackoverflow.com/a/2633674/215552). However, I'm guessing you'd not be able to tell if someone just ran cmd.exe from the Run window and typed "blah.bat" or something. – Heretic Monkey Mar 07 '17 at 23:32

0 Answers0