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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Windows Service cannot access mapped network drive

Windows Service cannot access mapped network drive

Scheduled Pinned Locked Moved C / C++ / MFC
helpsysadmin
6 Posts 3 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.
  • R Offline
    R Offline
    Ranojay
    wrote on last edited by
    #1

    Dear all, I have a console application that writes data to shared network drives. No problem if I launch it from command prompt or Windows explorer. But things go wrong if I call it from a Windows service created with sc command, The appliaction runs in memeory that is for sure, but for some reason it cannot get acess to network drives. ( both the console application and the windows service are wriiten in VC8 ) Please Help Regards

    S K 2 Replies Last reply
    0
    • R Ranojay

      Dear all, I have a console application that writes data to shared network drives. No problem if I launch it from command prompt or Windows explorer. But things go wrong if I call it from a Windows service created with sc command, The appliaction runs in memeory that is for sure, but for some reason it cannot get acess to network drives. ( both the console application and the windows service are wriiten in VC8 ) Please Help Regards

      S Offline
      S Offline
      Sauro Viti
      wrote on last edited by
      #2

      Please, do not cross post. Yu have already got an answer here[^]

      R 1 Reply Last reply
      0
      • S Sauro Viti

        Please, do not cross post. Yu have already got an answer here[^]

        R Offline
        R Offline
        Ranojay
        wrote on last edited by
        #3

        Thanks, But I need to know How to use my CreateProcess function from the service so that it can read or write any loaction on the system.

        1 Reply Last reply
        0
        • R Ranojay

          Dear all, I have a console application that writes data to shared network drives. No problem if I launch it from command prompt or Windows explorer. But things go wrong if I call it from a Windows service created with sc command, The appliaction runs in memeory that is for sure, but for some reason it cannot get acess to network drives. ( both the console application and the windows service are wriiten in VC8 ) Please Help Regards

          K Offline
          K Offline
          Kushagra Tiwari
          wrote on last edited by
          #4

          Hi, The reason why you are able to access the drive in when you normally run the executable from command prompt is that when u are executing it as normal exe you are running that application in the User account from which you have logged on . And that user has the privileges to access the network. But , when you install the executable as a service , by default if you see in the task manage it runs under 'SYSTEM' account . And you might be knowing that the 'SYSTEM' doesn't have rights to access network resources. There can be two solutions to this problem. 1. As Sauro Viti already pointed out in the link he gave you , to map the drive as persistent. 2. There is one more approach that can be followed. If you open the service manager by typing in the 'services.msc'you can go to your service and in the properties of your service there is a logOn tab where you can specify the account as any other account than 'System' you can either start service from your own logged on user account or through 'Network Service'. When you do this .. the service can access any network component and drive even if they are not persistent also. To achieve this programmatically you can look into 'CreateService' function at http://msdn.microsoft.com/en-us/library/ms682450(v=vs.85).aspx and can set the parameter 'lpServiceStartName ' to 'NT AUTHORITY\NetworkService'. This will start your service under 'Network Service' account and then you are done. 3. You can also try by making the service as interactive by specifying SERVICE_INTERACTIVE_PROCESS in the servicetype parameter flag of your CreateService() function but this will be limited only till XP as Vista and 7 donot support this feature. Hope the solutions help you.. Let me know if this worked for you . -Kushagra

          R 1 Reply Last reply
          0
          • K Kushagra Tiwari

            Hi, The reason why you are able to access the drive in when you normally run the executable from command prompt is that when u are executing it as normal exe you are running that application in the User account from which you have logged on . And that user has the privileges to access the network. But , when you install the executable as a service , by default if you see in the task manage it runs under 'SYSTEM' account . And you might be knowing that the 'SYSTEM' doesn't have rights to access network resources. There can be two solutions to this problem. 1. As Sauro Viti already pointed out in the link he gave you , to map the drive as persistent. 2. There is one more approach that can be followed. If you open the service manager by typing in the 'services.msc'you can go to your service and in the properties of your service there is a logOn tab where you can specify the account as any other account than 'System' you can either start service from your own logged on user account or through 'Network Service'. When you do this .. the service can access any network component and drive even if they are not persistent also. To achieve this programmatically you can look into 'CreateService' function at http://msdn.microsoft.com/en-us/library/ms682450(v=vs.85).aspx and can set the parameter 'lpServiceStartName ' to 'NT AUTHORITY\NetworkService'. This will start your service under 'Network Service' account and then you are done. 3. You can also try by making the service as interactive by specifying SERVICE_INTERACTIVE_PROCESS in the servicetype parameter flag of your CreateService() function but this will be limited only till XP as Vista and 7 donot support this feature. Hope the solutions help you.. Let me know if this worked for you . -Kushagra

            R Offline
            R Offline
            Ranojay
            wrote on last edited by
            #5

            Hi Kushagra, Thanks a lot for your help. I will just try with the methods you described. I have also came accros some posts where it is said to use CreateProcessAsUser function to launch the child process. But I could find a proper code to get the "Token Handle" to be used as a parameter to this function. Could you please help me in this area. ? with thanks and regards Ranojay

            K 1 Reply Last reply
            0
            • R Ranojay

              Hi Kushagra, Thanks a lot for your help. I will just try with the methods you described. I have also came accros some posts where it is said to use CreateProcessAsUser function to launch the child process. But I could find a proper code to get the "Token Handle" to be used as a parameter to this function. Could you please help me in this area. ? with thanks and regards Ranojay

              K Offline
              K Offline
              Kushagra Tiwari
              wrote on last edited by
              #6

              Ranojay wrote:

              I have also came accros some posts where it is said to use CreateProcessAsUser function to launch the child process. But I could find a proper code to get the "Token Handle" to be used as a parameter to this function. Could you please help me in this area. ?

              For doing this .. First you will have to make the service as 'INTERACTIVE' as I mentioned in the earlier reply. Then if u are using the function CreateProcessAsUser() you will have to fallow the process as mentioned in this link : http://msdn.microsoft.com/en-us/library/aa379608(VS.85).aspx This should solve your problem. -Kushagra PS: If you like my Answers .. Please rate them ... That will give me a lot of confidence :)

              modified on Wednesday, September 29, 2010 9:23 AM

              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