.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Execute Command and wait until finished (WMI - ManagementClass)

Posted By:      Posted Date: September 03, 2010    Points: 0   Category :.NET Framework
Hi allI am trying to execute a command on a remote maschineand wait until the command is finished.I can start the process but I do not know how to wait for finish.Thanks for any comment !!!Best regardsFrankHere is what I am doing            System.Management.ConnectionOptions local_Connection = new System.Management.ConnectionOptions();            local_Connection.Username = "some_user";            local_Connection.Password = "some_password";            local_Connection.Authority = "ntlmdomainome_domain";            // ManagementScope erstellen            System.Management.ManagementScope local_Scope = new System.Management.ManagementScope("\\\\servername\\root\\CIMV2", local_Connection);            local_Scope.Connect();            // ManagementClass erstellen            System.Management.ManagementClass local_ClassInstance = new System.Management.ManagementClass(local_Scope, new System.Management.ManagementPath("Win32_Process"), null);            // Create a results and completion handler            System.Management.ManagementOperationObserver local_ClassHandler = new System.Management.ManagementOperationObserver();            // Invoke method asynchronously            System.Management.ManagementBaseObject local_InParams = local_ClassInstance.GetMethodParameters("Create");            local_InParams["CommandLin

View Complete Post

More Related Resource Links

can't execute "create table" command with Visual Web Developer express

I have a folder with a web site I'm developing which is connected to a database.Every time I move the folder to a different computer it's a pain when I have to move the database and change the connection string.I've thought to use for the first time a database in the app_data folder and move all the database inside it.Nevertheless, when I try to recreate all the tables in the new database for the first time with the query "create table ..." I get and error saying that "SQL CREATE TABLE" is not supported.Is there a way to manage this situation?--   Giuseppe

How to know when a process run through the command line is finished - C#

Hi , I'm developing a web application in asp.net using  C# and running a .bat file from the command line. The .bat file runs another 3rd party software which resides in the server.Need to know whether the 3rd party software ran successfully to the end.Here is the code I used to run .bat file through the command line.bool RunBat(){            bool success= false;          try{            System.Diagnostics.Process proc = new System.Diagnostics.Process();           proc.StartInfo.WorkingDirectory = @"E:\test";                      proc .StartInfo.FileName = "ABC.bat";                               proc .Start();                     proc .Close();               success= true;          }       

How to run multiple methods asyncronously and wait until all are finished?

