• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

Run Exe/ any file remotely?

Hi,

The idea is run an Exe or any kind of file from the client.

Note: I don't want to run the exe in server, but need to run the exe in client side instead.

Thanks and hope you guys understand.
0
trowa
Asked:
trowa
1 Solution
 
chops123Commented:
Your question is too general.Please specify exact requirement.

Where is the exe located ? Why mention the server when you dont need it ?

You can easily run any exe file from your client.

Please elaborate more..

Rgds
KC

0
 
trowaAuthor Commented:
Imagine like this:

Let say: I have develope an application (Exe A) that can lock a computer (from keyboard or mouse, etc). (The Exe A stayed at Client pc). Now a Server pc is activated and it unlock the Client by calling the Exe stayed at Client, then the Exe A launched at Client side.

Something like the software: PcAnywhere??
0
 
chops123Commented:
To deduce what you have said:

The Server Program that is listening for requests will be running at the Server.

You mean to say .. that the Server program should unlock the client (what do u mean by unlock) by calling the exe (which exe is this) on the Client PC and then launch the same exe which locks the computer..

:-( ... well I dont think its still clear.This doesnt make much sense.

---------------------------------------------------
If I can somewhat understand what you are trying to do:

You have a client program that needs to control another computer.

Ideally,you would need to have a "server program" running on the PC that you wish to connect to on some specific port no.

When you connect to the desired PC,you want to send certain commands that will do some activity on the desired PC like "shut down pc","start notepad".

What else ?
--------------------------------------------------

Please comment as to what I deducee is correct.

Rgds
KC
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
glass_cookieCommented:
Hi!

To do something like that, you'll need to do something like use winsock to connect the 2 programs together.  You'll also need sort of a medium to do that, either through the network, or through the internet.


Here's a an example to help you:

Download...
http://www.vb-helper.com/HowTo/sockchat.zip
Description: Use winsock to make a simple chat program (3K)

Instead of using the above example as a chat program, you'll simply use the senddata method to send a 'command', and under this event,

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

you'll use

winsock1.getdata <a string to store the data>

To read the data into a string.  From there, you should then issue code to do whatever the command represents.

That's it!

glass cookie : )
0
 
roysterCommented:
What are you doing? Is this web based application? You can make an active X control. Using ASP you can open documents on the client side. Browser security will prevent you from running exe's unless the user ok's an ocx install.
0
 
jdc0724Commented:
It sounds like you have a central server that you would like to be able to control a PC (or a number of PC's) from.  You would have an exe on each client PC that would be called by the central server application.  I am assuming you are on some sort of network.  If the server pc is running windows as its operating system, and you plan on using a Visual Basic program on the server (for your server program) that will call the Client side exe(s), then you can use the following code in the SERVER Visual Basic program in a bas module:

=======================================================
In the beginning of the module insert the following declarations:
=======================================================

'--- WinAPI declarations
Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Declare Function GetLastError Lib "kernel32" () As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Const NORMAL_PRIORITY_CLASS = &H20

Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
End Type

Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessId As Long
        dwThreadId As Long
End Type

Type STARTUPINFO
        cb As Long
        lpReserved As String
        lpDesktop As String
        lpTitle As String
        dwX As Long
        dwY As Long
        dwXSize As Long
        dwYSize As Long
        dwXCountChars As Long
        dwYCountChars As Long
        dwFillAttribute As Long
        dwFlags As Long
        wShowWindow As Integer
        cbReserved2 As Integer
        lpReserved2 As Byte
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
End Type

===========================================================================
In your code copy this function that will run an exe by passing the full path and name of the exe
(Ex: c:/projects/example.exe) or (Ex: "\\pcname\projects\example.exe") if you want the server to
execute the exe on another client machine anywhere on the network. This will execute the exe
and return a long value indicating success or failure.
===========================================================================

Public Function ExecCmd(cmdline$) As Long
    '--------------------------------------------------------------------------------------------
    ' This function will execute an external process and wait for it to complete before resuming-
    ' with this program.                                                                        -
    '--------------------------------------------------------------------------------------------
    Dim lngWork As Long
    Dim proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO
    Const INFINITE = &HFFFF      '  Infinite timeout

On Error GoTo ERROR_HANDLER:
' Initialize the STARTUPINFO structure:
    start.cb = Len(start)
' Start the shelled application:
    Call CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, _
        vbNullString, start, proc)
' Wait for the shelled application to finish:
    lngWork = WaitForSingleObject(proc.hProcess, INFINITE)
    Call GetExitCodeProcess(proc.hProcess, lngWork)
    Call CloseHandle(proc.hThread)
    Call CloseHandle(proc.hProcess)
    ExecCmd = lngWork
    GoTo SKIP_ERROR_HANDLER
ERROR_HANDLER:
        Resume Next
SKIP_ERROR_HANDLER:
End Function

This code should definitely be in your server program and all you have to do is change the path to the pc you want to execute the EXE on.  Hope this helps.  We use this quite often.

Thanks,
JDC0724
0
 
xchaixCommented:
exe at client, and database at server..
just do like this.. using namepipe..

c:\your_app.exe \\your_server_name\your_shared_folder\your_database.mdb


hope u like it :)

-chai-
0
 
trowaAuthor Commented:
Maybe here are 2 solution, first using Client - Server application, second is using the CreateProcess API as shown above. Which is better? Why?
0
 
trowaAuthor Commented:
I have tried the Client- server example posted by Glass Cookie, is it possible to make this application to 1 server, multiple Clients structure? Is that mean i need to open multiple ports?? or how can i do that? thanks
0
 
Asta CuCommented:
A deletion request has been issued in the Community Support topic area, which a Moderator will handle shortly.

Any time a deletion is requested, the primary question should contain the comment that you wish to delete so that the Experts who have helped you are advised.

":0) Asta
0
 
trowaAuthor Commented:
So, can i delete this question, or can someone give advise who deserve the points and why? TQ
0
 
JgouldCommented:
monitoring for a day or two if no one is opposing then i'll move this to PAQ : points refunded : grade a B

JGould-EE Moderator
0
 
MindphaserCommented:
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now