Solved

Wait till Finished Process

Posted on 2004-10-06
4
276 Views
Last Modified: 2012-05-05
Hi there,

I'm sorry about the points but it's all the points i have left.

This is my problem:

I have this code:

First i have to change the StartType of the Service:

procedure TForm1.Button2Click(Sender: TObject);
begin

//Set the StartType
NTServiceManager1.ServiceAccess := S_ALL_ACCESS;
NTServiceManager1.ServiceName   := 'wuauserv';
NTServiceManager1.ActiveManager := true;
NTServiceManager1.ActiveService := true;
NTServiceManager1.StartType := AUTO_START;
NTServiceManager1.ActiveManager := false;


I Now Start the Service:

//Start the Service
NTServiceManager1.ServiceAccess := S_ALL_ACCESS;
NTServiceManager1.ServiceName   := 'wuauserv';
NTServiceManager1.ActiveManager := true;
NTServiceManager1.ActiveService := true;
NTServiceManager1.Startservice(memo1.Lines);
NTServiceManager1.ActiveManager := false;

My problem is that the program is trying to Start executing the Service while the Startype is still changing and i get an error.

How could i wait for Part 1 to finish and then start part 2?

Thanks

SFern

end;
0
Comment
Question by:sfern
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12237692
> NTServiceManager1.ActiveService := true;

What does this line do exactly ?
0
 
LVL 6

Accepted Solution

by:
vadim_ti earned 100 total points
ID: 12237702
only suggestion:

//stop service

with NTServiceManager1 do begin
   ManagerAccess := [M_CONNECT, M_ENUMERATE_SERVICE];
    ServiceAccess := [S_ALL_ACCESS];
    ActiveManager := true;
    ServiceName   := 'NetLogon';
    ActiveService := true;
    ControlService(CONTROL_STOP);
    ActiveService := false;
    ActiveManager := false;
end;

//Set the StartType
with NTServiceManager1 do begin
   ManagerAccess := [M_CONNECT, M_ENUMERATE_SERVICE];
    ServiceAccess := [S_ALL_ACCESS];
    ActiveManager := true;
    ServiceName   := 'wuauserv';
    ActiveService := true;
    StartType := AUTO_START;
    ActiveService := false;
    ActiveManager := false;
end;
   
   

// Start the Service:
with NTServiceManager1 do begin
   ManagerAccess := [M_CONNECT, M_ENUMERATE_SERVICE];
    ServiceAccess := [S_ALL_ACCESS];
    ActiveManager := true;
    ServiceName   := 'wuauserv';
    ActiveService := true;
    Startservice(memo1.Lines);;
    ActiveService := false;
    ActiveManager := false;
end;

0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12237715
maybe like this:

try
  //Set the StartType
  ...
finally
  //Start the Service
  ...
end;
0
 

Author Comment

by:sfern
ID: 12237860
Just what i needed.

Thanks a Million :o)

SFern.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question