Link to home
Start Free TrialLog in
Avatar of GautamSYadav
GautamSYadav

asked on

Launching an application on remote machine.

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
Avatar of chensu
chensu
Flag of Canada image

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
Avatar of GautamSYadav
GautamSYadav

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

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
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.