1

My application installs a virtual printer driver.

On some users' systems I need to restart the printer spooler because functions like OpenPrinter return RPC_S_SERVER_UNAVAILABLE (text is "The RPC server is unavailable."), which means the spooler has stopped working.

I try to do that by calling "net start spooler" with CreateProcess:

PROCESS_INFORMATION pi = { 0 };
STARTUPINFO si = { sizeof(si) };
// later
CreateProcess(0, "net start spooler", 0, 0, 0, 0, 0, 0, &si, &pi );

On some users' systems this works, but on others it fails with exit code 2, and GetLastError returns ERROR_NO_MORE_FILES (text is "There are no more files.").

Does anyone know what ERROR_NO_MORE_FILES would mean in this case?

sashoalm
  • 75,001
  • 122
  • 434
  • 781

1 Answers1

2

It seem that you interpret the ERRORLEVEL code 2 in the wrong way. It is not the code ERROR_NO_MORE_FILES. I started cmd.exe under the user account and received the following output

C:>echo %errorlevel% 0

C:\Users\Rita>net stop spooler System error 5 has occurred.

Access is denied.

C:>echo %errorlevel% 2

Any exit code of "net.exe" larger as 0 is an error.

I recommend you to use StartService to start the service, then you will have more error control.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks, I updated the title of my question. So 'net start spooler' fails with Access Denied. I don't understand how this could happen, since my installer reiqires administrative priviledges to run. – sashoalm Mar 02 '11 at 14:33
  • @satuon: You should describe more detailed from what program the 'net start spooler' will be started. Windows Installer for example has special actions to stop/start the service. Who started the setup? Hat the setup UAC Manifest with `` and so on? – Oleg Mar 02 '11 at 14:41
  • I use Inno Setup for the installer of the main program. The printer driver installer is a standalone exe which I call from the [Run] section of Inno Setup. But the installer for my app requires administrative priviledges, i.e. an UAC screen always appears when you try to start the installer. And the standalone exe inherits the parent process's priviledges, so it has administrative access as well. – sashoalm Mar 02 '11 at 14:58
  • @satuon: "Access is denied" is only one possibility for your error. Can you reproduce the problem in your environment? **You need more information about the reason of the error**. You can try redirect stderr and stdout (see [here](http://msdn.microsoft.com/en-us/library/ms682499(v=vs.85).aspx)) for example. You can use WMI from VBS to start the service it gives [documented return code](http://msdn.microsoft.com/en-us/library/aa393673(VS.85).aspx) back. You can also use StartService API which I mention before. – Oleg Mar 02 '11 at 15:10