0

I know its been asked a thousand times and I tried quite a few solutions but I need help to execute a batch file.

I'm using json.net and through debugger it's getting the correct value. But I'm getting an error. And reason for json is because the file path to the batch file can change and I want to write this in such a way the program can change file path too.

Process.Start("cmd.exe", @"/k " + rootObject.Activate.BatchLocation.ToString());

Error

'c:\pathtofile.bat' is not an recognized internal or external command.[code]

deskmonkey
  • 23
  • 7
  • add `var cmd = "cmd.exe /k " + rootObject.Activate.BatchLocation.ToString();`, copy the runtime value of that into a command prompt. if this works, we can move on to reasons less obvious than a simple name mismatch. – Cee McSharpface Oct 31 '17 at 17:00
  • I added that and it failed. To note I added your line and changed to "Process.Start(cmd);" I have notice that when I copied the output to another cmd it works but in the console it opens won't run the file no matter where in the directory I changed too. – deskmonkey Oct 31 '17 at 17:11
  • Is your batch file actually in the root of C? Windows doesn't like putting things there anymore... does it work with a batch file in a subfolder? – Chris Nevill Oct 31 '17 at 18:10
  • It's actually in c:\Windows\system 32\sysprep\test.bat. This is a test file and not the real one. Don't try to understand why but I just got several batch files in various locations at which any point can change. Majority are on a map network drive. But I can copy the location and run the file in new cmd but when the my program opens cmd, it fails. – deskmonkey Oct 31 '17 at 18:26
  • Just tried to dir in cmd that my program opens and it doesn't list any files inside that directory. Is System.Diagnostics don't have access to system folders? Everything running in admin. UAC is off....either way not code problem but permissions. Now what? – deskmonkey Oct 31 '17 at 18:34
  • probably related to WoW (32/64)... system32 is [special](https://stackoverflow.com/a/1855051/1132334) – Cee McSharpface Oct 31 '17 at 19:12

0 Answers0