Search code examples
delphiwindows-services

How to mount network disks within Delphi Service?


I am newbie in Delphi, but I need to fix Delphi code in order to make network disks to be mounted when "Service start" is executed. By default when my application is started by Windows Service network disks are not accessible for application, so the solution is to insert UNC mapping script in my service. Can you help me with this issue?


Solution

  • It looks like this is not a Delphi problem, supposing is the ShellExecute what doesn't work well (not clear to me).

    In this case, it could be a [network] file permissions issue, and I suggest you to choose between two different solutions:

    • To set the logon for the service to an account with proper (and tested) network read/write/execute rights for the required files. Remember the services run with the 'system' account by default, which is OK for accesing local resources, but not as good for network ones.
    • To change your ShellExecute approach for one who permits the start of the 'alestart.exe' in the context of a different user (the service runs as system, stores in it's configuration the credentials of the user to start the 'alestart.exe' process. To start a process in the context of a different user you can use the CreateProcessWithLogonW API call. In order of this to work your process must have enabled the SeImpersonatePrivilege.

    regards.