Results 1 to 14 of 14

Thread: [RESOLVED] Starting program on remote pc

  1. #1

    Thread Starter
    New Member ulv81's Avatar
    Join Date
    Sep 2009
    Location
    Norway
    Posts
    14

    Resolved [RESOLVED] Starting program on remote pc

    Hello.

    Please help me with this code.
    I don't understand how I can get this to work!!!

    Code:
            Dim co As ConnectionOptions = New ConnectionOptions()
            co.Username = "username"
            co.Password = "password"
            Dim mp As ManagementPath = New ManagementPath("\\targetMachine\root\cimv2:Win32_process")
            Dim mc As ManagementClass = New ManagementClass(mp, co)
            mc.InvokeMethod("Create", New Object() {"calc.exe"})

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Starting program on remote pc

    What don't you understand? It seems like a pretty simple example to me.

  3. #3

    Thread Starter
    New Member ulv81's Avatar
    Join Date
    Sep 2009
    Location
    Norway
    Posts
    14

    Re: Starting program on remote pc

    Well... It doesn't work!!!

    ManagementClass overload don't support ConnectionOptions...

    So... How am I supposed to do this???

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Starting program on remote pc

    The error message is telling you the problem. No constructor for the ManagementClass takes a connectionOptions object. Where did you get this code from?

  5. #5

    Thread Starter
    New Member ulv81's Avatar
    Join Date
    Sep 2009
    Location
    Norway
    Posts
    14

    Re: Starting program on remote pc

    A friend of my wrote a similar code in C#, and I tried to convert it to VB.
    This is what I got from it...

    But if you see what i'm trying to do with the code here, could you maybe point me in the right direction?!

  6. #6
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Starting program on remote pc

    Do you have the C# code that works?

  7. #7

    Thread Starter
    New Member ulv81's Avatar
    Join Date
    Sep 2009
    Location
    Norway
    Posts
    14

    Re: Starting program on remote pc

    I'm not sure if it even works, but this is what my friend gave me:

    Code:
    ConnectionOptions co = new ConnectionOptions("username and password here");
    ManagementPath mp = new ManagementPath(@"\\targetMachine\root\cimv2:Win32_process");
    ManagementClass mc = new ManagementClass(mp, co);
    I tried to search google and msdn but I can't find anything about this...

    This is what I want:
    I have a server called myserver and a computer called mypc (example!).
    On myserver (local), I have created a batch file in system root that deletes some log files.
    Normaly I would log on to myserver (RDP) to execute this batchfile...
    I'm trying to create a program I can run locally on mypc which executes the batchfile locally on myserver...
    I Hope you understand what I'm trying to do here... My English isn't very good.

  8. #8
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Starting program on remote pc

    I think you want something more like this (Code which I generated from the WMICodeCreator):

    Code:
                    Dim connection As New ConnectionOptions
                    connection.Username = userNameBox.Text
                    connection.Password = passwordBox.Text
                    connection.Authority = "ntlmdomain:DOMAIN"
    
                    Dim scope As New ManagementScope( _
                        "\\FullComputerName\root\CIMV2", connection)
                    scope.Connect()
    
                    Dim classInstance As New ManagementClass( _
                        scope, _
                        New ManagementPath("Win32_Process"), Nothing)

  9. #9

    Thread Starter
    New Member ulv81's Avatar
    Join Date
    Sep 2009
    Location
    Norway
    Posts
    14

    Re: Starting program on remote pc

    Yes, I think we're on to something here!
    I just don't understand where to put the path to my batchfile...

  10. #10
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Starting program on remote pc

    Does the Calc.exe work?

  11. #11

    Thread Starter
    New Member ulv81's Avatar
    Join Date
    Sep 2009
    Location
    Norway
    Posts
    14

    Re: Starting program on remote pc

    No.... I think it's because I type the code wrong or something!

    Code:
    ("Win32_Process.create("calc.exe")")
    Could you maybe give me an example whit calc.exe ot notepad.exe?!

  12. #12

    Thread Starter
    New Member ulv81's Avatar
    Join Date
    Sep 2009
    Location
    Norway
    Posts
    14

    Re: Starting program on remote pc

    Anyone?!

  13. #13
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Starting program on remote pc

    Download the WMI Code creator that I linked in post 8. You should be able to use that to get the code that works.

  14. #14

    Thread Starter
    New Member ulv81's Avatar
    Join Date
    Sep 2009
    Location
    Norway
    Posts
    14

    Re: Starting program on remote pc

    I found this link, and it works

    http://weblogs.asp.net/steveschofiel...als_2E00_.aspx

    The code is also very similar to the one provided by the WMI Code Creator.

    Thanks for all the help, and I really hope this thread will help other people with the same problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width