Deleting tmp files from windows service
-
Hello all I coded a window service which creates a lot of tmp files in the course of its operation. I wanted to delete these files once service is stopped. I'm using the following code to do so in destructor function ... SHFILEOPSTRUCT fs ; char buff[255]; char tmp[]="\\*\0\0"; sprintf(buff,"%s%s",sWorkingDir,tmp); int len=strlen(buff); buff[++len]=NULL; buff[++len]=NULL; fs.hwnd = NULL; fs.wFunc = FO_DELETE ; fs.pFrom = ( LPCSTR ) buff ; fs.pTo = NULL; fs.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT; if(SHFileOperation ( &fs ) ==0) WriteLogData('I',5,"DST","Successfully deleted tmp files"); else WriteLogData('E',5,"DST","Unable to delete tmp files"); but the above code is not working within windows service. When I used the same code in a standalone application it is working. When I use GetLastError() in service I'm getting value 6( stands for INVALID_HANDLE). Can any one help me in this Thanks for your help Hari.
-
Hello all I coded a window service which creates a lot of tmp files in the course of its operation. I wanted to delete these files once service is stopped. I'm using the following code to do so in destructor function ... SHFILEOPSTRUCT fs ; char buff[255]; char tmp[]="\\*\0\0"; sprintf(buff,"%s%s",sWorkingDir,tmp); int len=strlen(buff); buff[++len]=NULL; buff[++len]=NULL; fs.hwnd = NULL; fs.wFunc = FO_DELETE ; fs.pFrom = ( LPCSTR ) buff ; fs.pTo = NULL; fs.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT; if(SHFileOperation ( &fs ) ==0) WriteLogData('I',5,"DST","Successfully deleted tmp files"); else WriteLogData('E',5,"DST","Unable to delete tmp files"); but the above code is not working within windows service. When I used the same code in a standalone application it is working. When I use GetLastError() in service I'm getting value 6( stands for INVALID_HANDLE). Can any one help me in this Thanks for your help Hari.
Could it be that SHFileOperation is considered "interactive" and your service is not allowed to interact with the desktop? -- Talk to the hand!
-
Could it be that SHFileOperation is considered "interactive" and your service is not allowed to interact with the desktop? -- Talk to the hand!
Hello Jorgen I already selected "interact with desktop" option from service control window. but it's not working .. Thanks for the help Hari.
-
Hello Jorgen I already selected "interact with desktop" option from service control window. but it's not working .. Thanks for the help Hari.
Have you also tried running the service as different users? I know the LSA (Local System Account) can be tricky. Especially if you're copying files to/from a non-local drive/shares. IIRC, the LSA account can only operate on local/physical devices. -- Talk to the hand!