Running Teamsite User Admin tool IWUSERADM.exe from ASP.NET

Posted by Narendra Tiwari on Geeks with Blogs See other posts from Geeks with Blogs or by Narendra Tiwari
Published on Thu, 27 May 2010 04:33:14 GMT Indexed on 2010/05/27 5:21 UTC
Read the original article Hit count: 386

Filed under:


It has really been a head scratching task for me. I 've tried many options but nothing worked. Finally I found a workaround on google to achive this by TaskScheduler.

PROBLEM
When we run Teamsite user administration command line tool IWUSERADM.exe though ASP.Net it gives following error:

Application popup: cmd.exe - Application Error : The application failed to initialize properly (0xc0000142). Click on OK to terminate the application.

CAUSE
No specific cause, it seems to be a bug, supposed to be resolved with this Microsoft patch http://support.microsoft.com/kb/960266. and there is nothing related to permission issue, y web application is impersonated with an administrator account. off course running a bat file from dmin account is a potential secury threat but for this scenario lets conifned our discussion to run the command line tool.

RESOLUTION
I have not tried this patch as I have not permitted to run this patch on server. Below are the steps to achive the requirement.

1/ Create a batch file which runs the IWUSERADM.exe. 
       echo - Add Teamsite User
   CD E:\Appli\GN00\iw-home\bin
   iwuseradm add-user %1


2/ Temporarily create a schedule task and run  the .bat file by scheduled task by ASP.Net code using TaskScheduler http://www.codeproject.com/KB/cs/tsnewlib.aspx.

3/ Here is the function:
private int AddTeamsiteUser(string strBatchFilePath, string strUser)
{
//Get a ScheduledTasks object for the local computer.
ScheduledTasks st = new ScheduledTasks();
// Create a task
Task t;
try{
t = st.CreateTask("~AddTeamsiteUser");
}
catch
{
throw new Exception("Schedule Task ~AddTeamsiteUser already exist.");
}

 

 t.SetAccountInformation(yourLogin, yourPassword);

//Set the account under which the task should run.

 t.Save();

 t.Run();

Thread.Sleep(2000); //for sync issue

//Remove the scheduled task
st.DeleteTask("~AddTeamsiteUser");

return t.ExitCode;

 

Below are few resources related to the above scenario:-
- Task Scheduler Class Library for .NET
 http://www.codeproject.com/KB/cs/tsnewlib.aspx
- Run a .BAT file from ASP.NET
 http://codebetter.com/blogs/brendan.tompkins/archive/2004/05/13/13484.aspx
- TaskScheduler Class
 http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskscheduler.aspx
- Application Hangs whle running iwuseradm.exe through ASP.Net
 http://bytes.com/topic/asp-net/answers/733098-system-diagnostics-process-hangs
 

 

t.ApplicationName = strBatchFilePath;
t.Parameters = strUser;
t.Comment = "Adding user to Teamsite Application"

© Geeks with Blogs or respective owner