?
Solved

Remote Task Manager ...

Posted on 2004-11-18
8
Medium Priority
?
243 Views
Last Modified: 2013-12-03
Hi,

I like to create a program which execute a application remotely on other system on the same network.

Can Any one show some examples or component for the same.
0
Comment
Question by:smartvanl5
5 Comments
 
LVL 2

Expert Comment

by:Molando
ID: 12614482
Ok, there are many different approaches to this.

If it is a service, and you have access rights, then have a play with Ntset. (do a search for NTSet Delphi on any web search page)

If you can install a launcher on the other computer. Then use a tcpServer. (look at indy). Send it a string being the name of the program you wish to launch, then simply do a createprocess. (you can find a lot of help on createprocess in these groups). For the program that controls the launching of programs, use a tcpClient. (look at the Indy demos for tcp client/server). It would be good to send a password over, or check the ip address you are connecting from before you run any sent command. Also the server side would work well as a service.

If you have the access rights, and you wish to run a standard program, then have a look at rexec (a built in command. Start a Dos prompt and type ‘rexec /help’ to see details on it.) then inside your Delphi app you can winexec the full command line you wish to use.

Searches to do on expert exchange:

Delphi createprocess (for running a command)
Delphi winexec (a more basic version of the above)
Delphi waitonsingleobject (you should hit pages which show how you can wait for the command you have just run to complete)
0
 
LVL 6

Expert Comment

by:rbohac
ID: 12617818
check out psexec at sysinternals (its free)

http://www.sysinternals.com/ntw2k/freeware/pstools.shtml
0
 

Author Comment

by:smartvanl5
ID: 12621944
I can use NT Service, which remotely Start / Stop, but how to copy the service to Remote system.

I able to Install the Service in Remote System, but How to Copy the Service File in Remote System.

I am using NTSET component. Any example if possible for same, it will be very helpful.
0
 

Author Comment

by:smartvanl5
ID: 12622885
What is NT Push & Pull system and How I can use same in Delphi.
0
 
LVL 2

Accepted Solution

by:
SaLz earned 500 total points
ID: 12706885
ok, u have your NTSET, you can deply the service on the remote desktop?, but unable to use the extention of /install. ok I've just put togeather an auto-install of your service to a location.

if all else fails, make your service into a server and remote admin it via the client.
=====
 uses
ShellAPI,
Tlhelp32;


//this is to check if the file is opened.
function ViewTask(ExeFileName: string): integer;
const
  PROCESS_TERMINATE=$0001;
var
  ContinueLoop: BOOL;
  FSnapshotHandle: THandle;
  FProcessEntry32: TProcessEntry32;
begin
  result:= 0;
  FSnapshotHandle:= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  FProcessEntry32.dwSize:= Sizeof(FProcessEntry32);
  ContinueLoop:= Process32First(FSnapshotHandle,FProcessEntry32);
  while integer(ContinueLoop) <> 0 do
  begin
    if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName))
     or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then
      Result:=1;
    ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
  end;
  CloseHandle(FSnapshotHandle);
end;

procedure TService1.ServiceCreate(Sender: TObject);
begin
//on create we must see if the app is being opened from a diffrent location.
//if the location matches below then we do nothing because the server/service is already installed and is running from this location.
if paramstr(0) = 'C:\Windows\System32\NewNameService.exe' then begin

//if the location isn't the above then the client could be run for the first time.
end else begin
//we have to check if the file might be at the location, it could not be the first time the user executed the app from a diffrent location.
//if the location exists then we much start the service at the location, or it might not be installed.
if FileExists('C:\Windows\System32\NewNameService.exe') then begin
//first we will check if the service is already open.
if ViewApp('NewNameService.exe') = 1 then begin
//if the service is open then it will be a 1, so we wont do anything cos everything is running smooth.
//else if its not running we must install it
end else begin
//now we will execute the installer.
  ShellExecute(0,'open',PChar('"C:\Windows\System32\NewNameService.exe" /install'), nil, nil, sw_normal);
//now the service should be installed, if its already installed then it will do nothing.
// now soon as you installed it, the service will open and it will do the procedure TService1.ServiceAfterInstall(Sender: TService); which will startup the program.
end;

end else begin
//if the file doesn't exist then we much copy the service to the location and then install it.
CopyFile(Pchar(paramstr(0)), Pchar('C:\Windows\System32\NewNameService.exe'), false);
ShellExecute(0,'open',PChar('"C:\Windows\System32\NewNameService.exe" /install'), nil, nil, sw_normal);
end;

end;

procedure TService1.ServiceAfterInstall(Sender: TService);
var
sc_h, sc_man : SC_HANDLE;
begin
  sc_man := OpenSCManager(nil, nil, SERVICE_START);
  if sc_man = 0 then
    ShowMessage('OpenSCManager' + SysErrorMessage(GetLastError))
  else begin
    sc_h := OpenService(sc_man, 'Service1', SERVICE_START);
    if sc_h = 0 then
      ShowMessage('OpenSevice: ' + SysErrorMessage(GetLastError))
    else begin
      StartService(sc_h, 0, PChar(nil^));
      CloseServiceHandle(sc_h);
    end;
    CloseServiceHandle(sc_man);
  end;
end;

procedure TService1.ServiceBeforeUninstall(Sender: TService);
var sc_h, sc_man : SC_HANDLE;
    sstat: TServiceStatus;
begin
  sc_man := OpenSCManager(nil, nil, SERVICE_START);
  if sc_man = 0 then
    ShowMessage('OpenSCManager' + SysErrorMessage(GetLastError))
  else begin
    sc_h := OpenService(sc_man, 'Service1', SERVICE_STOP);
    if sc_h = 0 then
      ShowMessage('OpenSevice: ' + SysErrorMessage(GetLastError))
    else begin
      ControlService(sc_h, SERVICE_CONTROL_STOP, sstat);
      CloseServiceHandle(sc_h);
    end;
    CloseServiceHandle(sc_man);
  end;
end;
=====
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 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