Solved

Run Exe/ any file remotely?

Posted on 2002-05-30
13
211 Views
Last Modified: 2012-05-04
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
Comment
Question by:trowa
13 Comments
 
LVL 2

Expert Comment

by:chops123
Comment Utility
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
 

Author Comment

by:trowa
Comment Utility
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
 
LVL 2

Expert Comment

by:chops123
Comment Utility
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
 
LVL 8

Expert Comment

by:glass_cookie
Comment Utility
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
 
LVL 1

Expert Comment

by:royster
Comment Utility
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
 
LVL 1

Expert Comment

by:jdc0724
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:xchaix
Comment Utility
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
 

Author Comment

by:trowa
Comment Utility
Maybe here are 2 solution, first using Client - Server application, second is using the CreateProcess API as shown above. Which is better? Why?
0
 

Author Comment

by:trowa
Comment Utility
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
 
LVL 27

Expert Comment

by:Asta Cu
Comment Utility
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
 

Author Comment

by:trowa
Comment Utility
So, can i delete this question, or can someone give advise who deserve the points and why? TQ
0
 

Expert Comment

by:Jgould
Comment Utility
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
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
Comment Utility
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now