Solved

Wait till Finished Process

Posted on 2004-10-06
4
272 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now