1
votes
string path = "D:";
string wbadminPath = Environment.SystemDirectory + @"\wbadmin";
string wbadminEvent = "start systemstatebackup -backupTarget:" + path + " -quiet";

        try
        {
            int exitCode = 0;
            ProcessStartInfo start = new ProcessStartInfo(wbadminPath, wbadminEvent);
            using (Process proc = Process.Start(start))
            {
                proc.WaitForExit();
                exitCode = proc.ExitCode;                    
            }
        }

If I execute this code in Console Application, - It works. If I execute this code in Windows Service I have this error:

Command Line Interface for Microsoft BLB Backup has stopped working

Problem signature: Problem Event Name: APPCRASH Application Name: wbadmin.exe Application Version: 6.0.6001.18000 Application Timestamp: 47918aed Fault Module Name: kernel32.dll Fault Module Version: 6.0.6002.18327 Fault Module Timestamp: 4cb73436 Exception Code: c0000142 Exception Offset: 00009f7d OS Version: 6.0.6002.2.2.0.274.10 Locale ID: 1033 Additional Information 1: 9d13 Additional Information 2: 1abee00edb3fc1158f9ad6f44f0f6be8 Additional Information 3: 9d13 Additional Information 4: 1abee00edb3fc1158f9ad6f44f0f6be8

1

1 Answers

2
votes

Okay, so I know I'm to late to be of help, but hopefully someone else will benefit from this.

Windows Services cannot interact with anything with a GUI or that requires user interaction. Basically when you call Process.Start(start) it tries to open the CMD window which a service can't do. You can use something like:

            start.UseShellExecute = false;
            // Do not create the black window.
            start.CreateNoWindow = true;//This stops the GUI

HOWEVER it is worth noting I tried for hours to get this particular command to work and could not. I ended up scrapping the entire idea after hours of work and research. In general you can run CMD commands from a service using the .CreateNoWindow, however it does not seem to work in this case (it fails to find the WBADMIN process). If I find anythign new on this in the future I will update.

Here's a thread talking about why services can't access GUIs anymore