Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Launching an application on remote machine.

Posted on 2004-03-23
4
Medium Priority
?
476 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 750 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

927 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