DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005

    Exclamation Creating NT Services with Logon User Option

    Hi friends,
    I have one problem regarding Service.I have created service using Service API(i.e createService Winsvc.h).When I create and install service as LocalSystem account(i.e when its user is system,i.e last 2 parameters in CreateService are NULL) every thing works fine.But my problem requires service to have access to domain resources.So I have to specify the user name and password in last 2 parameters of CreateService function.But doing this doesn't work when I try to start servce after installing it.Starting it gives "logon failure" message.But when I change username and password manually in service property applet then every thing works fine and even for next time after reinstalling it works fine that mean I have to give the parameter in service property manually.Can any one guide me where I am making mistake???
    Thanks in Advance

    Waiting for positive reply.


  2. #2
    Join Date
    Jan 2005
    Hi J,

    this is copied from the msvc++ help for CreateService. As you see the lpServiceStartname is of the form Domain\Account. If you enter the string like this
    "mydomain\someaccount" you might get a warning that you have an "unrecognized escape sequence" namely "\s" in my case. Make sure you mask out the backslash!
    -> "mydomain\\someaccount". If the account you are using is for example "norbert", you wouldn't even get the warning, because "\n" IS a recognised escape sequence.
    The local system account would be defined in the right way, so if you use NULL for this parameter, you would be authorized as you expect.

    [in] Pointer to a null-terminated string that specifies the name of the account under which the service should run. If the service type is SERVICE_WIN32_OWN_PROCESS, use an account name in the form DomainName\UserName. The service process will be logged on as this user. If the account belongs to the built-in domain, you can specify .\UserName.
    If this parameter is NULL, CreateService uses the LocalSystem account. If the service type specifies SERVICE_INTERACTIVE_PROCESS, the service must run in the LocalSystem account.

    If this parameter is NT AUTHORITY\LocalService, CreateService uses the LocalService account. If the parameter is NT AUTHORITY\NetworkService, CreateService uses the NetworkService account.

    Windows NT: If the service type is SERVICE_WIN32_SHARE_PROCESS, you must specify the LocalSystem account. On later versions of Windows, a shared process can run as any user.

    If the service type is SERVICE_KERNEL_DRIVER or SERVICE_FILE_SYSTEM_DRIVER, the name is the driver object name that the system uses to load the device driver. Specify NULL if the driver is to use a default object name created by the I/O system.

    [in] Pointer to a null-terminated string that contains the password to the account name specified by the lpServiceStartName parameter. Specify an empty string if the account has no password or if the service runs in the LocalService, NetworkService, or LocalSystem account. For more information, see Service Record List.
    Passwords are ignored for driver services.



  3. #3
    Join Date
    Apr 2005
    Thanks for reply

    But You didn't get my point.
    I had created service successfully and it works fine but if i want to logon with other user i am passing the last two parameter and then also it works but if the passed user name and password is used for first time on the system then manuallly i had to give password from myservice - >properties in log as tab and then it works fine . means it is not taking the password parameter from createservice function. plz any body had any idea then help me plz...........

    my function is
    "Test Service", // service name to display
    SERVICE_ALL_ACCESS, // desired access
    //| SERVICE_INTERACTIVE_PROCESS, // service type
    SERVICE_AUTO_START, // start type
    SERVICE_ERROR_NORMAL, // error control type
    lpszBinaryPathName, // service's binary
    NULL, // no load ordering group
    NULL, // no tag identifier
    NULL, // no dependencies
    "aaa"); // password

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.