SiComponents Home Page SiComponents Forums
Here you will be able to get help and share your experience
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Overlapped I/O operation is in progress

 
Post new topic   Reply to topic    SiComponents Forums Forum Index -> VCL Scheduling Agent
View previous topic :: View next topic  
Author Message
richardd



Joined: 14 Oct 2008
Posts: 11

PostPosted: Fri Oct 24, 2008 9:05 pm    Post subject: Overlapped I/O operation is in progress Reply with quote

Trying to change a few Scheduled task passwords on a remote machine and always get error "Overlapped I/O operation is in progress".

It happens when running either from a Windows 2000 to XP (remote).
Same problem when running from Vista to XP (remote).

Any ideas/suggestion at this point would be greatly appreciated?

Thanks in advance.

~Richard
Back to top
View user's profile Send private message
richardd



Joined: 14 Oct 2008
Posts: 11

PostPosted: Tue Oct 28, 2008 6:38 pm    Post subject: Reply with quote

Some of you have had better luck than I have so far. Any thoughts on why I get this error ('Overlapped I/O operation is in progress')?

This error seems to always happen when calling the following line:

if AnsiSameText( TaskScheduler.Items[Index].AccountName,
AComputerName + '\' + AUserName ) then


My Code snippet:

for Index := 0 to TaskScheduler.Items.Count -1 do begin

{Apparently the following call lets us access task properties: Use this method before accessing any properties and methods of the task, except newly created task with CreateNewItem method. If the task has not activated accessing its members rises an exception.}
TaskScheduler.Items[ Index ].Activate;

if AnsiSameText( TaskScheduler.Items[Index].AccountName,
AComputerName + '\' + AUserName ) then
begin
//Change password
TaskScheduler.Items[Index].SetAccountInformation(AnAccountName, APassword );

TaskScheduler.Items[ Index ].Save;
end
end;
Back to top
View user's profile Send private message
richardd



Joined: 14 Oct 2008
Posts: 11

PostPosted: Tue Oct 28, 2008 6:44 pm    Post subject: Reply with quote

Further more, the exception is originating from this routine found in saTask

function TTaskItem.GetAccountName: WideString;
var
ppwszAccountName: PWideChar;
begin
// 2.0.0.4
if not (FTaskManager.RunningVistaOrLater) then
begin
if not Assigned(FInterface) then <-In my case, this is never assigned)
Error(sTaskNotActivated, [Name]); <- Causing this
OleCheck((FInterface as ITask).GetAccountInformation(ppwszAccountName));
Result := ppwszAccountName;
CoTaskMemFree(ppwszAccountName);
end
else
begin
//
if not Assigned(FTaskDefinition) then
Error(sTaskNotActivated, [Name]);
Result := FTaskDefinition.Principal.UserId;
end;
end;

Please help!
Back to top
View user's profile Send private message
richardd



Joined: 14 Oct 2008
Posts: 11

PostPosted: Tue Oct 28, 2008 10:40 pm    Post subject: Reply with quote

After more investigation, I found the following:

CODE SNIPPET:
TaskScheduler := TTaskScheduler.Create( nil );
try
//Specifies whether Task Scheduler should invoke Refresh method before ActivateTask method is called.
TaskScheduler.AutoRefresh := False;

//Specifies the behavior of the Task Scheduler when the user tryes to create a new TTaskItem
//with a name that already exists.
TaskScheduler.Duplicate := tdError;

//Specifies if the Task Scheduler service is running and active.
TaskScheduler.Active := True;

//Specifies the computer that the TaskScheduler operates on.
TaskScheduler.TargetComputer := '\\' + AComputerName;

//StartScheduler: Checks if Task Scheduler Service is working and if not starts this service. This function "silently" checks if the service is working.
//Open: Calls StartScheduler and initializes Scheduler interface. Raizes exception if any error is encountered.

//TaskScheduler.Open; <-- DO NOT USE THIS (IT WILL CLEAR THE TARGET COMPUTER PREVIOUSLY SET AND USE THE LOCAL COMPUTER INSTEAD)

TaskScheduler.Refresh;

// Then I loop through the Task and reset the passwords
for Index := 0 to TaskScheduler.Count - 1 do
begin
TaskItem := TaskScheduler.Items[ Index ];
if TaskItem <> nil then
begin
TaskItem.Activate;

if AnsiSameText( TaskItem.AccountName, AComputerName + '\' + AUserName ) then
begin
//Reset password here
TaskScheduler.Items[ Index ].SetAccountInformation(
{AComputerName} AUserName, APassword );
end;
end;
end;


The issue is occurring when reading the AccountName (TaskItem.AccountName) that calls GetAccountName

function TTaskItem.GetAccountName: WideString;
var
ppwszAccountName: PWideChar;
begin
// 2.0.0.4
if not (FTaskManager.RunningVistaOrLater) then
begin
if not Assigned(FInterface) then
Error(sTaskNotActivated, [Name]);
OleCheck((FInterface as ITask).GetAccountInformation(ppwszAccountName));
Result := ppwszAccountName;
CoTaskMemFree(ppwszAccountName);
end
else
begin
//
if not Assigned(FTaskDefinition) then
Error(sTaskNotActivated, [Name]);
Result := FTaskDefinition.Principal.UserId;
end;
end;

Which calls GetAccountInformation. That method raises an exception.

This only happens when I am trying to change the password on the Account I am currently logged on. We decided to not change the password on the current account but the only way to check if the current account is used on that task is to compare the AccountName property ... which raises the error (you see my dilemma here).

PLEASE HELP!
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2097

PostPosted: Wed Oct 29, 2008 10:00 am    Post subject: Reply with quote

Hello Richard,

Do you use IIS or anything mentioned in the MS KB article: http://support.microsoft.com/default.aspx?scid=kb;en-us;297989
?
May be it will help you, because it looks very similar.
Back to top
View user's profile Send private message
richardd



Joined: 14 Oct 2008
Posts: 11

PostPosted: Wed Oct 29, 2008 4:08 pm    Post subject: Reply with quote

No I do not use IIS.

Why can't I simply get the Account Name (TaskItem.AccountName)?
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2097

PostPosted: Thu Oct 30, 2008 5:52 am    Post subject: Reply with quote

Hello Richard,

As you may noticed the exception (error) raised by GetAccountInformation() method which is native Windows API call. So the reason of this could be in some system misconfiguration.
Could you please try the following:
change the code to the following:

Code:
function TTaskItem.GetAccountName: WideString;
var
  ppwszAccountName: PWideChar;
  Res: HRESULT; // !!!
begin
// 2.0.0.4
  if not (FTaskManager.RunningVistaOrLater) then
  begin
    if not Assigned(FInterface) then
      Error(sTaskNotActivated, [Name]);
    Res := (FInterface as ITask).GetAccountInformation(ppwszAccountName); // !!!
    OleCheck(Res); // !!!
    Result := ppwszAccountName;
.....

And then while debugging check the value of Res before OleCheck(). In order to get the real code returned. Because may be OleCheck() raises wrong error here. And compare it with one of the following:

Code:

  { One or more arguments are invalid }
  E_INVALIDARG = HRESULT($80070057);
  { Ran out of memory }
  E_OUTOFMEMORY = HRESULT($8007000E);

  SCHED_E_NO_SECURITY_SERVICES = HResult($80041312);

If none of the above returned please let me know the exact value of Res.
Back to top
View user's profile Send private message
richardd



Joined: 14 Oct 2008
Posts: 11

PostPosted: Thu Oct 30, 2008 3:31 pm    Post subject: Reply with quote

Result is NOERROR ( 0 )... but strangely, it now works OK!

I am a bit confused because that code is essentially the same as before just broken up in 2 separate instructions.

This:
Res := (FInterface as ITask).GetAccountInformation(ppwszAccountName);
OleCheck(Res);

Is the same as:
OleCheck((FInterface as ITask).GetAccountInformation(ppwszAccountName));

If it's all the same to you, could you modify saTask to use the 2 separate instructions instead of 1 so I don't have to modify your unit. I am still curious and would still like to know why one way works and the other doesn't.

By the way, thanks for the reply/help. I appreciate it.
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2097

PostPosted: Thu Oct 30, 2008 4:46 pm    Post subject: Reply with quote

Very strange!
Do you have Optimization turned ON in Compiler settings? May be it caused that?
Back to top
View user's profile Send private message
richardd



Joined: 14 Oct 2008
Posts: 11

PostPosted: Thu Oct 30, 2008 6:12 pm    Post subject: Reply with quote

Yes I do have Optimization turned ON.

Given the following scenario (we have 3 account to modify):

ACCOUNT_A
ACCOUNT_B
ACCOUNT_C

It seems to be happening when the following conditions are meant:

1. I am currently logged on (Windows) as ACCOUNT_C
2. I am changing the account passwords (windows users) for ACCOUNT_A, B and C
3. Then I am changing the Task Passwords for ACCOUNT_A, B and C
4. The remote station is NOT on a domain (workgroup)
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2097

PostPosted: Fri Oct 31, 2008 5:57 am    Post subject: Reply with quote

But does turning Optimization OFF eliminates the problem even when the code is in single line?
Just curious.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SiComponents Forums Forum Index -> VCL Scheduling Agent All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by p h p B B  © 2001, 2005 p h p B B  Group