Forum posts for splwow64.exe

How to properly install virtual printer using WinAPI on Win x64?

I am trying to install virtual printer from C++ console program using WinAPI calls. It works fine on Windows XP, but on Windows 7 x64 there are some processes which lock files in system folders, required for install. I think they appear only on x64 Windows systems, but I haven't tested it with Windows XP x64.

These are processes splwow64.exe and PrintIsolationHost.exe. I tried to kill them programmaticly and it turns out well (well, for terminating PrintIsolationHost.exe I've set a Debug Privileges, 'coz it's system process) but I have started to think there is probably something wrong with my code if it doesn't work in this way. Apparently there must be some way of installing without terminating any system processes.

The code is something like that:

BOOL res = FALSE;
printf('Run install: ');

// Set debug privilages to current process
HANDLE hTokenThis( NULL );
OpenProcessToken( GetCurrentProcess(), TOKEN_ASSIGN_PRIMARY | TOKEN_ALL_ACCESS | TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hTokenThis );
SetPrivilege( hTokenThis, SE_DEBUG_NAME, TRUE );

printf('Stop spooler service... ');
if(!StopService('spooler'))
return FALSE;

// Stop splwow64.exe and PrintIsolationHost.exe - it can prevent some files to be copied
HANDLE process = GetProcessByName( 'splwow64.exe' );
if (process)
TerminateProcess( process, 0 );

// Stop PrintIsolationHost.exe (it runs under SYSTEM and requires debug rights to be stopped)
process = GetProcessByName( 'PrintIsolationHost.exe' );
if (process)
TerminateProcess( process, 0 );

// Continue install
printf('Copy driver file... ');
if(!CopyInstFile())
{
return FALSE;
}
printf('Start spooler service... ');
if(!StartServices('spooler'))
return FALSE;

printf('Add Port... ');
res = AddPort();
ERROR_CHECK_EXIT(res)

printf('Add Driver... ');
res = AddDriver();
ERROR_CHECK_EXIT(res)

printf('Add print Processor... ');
res = AddProcessor();
ERROR_CHECK_EXIT(res)

printf('Add printer... ');
res = AddPrint();
ERROR_CHECK_EXIT(res)


The functions which install various stuff:

BOOL CPrintInstal::AddDriver()
{
DRIVER_INFO_3 driverInfo;
memset(&driverInfo,0,sizeof(driverInfo ));
driverInfo.cVersion = 3;
driverInfo.pName = PRINTERDRIVERNAME;
driverInfo.pEnvironment = NULL;//'Windows NT x86';
driverInfo.pDriverPath='UNIDRV.DLL';
driverInfo.pDataFile=PDFCONVERTED_GPD;
driverInfo.pConfigFile= 'UNIDRVUI.DLL';
driverInfo.pHelpFile= 'UNIDRV.HLP';
driverInfo.pDependentFiles = NULL;
driverInfo.pDefaultDataType=NULL;

return AddPrinterDriver(NULL,3,(LPBYTE)&driverInfo);
}

BOOL CPrintInstal::AddPrint()
{
PRINTER_INFO_2 printInfo;
memset(&printInfo,0,sizeof(PRINTER_INFO_2));
printInfo.pServerName=NULL;
printInfo.pPrinterName=PRINTERNAME;
printInfo.pShareName=NULL;
printInfo.pPortName=PORTNAME_A;
printInfo.pPrintProcessor =PRINTPROCESSORNAME;
printInfo.pDatatype = 'NT EMF 1.008';
printInfo.pDriverName =PRINTERDRIVERNAME;
printInfo.Attributes = PRINTER_ATTRIBUTE_LOCAL | PRINTER_ATTRIBUTE_QUEUED | PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS;
SetLastError(0);
HANDLE handle = AddPrinter(NULL,2,(LPBYTE)&printInfo);
if(handle == NULL)
{
if(GetLastError()!=1802)
return FALSE;
}
ClosePrinter(handle);
return TRUE;
}


There are more of them and some are really long, so I won't post it here if it's not needed.

Is there any way to prevent system lock files and force printer install?

P.S. I stop spooler service while copying files and then run it before any calls to WinAPI.
P.P.S It's not my code. It's legacy code which we need to maintain for the customer.

View complete forum thread with replies

Other posts related to splwow64.exe

See Related Forum Messages: Follow the Links Below to View Complete Thread

Faulting application splwow64.exe
Debugging/troubleshooting windows applications without source code
How to properly install virtual printer using WinAPI on Win x64?

What is the carbon footprint of your coffee?

Is it low? Is it high? Can this things really kill the planet Earth? Maybe the answer will surprise you. Maybe not.