[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"})
Re: Starting program on remote pc
What don't you understand? It seems like a pretty simple example to me.
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???
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?
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?!
Re: Starting program on remote pc
Do you have the C# code that works?
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.
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)
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...
Re: Starting program on remote pc
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?!
Re: Starting program on remote pc
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.
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.