Home > other >  The great spirit is good at c #
The great spirit is good at c #

Time:10-10

Younger brother beginners c #, project ran into a problem, now do is needed in the cancellation of the user (not to turn it off! Start a Windows service, write your own original ideas in the program to capture the cancellation message, and then start the service, but the cancellation message is captured successfully, but use sc. Exe start the service failed

CodePudding user response:

Windows a great god to tell you
Gpedit.msc open the group policy, "user profile" - & gt; "Windows Settings" - & gt; "Script (login/logout)", select "logout" on the right

CodePudding user response:

reference 1st floor Runnerchin response:
Windows great god to tell you
Gpedit.msc open the group policy, "user profile" - & gt; "Windows Settings" - & gt; "Script (login/logout)", select "logout" on the right

Sorry you said I don't understand, I want to in the code to implement the service function,

CodePudding user response:

What results returned sc start the service? Without permission? Or parameter errors? Net start command can also start the service,
In addition, the system services have two name, one is the servicename, one is the displayname, with sc or net start command started, you need to specify the service name,
Further said, now you don't have to die to dig this scenario itself the service, you can use the process, start to perform the services corresponding executable, and sc is one thing,
Or in a train of thought, can directly in the I said above Settings to set "when the user logged off to run a specified program", this setting is Windows's own function

CodePudding user response:

The
reference 3 floor Runnerchin response:
sc start service returns the results? Without permission? Or parameter errors? Net start command can also start the service,
In addition, the system services have two name, one is the servicename, one is the displayname, with sc or net start command started, you need to specify the service name,
Further said, now you don't have to die to dig this scenario itself the service, you can use the process, start to perform the services corresponding executable, and sc is one thing,
Or in a train of thought, can directly in the I said above Settings to set "when the user logged off to run a specified program", this setting is Windows's own

Prompt because window station closed, the application failed to initialize, used the net start is also the same problem, and sometimes prompt application initialization failed, 0000142 normal because they project framework is ready, can choose only start the service in a particular program, so I am also very tangled, can also use the process after users log off. Start

CodePudding user response:

User logout, associated with the current session of the program will be shut down, you run into problems should be trying to run in the process of the cancellation of the task, so recommend you run the script is set in the cancellation of the Windows, so that it can execute it before the cancellation, performed to logout, service is essentially an executable program, at this time, you don't use A.e xe run B.e xe, directly in the Windows logout script Settings, add B.e xe can,

CodePudding user response:

Can be operated by c # Windows, please logout script, searched the along while didn't search, thanks to the great god, and worship of

reference 5 floor Runnerchin reply:
user logout, associated with the current session of the program will be shut down, you run into problems should be trying to run in the process of the cancellation of the task, so recommend you run the script is set in the cancellation of the Windows, so that it can execute it before the cancellation, performed to logout, service is essentially an executable program, at this time, you don't use A.e xe run B.e xe, directly in the Windows logout script Settings, add B.e xe,

CodePudding user response:

Thanks for the great spirit, has been solved, I use this one line of code:
If (control. The Status==System. ServiceProcess. ServiceControllerStatus. Stopped)
{
Control. The Start ();
}
  • Related