Overlapped I/O operation is in progress

This forum is designated to discuss SiComponents Scheduling Agent.
Post Reply
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Overlapped I/O operation is in progress

Post by richardd »

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
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Post by richardd »

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;
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Post by richardd »

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!
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Post by richardd »

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!
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Hello Richard,

Do you use IIS or anything mentioned in the MS KB article: http://support.microsoft.com/default.as ... -us;297989
?
May be it will help you, because it looks very similar.
Best regards,
Igor Siticov.
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Post by richardd »

No I do not use IIS.

Why can't I simply get the Account Name (TaskItem.AccountName)?
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

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: Select all

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: Select all

  { 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.
Best regards,
Igor Siticov.
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Post by richardd »

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.
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Very strange!
Do you have Optimization turned ON in Compiler settings? May be it caused that?
Best regards,
Igor Siticov.
richardd
Posts: 11
Joined: Tue Oct 14, 2008 8:29 pm

Post by richardd »

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)
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

But does turning Optimization OFF eliminates the problem even when the code is in single line?
Just curious.
Best regards,
Igor Siticov.
Post Reply