CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

Start a remote process topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 08-31-2010, 05:56 AM
 
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sjgasca is on a distinguished road
| More
Start a remote process

Hi,

I have written a small application that analises several logs locally (sizes may be up to 300 MB). I'm now building an application that is able to execute and control that process on every machine.

For that, I've read to use WMI to start a process on a remote machine (same LAN), but found several problems:

The application must reside on the remote machine, which is not valid for me (I can launch the exe i.e psexec -c app.exe or somehow "send" the code to the machine)
Second, the code below works but I can't see anything on the screen, I see the process though.

Code:
    class Program
    {
        static void Main(string[] args)
        {
            string hostname = "k2";

            try
            {

            ConnectionOptions theConnection = new ConnectionOptions();
            theConnection.Impersonation = ImpersonationLevel.Impersonate;
            theConnection.Username = "salva";
            theConnection.Password = "salva";

            //ManagementScope theScope = new ManagementScope("\\\\" + IP + "\\root\\cimv2", theConnection);
            ManagementScope theScope = new ManagementScope(@"\\" + hostname + @"\root\cimv2", theConnection);

            ManagementClass theClass = new ManagementClass(theScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());

                ManagementBaseObject inParams = theClass.GetMethodParameters("Create");
                //inParams["CommandLine"] = @"\\" + IP + "\\admin$\\ipconfig";
                inParams["CommandLine"] = "notepad";
                ManagementBaseObject outParams = theClass.InvokeMethod("Create", inParams, null);
                
                Console.WriteLine("Creation of the process returned: " + outParams["returnValue"]);
                Console.WriteLine("Process ID: " + outParams["processId"]); 

            }
            catch (ManagementException ex) {
                Console.WriteLine(ex.Message);
             }
            Console.ReadLine();
        }
Any idea?

Cheers.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Remote database adobe71 C# Programming 0 08-28-2010 03:11 AM
remote application johndoe444 C# Programming 0 08-28-2010 03:11 AM
remote command exexcution ramukumar Shell Scripting 0 08-28-2010 03:11 AM
how to integrate process with exe file vidhya Win32 Programming 3 05-22-2007 07:42 AM
How to uniquely identify a process? codeunlock C# Programming 0 04-29-2007 12:49 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 02:23 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board