Geeks With Blogs

News
Employers
Soppa Group India
iSmart Panache Inc
R Systems Internationals Ltd
Technovate eSolutions Pvt Ltd
The contents of this blog are my personal opinion and do not represent in any way the view of my employer.
These postings are provided "AS IS" with no warranties, and confer no rights.

Google PR™ - Post your Page Rank with MyGooglePageRank.com

Narendra Tiwari

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, Moreover there is nothing related to permission issue my web application is impersonated with an administrator account. offcourse running a .bat file from admin account is a potential security threat but for this scenario lets conifne our discussion to run the command line tool only.

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.ApplicationName = strBatchFilePath;
t.Parameters = strUser;
t.Comment = "Adding user to Teamsite Application"

t.SetAccountInformation(yourLogin, yourPassword); 
t.Save();
t.Run();


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

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

return t.ExitCode;
}

Calling function
//Add User in Teamsite
string strBatFilePath = ConfigurationManager.AppSettings["batFilePath"];
this.AddTeamsiteUser(strBatFilePath, domainName\UserName)

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

 

Posted on Thursday, May 27, 2010 10:33 AM .Net | Back to top


Comments on this post: Running Teamsite User Admin tool IWUSERADM.exe from ASP.NET

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Narendra Tiwari | Powered by: GeeksWithBlogs.net