I have this method:   public virtual List<User> GetUsersAsync(string[] usernames) { var result = new List<User>(); foreach (var username in usernames) { result.Add(this.GetUser(username)); } return result; }   Currently this method and GetUser run synchronously. How can I change this so that each GetUser runs asynchronously and GetUsers returns when all the GetUser() requests are completed? I know one way would be using delegate beginInvoke and endInvoke like this:   public virtual List<User> GetUsers(string[] usernames) { var result = new List<User>(); var delegates = new Dictionary<GetUserDelegate, IAsyncResult>(); // begin invoke all asynchronously foreach (var username in usernames) { var thisDelegate = new GetUserDelegate(GetUser); var asyncResult = thisDelegate.BeginInvoke(username, null, null); delegates.Add(thisDelegate, asyncResult); } // end invoke all foreach (var thisDelegate in delegates) { result.Add(thisDelegate.Key.EndInvoke(thisDelegate.Value)); } return result; }   this does work but seems to be a bit ugly code; what is the better way to do this? Thanks  

ListView.ItemTemplate with Button. Command doesn't execute when item is selected

I have a listview with an item template that contains a button: <ListView ItemsSource="{Binding AllProducts}"> <ListView.ItemTemplate> <DataTemplate> <Grid> <Button Content="Add Supplier" Command="{Binding AddSupplier}"/> </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView> When the listitem is not selected and the button is clicked, the command executes fine. However, if the listitem is selected, the command does not execute. I have tried putting click and mouse down event handlers on the button, but the events do not fire. Is there any way to make the command execute when the listitem is selected?

SQL Command Or Stored Procedure in Execute SQL Task


Hi all,

Which is a better way to do in Execute SQL Task : Direct SQL input or Create a stored proc in database and then use that.

In my opinion, Stored Procedure is a better and recommended way for following reasons:

  • Cached execution plan
  • More secure
  • Centralized code
  • Code reuse

Please let me know if this is not the case with SSIS Execute SQL Task.


The data source control failed to execute the insert command


Hi All,

I have create table in SQL 2005 and retrive its data in to sharepoint  with the help of Database connection option through Sharepoint Designer. When configuring the connection i have selected a custom quer with stored procedure option and from the dropdown option selected the insert stored procedure everything is ok.

Stored Procedure
CREATE PROCEDURE ChangeTable_insert

 @PROJECT varchar(50) ,

INSERT INTO [dbo].[ChangeTable]





i have created new aspx page in Sharepoint Designer from the datasource details-->Insert selected fields as-->selected new item form and saved this page.
When i opened this page in to browser and try to save data it gives an below error
Go back to site 
Error: "The data source control failed to execute the insert command.
 Troubleshoot issues with Windows SharePoint Services."

please help me. i have to save data to sql database through sharepoint

thanks in advance

Execute DOS Command with Variable



I am using 2 task in control flow.

1st task is a "execute SQL task" which returning from DB into a variable called VAR1(i.e. VAR1 = C:\test_data\)

2nd task is "execute process task" where I wnat to delete all the files from the directory (i.e. value got in VAR1)

Pls help.

Many Thanks,





Using MVVM and commands inside of a datatemplate, the command wont execute.

Inside of my main view i have a datatemplate showing off all the items in an observable collection. now inside of that i want to set commanding on a radio button.

outside the datatemplate this works
<Button Height="23" Name="btnUpdate" Command="{Binding UpdateCommand}"

The data source control failed to execute the insert command


In SharePoint Designer 2007 I'm trying to customize the edit form that you get when you create a list item in a SharePoint 2007 list (EditForm.aspx). I took the following steps:

1.       Open the site in SharePoint Designer 2007.

2.       Browse to the list and open the 'NewForm.aspx' web form.


Cannot execute a program. The command being executed was "c:\WINDOWS\Microsoft.NET\Framework\v3.5\cs


The webserive is throwing the following exception every time unless I reset iis. I don't think it is machine dependent as it is happening on other machines. There is some fix for asian version and I don't think I have asian version (conime). but I tried it anyway but doesn't work. The error clears by restarting IIS on development but that is not a solution for webserver. Does anybody know how to resolve this issue? It's not memory issue as I have plenty of free memory.

ExternalException (0x10b): Cannot execute a program. The command being executed was "c:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe" /noconfig /fullpaths @"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\fi_firtkservice\5e540d70\ff1820cc\nitishj0.cmdline".]
   System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonated(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) +2204
   System.CodeDom.Compiler.Executor.ExecWaitWithCapture(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) +122
   Microsoft.CSharp.CSharpCodeGenerator.Compile(CompilerParameters options, String compilerDi

"The data source control failed to execute the insert command." when inserting to sql table with tri



I have a data view web part that inserts a new record into a sql table. This works fine.

I have now needed to add a trigger to the sql table that sends an email when a new record is inserted (the code for which works fine) but now my insert fails with 'The data source control failed to execute the insert command.'.

If I disable the trigger the form works fine again.

Any ideas what could be causing this?


how to execute a command on gridview row click???


i have two gridviews in my page..gridviewCart to display the items in the cart and gridviewStore to display the list of stores a particular item is available in.


now what i want is....when the user clicks on a row in gridviewCart...i want to dynamically show the list of stores in gridviewStore.


Eg. in gridviewCart row number one has the item Samsung Galaxy...so when a user clicks on row number one i want to show the list of shops whis has Samsung galaxy in gridviewStore.


is there any way to do this??


HttpContext.Items and Server.Transfer/Execute

The problem was basically that when a Server.Transfer call was applied the script container (and also various ClientScriptProxy script embedding routines) would potentially fail to load up the specified scripts.

want to execute url without showing that page or url to client.


hello friends,

I need ur help,what i want to do is to execute a url ("To send a text message to client") on client registration but without showing that url page, in short executing url without displaying any page or url to the client.

please help and thanks in advance.

Row command working on all rows not selected one?



I have this code that hides a column in a gridview.  (The column houses another nested gridview).

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "Select" Then
            If GridView1.Columns(0).Visible = False Then
                GridView1.Columns(0).Visible = True
                GridView1.Columns(0).Visible = False
            End If
        End If
    End Sub

The trouble is that if I click the select link on one row that action to hide is carried out on all rows.  How can I set this up so that it only hides the row that is selected?


Print command



Is there a way of setting up a print area for a part of my webpage, I only want to print a certain part of the page, when I select print at the moment it will print the whole page and the layout is rubbish!!

command object error


Could someone please tell me what is wrong with my syntax here?  I'd be much appreciative.


objCmd = New SQLCommand("SELECT CASE WHEN objDR('Item') = 'Enter Bill of Lading' then enterbol " _  

& "WHEN objDR('Item') = 'Bill of Lading History' THEN bolhistory " _  

& "WHEN objDR('Item') = 'Request Transfer' or objDR('Item') = 'View Transfer in Progress' THEN transfers " _  

& "END  from plantGroups where plantgroupid=@plantgroupid", objConn)

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend