Link to home
Start Free TrialLog in
Avatar of dees
dees

asked on

Run an exe which is located in other computer

hi friends
  i want to run an exe file from my machine  which is located in another compurter pls help me

Dees
Avatar of Sethi
Sethi
Flag of India image

There are two of ways by which you can do this.

First Method
Use the Shell Function In VB. Here is an example:
Shell "C:\WINNT\system32\notepad.exe " & strFileName, vbMaximizedFocus
Specify the textfile name with full path in strFileName.


Second Method
Use ShellExecute API.
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
ShellExecute Me.hwnd, "Open", filePath, 0&, 0&, SW_SHOWNORMAL

Specifying Network Path with ShellExecute
strPath = "\\ABC Computer\C\My Documents\Text.txt"

The last option will run your exe on other machine.
Avatar of MILU
MILU

Hello ,
   u can try winsock control , for that u have to create 2 applications one is Server and Other is client . When Client sends message to the server "Run" then the .exe file is get executed from server.

You may have problem to start because it may require some dll that is not reside in your computer
Avatar of dees

ASKER

hi there
   i want to run an exe from computer A ,The exe is located in  computer B,but the process should run in Computer B not in computer A
Avatar of dees

ASKER

dear Milu
   Can u please send me winsock source code to run exe from  computer A.the process should run in Computer B not in computer A plz send the code..waiting for ur reply

Dees
Here is the code to execute a program on another computer.  Note, this uses WMI, so it works best on Win2K or WinXP.  I haven't been able to get it to work on our NT machines.


'======= Shell ExecProg Code =========

private sub ExecProg(ServerName as string, ProgramName as string)
dim process as object, processid as long, result as long

set process=getobject("WinMgmts:{impersonationLevel=Impersonate, authenticationLevel=pktPrivacy}\\" & servername & "\root\cimv2:Win32_Process")

result=process.create(programname, null, null, processid)

if result=0 then
 msgbox "Command executed successfully on remote machine"
else
 msgbox "Some error, could not execute command"
end if
end sub

'======End of Code=======


You call it as follows:

ExecProg (Comp, Prog)

where Comp is the computername and Prog is the full path of the executable.  To launch notepad on computer "Bob", you'd do it like this:

ExecProg ("Bob", "\\Bob\c$\winnt\system32\notepad.exe")

(or wherever the full path of notepad is on your computer 'Bob')

Hope that helps!
Avatar of dees

ASKER

Dear AlbertaBeef
  i tried ur code but getting "permission denied" error

iam running this code from my computer .my computername is
MXmum12.& i want to run it on MXmum32 computer & the exe is located in "\\MXmum32\d$\bids\x123.exe" .pls check & respond for my request

Dees

''''''''''''''''''''''
 
Private Sub Command1_Click()
  ExecProg "MXmum32", "\\MXmum32\d$\bids\x123.exe"
End Sub
'''''''''''''''''''''''''''''

Private Sub ExecProg(ServerName As String, ProgramName As String)
Dim process As Object, processid As Long, result As Long

Set process = GetObject("WinMgmts:{impersonationLevel=Impersonate, authenticationLevel=pktPrivacy}\\" & ServerName & "\root\cimv2:Win32_Process")

result = process.Create(ProgramName, Null, Null, processid)

If result = 0 Then
MsgBox "Command executed successfully on remote machine"
Else
MsgBox "Some error, could not execute command"
End If
End Sub  
Do you have permissions on the other computer?  Also, what operating systems are on yours, and the other computer?

If you have permissions on the other machine it should work.  I use it for remote administration purposes all the time.
Avatar of dees

ASKER

Dear AlbertaBeef
  yes i have the permission onthe other machine,still its giving same error i,e."Permission Denied".if u have any alternative solution pls send the code.waiting fro reply

Dees

Avatar of dees

ASKER

dear AlbertaBeef
  my Computer A has win 2000 professional and Computer B has win 2000 advance server

Dees
Hello Dees ,
  Wait .... I will upload the code.
ASKER CERTIFIED SOLUTION
Avatar of MILU
MILU

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dees

ASKER

dear milu
  its working fine.if u have any other source code do send
all the best

Dees