-
1 Attachment(s)
Classic VB/WMI - How Do I Run a Process On a Remote System?
Using VB and WMI you can run a process on any remote system on your network. The only requirements are that you have WMI on your system and you have Administrative prividgles on the remote system too.
When you run this you will get a return value of 0 for success and a process id which you can verify by logging into the remote system and looking in the task manager process' list. ;)
VB Code:
Option Explicit
'Copyright © 2005 by RobDog888 (VB/Office Guru™). All Rights reserved.
'
'Distribution: You can freely use this code in your own
' applications provided that this copyright
' is left unchanged, but you may not reproduce
' or publish this code on any web site, online
' service, or distribute as source on any
' media without express permission.
'
Private Sub Command1_Click()
On Error Resume Next
Dim oProcess As Object
Dim lProcessID As Long
Dim lRet As Long
Set oProcess = GetObject("winmgmts:{impersonationLevel=impersonate}!\\MyServer\root\cimv2:Win32_Process")
'Or
'Set oProcess = GetObject("winmgmts:{impersonationLevel=impersonate}!\\MyServer.MyDomain.com\root\cimv2:Win32_Process")
lRet = oProcess.Create("Notepad", Null, Null, lProcessID)
MsgBox "Method returned result: " & lRet & vbNewLine & "Id of new process: " & lProcessID, vbOKOnly + vbInformation
End Sub
Gangsta Yoda™ http://www.vbforums.com/attachment.p...chmentid=38679 ®
-
Re: How Do I Run a Process On a Remote System?
Dear
Whether i should pass any values to the procedure given.
if not how does this connet to the server i need.
i tried with this code. iget 0.
can u briefly give me the solution.
my problem is to run the vb file exe in the remote server
from my system using vb code
regards
Nagarjuna
Private Sub Command1_Click()
On Error Resume Next
Dim oProcess As Object
Dim lProcessID As Long
Dim lRet As Long
Set oProcess = GetObject("winmgmts:{impersonationLevel=impersonate}!\\MyServer\root\cimv2:Win32_Process")
'Or
'Set oProcess = GetObject("winmgmts:{impersonationLevel=impersonate}!\\MyServer.MyDomain.com\root\cimv2:Win32_Proces s")
lRet = oProcess.Create("Notepad", Null, Null, lProcessID)
MsgBox "Method returned result: " & lRet & vbNewLine & "Id of new process: " & lProcessID, vbOKOnly + vbInformation
End Sub[/Highlight]
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
You need Administrator permissions on the remote system and no parameters needed to pass.
Change the "MyServer" part to the name of the remote system.
If its returning null then its not executing because of a few different reasons like no permissions, bad computer name, bad file path, etc.
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
RD, is there any way to use this to close down applications as well?
Also, is there a way to make the application visible?
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
I believe there is but I cant test it out as my system died and I'm on my server which doesnt have any form of VB on it. I'll post back when its reloaded or post here to remind me. :)
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Quote:
Originally Posted by RobDog888
I believe there is but I cant test it out as my system died and I'm on my server which doesnt have any form of VB on it. I'll post back when its reloaded or post here to remind me. :)
Ah, ok, what is this method called? I can look it up myself hopefully :)
Good luck with the PC.
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
I think its like this...
VB Code:
For each oProcess in GetObject("winmgmts:{impersonationLevel=impersonate}!//MyServer").ExecQuery("select * from Win32_Process where Name='notepad.exe'")
oProcess.Terminate
MsgBox Process.Name & " Terminated"
Next
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Quote:
Originally Posted by RobDog888
I think its like this...
VB Code:
For each oProcess in GetObject("winmgmts:{impersonationLevel=impersonate}!//MyServer").ExecQuery("select * from Win32_Process where Name='notepad.exe'")
oProcess.Terminate
MsgBox Process.Name & " Terminated"
Next
Ack... all that time it was Terminate. I've tried exit, remove, delete, kill... the list is endless. When i'm back to my machine with a compiler i'll check it out. thanks RD :)
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Np, but I couldnt test it out right now. ;)
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Quote:
Originally Posted by RobDog888
Np, but I couldnt test it out right now. ;)
Still looking for a way to make them visible to the other user on the PC though.
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
What type of process/app are you running? Maybe have to write another one to active the window. Then start one process and then start the other process that activates it?
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Quote:
Originally Posted by RobDog888
What type of process/app are you running? Maybe have to write another one to active the window. Then start one process and then start the other process that activates it?
I was trying to open Word actually, but in the end it will be a range of different programs, so i was hoping there was built in support actually.
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Quote:
Originally Posted by thegreatone
I was trying to open Word actually, but in the end it will be a range of different programs, so i was hoping there was built in support actually.
Sorry to bump, but is there a way of oepning them and making them show remotely?
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Sorry, been real busy lately and havent been posting. I have my system up but no apps installed yet so over the weekend I should be able to try some things.
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Quote:
Originally Posted by RobDog888
Sorry, been real busy lately and havent been posting. I have my system up but no apps installed yet so over the weekend I should be able to try some things.
Thankyou RD. Looking forward to seeing what you manage to come up with (if its possible)
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Wow, that code looks pretty useful.
Thanks!
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Quote:
Originally Posted by RobDog888
[color=navy]Using VB and WMI you can run a process on any remote system on your network. The only requirements are that you have WMI on your system and you have Administrative prividgles on the remote system too.
How do I know whether WMI is installed in my system?
If not installed how/from where can install it?
Is it free for personal/commercial use?
Thanks in advance.
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
I believe WMI comes with Windows...
Quote:
Originally Posted by MS
WMI is preinstalled in Windows Vista, Windows Server "Longhorn", Windows Server 2003, Windows XP, Windows Me, and Windows 2000.
Heres the best page for all about WMI including the WMI SDK link and redistributable link for older systems.
http://msdn.microsoft.com/library/de...start_page.asp
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
i don't understand this line
\\MyServer.MyDomain.com\root\cimv2:Win32_Process
for example myservers name is comp2 and the file that i want to run is Project1.exe and it is located on the shareddocs folder
can i do this changes now
\\comp2\shareddocs:Project1.exe
is that right
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
No, you need to create the process class object first before executing a process.
VB Code:
Set oProcess = GetObject("winmgmts:{impersonationLevel=impersonate}!\\comp2\root\cimv2:Win32_Process")
'Try...
lRet = oProcess.Create("\\comp2\shareddocs\Project1.exe", Null, Null, lProcessID)
I cant test it out right now as my server is down so my network is essentially a workgroup. Let me know it this works for you.
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
nope it didn't work still getting the null results...:S
and please can someone explain me what does this code do?
Set oProcess = GetObject("winmgmts:{impersonationLevel=impersonate}!\\comp2\root\cimv2:Win32_Process")
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
It gets a Win32_Process class object from which you can invoke the .Create function. Do you have Admin permissions?
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
Hey Guys,
Cant seem to get this working:
Code:
On Error Resume Next
Dim oProcess As Object
Dim lProcessID As Long
Dim lRet As Long
Set oProcess = GetObject("winmgmts:{impersonationLevel=impersonate}!\\the_machine\root\cimv2:Win32_Process")
lRet = oProcess.Create("c:\share\1.zip", Null, Null, lProcessID)
MsgBox "Method returned result: " & lRet & vbNewLine & "Id of new process: " & lProcessID, vbOKOnly + vbInformation
If i just put in the file path "cmd" or "notepad" it work great but as soon as i change the path so somewhere outside the system32 dir it fails
-
Re: Classic VB/WMI - How Do I Run a Process On a Remote System?
The app needs to be located on the remote system and you also need admin permissions.