Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Deleting tmp files from windows service

Deleting tmp files from windows service

Scheduled Pinned Locked Moved C / C++ / MFC
helplearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    haritadala
    wrote on last edited by
    #1

    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.

    J 1 Reply Last reply
    0
    • H haritadala

      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.

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      Could it be that SHFileOperation is considered "interactive" and your service is not allowed to interact with the desktop? -- Talk to the hand!

      H 1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        Could it be that SHFileOperation is considered "interactive" and your service is not allowed to interact with the desktop? -- Talk to the hand!

        H Offline
        H Offline
        haritadala
        wrote on last edited by
        #3

        Hello Jorgen I already selected "interact with desktop" option from service control window. but it's not working .. Thanks for the help Hari.

        J 1 Reply Last reply
        0
        • H haritadala

          Hello Jorgen I already selected "interact with desktop" option from service control window. but it's not working .. Thanks for the help Hari.

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups