Solved

Launching an application on remote machine.

Posted on 2004-03-23
4
458 Views
Last Modified: 2013-11-20
Hi All,
Can any one tell me, how to launch an application (executable) on remote machine from my workstation(In office LAN)?

To do this I m doing following efforts....
1. Copying the application(xyz.exe file) on remote machine using CopyFile() API.
2. Copying a service ( RemoteExeService.exe written by me) on remote machine.
3. Installing, starting the RemoteExeService on remote machine. (from my local  workstation).
   
   Now I m putting some code in RemoteExeService to find & execute the application (xyz.exe). basically calling ShellExecute API to execute xyz.exe.
Now problem is that, whenever I m starting service on remote machine, the application ( xyz.exe) is not launching, but I can see this xyz.exe in processes of remote machine (appearing in windows Task manager).

 can any one of you give some sample code for service to launch this application ?
I have administrative privileges of remote machine. Even if I m testing it on my local machine the application is not launching.

I really want help to this problem and any usefull input to this problem will get points from me.

Thanks & Regard
GautamSYadav
0
Comment
Question by:GautamSYadav
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 10664665
Use CreateProcess() instead of ShellExecute() to specify the user's interactive window station and default desktop. See

Creating an Interactive Process
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating_an_interactive_process.asp
0
 

Author Comment

by:GautamSYadav
ID: 10664972
Thanks for reply.
I have tryed the CreateProcess(), but it is giving same results.
In the service, i m doing following....

creating a thread .......
CreateThread (0, 0, (LPTHREAD_START_ROUTINE )MyService, 0, 0, &ThreadId)

and this is the function Myservice()

DWORD WINAPI MyService ()
{
      
     STARTUPINFO         si = { sizeof(STARTUPINFO) };
     si.lpDesktop = "WinSta0\\Default";
     si.cb = sizeof(STARTUPINFO);
     si.dwFlags = STARTF_USESHOWWINDOW;
     si.wShowWindow = SW_SHOWNOACTIVATE|SW_SHOWDEFAULT;
     PROCESS_INFORMATION pi = {0};
     LPCTSTR szExecutablePath = _T("E:\\Public\\DllRegister.exe");
     TCHAR               szCmdLine [2*MAX_PATH];
     wsprintf ( szCmdLine, _T("\"%s\" /c /s"), szExecutablePath );
     fprintf (stdout, "Service started!\n");
    while (1)
    {
          if (StopServing)
         {
               fprintf (stdout, "Service stopped!\n");
      StoppedServing = 1;
      return 0;
         }
         //WinExec(szExecutablePath, SW_SHOWMAXIMIZED);
//ShellExecute(NULL, "open" , "DllRegister.exe", "E:\\Public\\DllRegister.exe", (LPCTSTR)"E:\\Public", SW_SHOWNORMAL);
                        
CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS , NULL, "E:\\Public", &si, &pi);
            
        //Beep (1000, 300);
        //Sleep (700);
        //break;
            
    }
    return 0;
}

all three ShellExecute, CreateProcess and WinExec are giving same results.
Is this the right manner to do the same ?

If i m doing same in simple console application, the things are going well and able to launch application. but not working through service.

Thanks again

Regards
GautamSYadav
0
 
LVL 23

Accepted Solution

by:
chensu earned 250 total points
ID: 10670167
"To create an interactive process as shown in this example, a service application must be logged in to the LocalSystem account."
0
 

Expert Comment

by:jcalles
ID: 10873960
A service must have the ability to interact with the desktop if you want to display something. You can check the service by viewing the properties to see if the "Allow service to interact with desktop" is checked. You can also set this when you create the service. You can use dwServiceType and the SERVICE_INTERACTIVE_PROCESS bit to set this programatically. I have included the section from the help files that describes the function.

Regards,
JC

SC_HANDLE CreateService(
  SC_HANDLE hSCManager,  // handle to service control manager database
  LPCTSTR lpServiceName, // pointer to name of service to start
  LPCTSTR lpDisplayName, // pointer to display name
  DWORD dwDesiredAccess, // type of access to service
  DWORD dwServiceType,   // type of service
  DWORD dwStartType,     // when to start service
  DWORD dwErrorControl,  // severity if service fails to start
  LPCTSTR lpBinaryPathName,  // pointer to name of binary file
  LPCTSTR lpLoadOrderGroup,  // pointer to name of load ordering group
  LPDWORD lpdwTagId,     // pointer to variable to get tag identifier
  LPCTSTR lpDependencies,  // pointer to array of dependency names
  LPCTSTR lpServiceStartName, // pointer to account name of service
  LPCTSTR lpPassword       // pointer to password for service account
);

dwServiceType
A set of bit flags that specify the type of service. You must specify one of the following service types. Value Meaning
SERVICE_WIN32_OWN_PROCESS Specifies a Win32-based service that runs in its own process.
SERVICE_WIN32_SHARE_PROCESS Specifies a Win32-based service that shares a process with other services.
SERVICE_KERNEL_DRIVER Specifies a driver service.
SERVICE_FILE_SYSTEM_DRIVER Specifies a file system driver service.

If you specify either SERVICE_WIN32_OWN_PROCESS or SERVICE_WIN32_SHARE_PROCESS, you can also specify the following flag. Value Meaning
SERVICE_INTERACTIVE_PROCESS  Enables a Win32-based service process to interact with the desktop.

0

Featured Post

What Security Threats Are You Missing?

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.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
paragon account problem 9 96
iSeries FTP Exit Program 8 114
Smart Camera scanning and reading information 3 86
centeredAverage challenge 8 123
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

21 Experts available now in Live!

Get 1:1 Help Now