Can i use user32.dll in Windows Service ?

Jayasuriya, Pathum 26 Reputation points
2022-09-12T11:35:49.42+00:00

I need to automate mouse movement, within certain time period, for that i have wrote a Windows service with using user32.dll to automate mouse movement, it works in debug mode, but when i run it as service it doesnt seems to work. Is there any limitation for user32.dll not to work in windows service ?

Thanks in advance.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,650 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,997 questions
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 45,691 Reputation points
    2022-09-12T12:31:32.56+00:00

    Typically, Windows services run in non-interactive session 0. They are isolated from the session used by a logged on interactive user and do not have direct access to the window station and desktop of that user.

    However, beginning with Windows 10 you can create a Per-user service. Such a service runs in the same session as the interactive user which should provide your service with the ability to interact with the mouse.

    1 person found this answer helpful.
    0 comments No comments

  2. FatedCode 0 Reputation points
    2024-06-15T16:14:31.87+00:00

    I tried, but it didn't work


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.