sreekanthpuram
March 11th, 2003, 06:06 PM
I am trying to write a program which opens a notepad application on windows XP machine. I have used the createprocess() function to acheive this. If i open the command prompt and run my program, the note pad application opens up without any problem.
I tried run the same application as a service it displays a part of the GUI for note pad. I have passed on "winsta0\default" as the desktop with the startup parameters to the createprocess application. The user who is running the service is same as the loggedon user.
I tried to run the same executable on a win2k machine as a service, the notepad application opens without any problems. Can anyone help me out to solve this problem.
The code looks like this and the input to this would be the application I would be launching ie notepad.exe.
I would be thankful to anyone who would helpme out with this.
------------------------------------------------------------------------------------
#include <windows.h>
#include <iostream.h>
void main (int argc , char * argv[])
{
void fnc_CreateProcess(char *);
fnc_CreateProcess(argv[1]);
}
void fnc_CreateProcess(char * command)
{
STARTUPINFO si;
HDESK hdesk;
HWINSTA hwinsta;
SECURITY_ATTRIBUTES saProcess, saThread;
PROCESS_INFORMATION piProcess;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.lpDesktop = "winsta0\\Default";
saProcess.nLength = sizeof(saProcess);
saProcess.lpSecurityDescriptor = NULL;
saProcess.bInheritHandle = TRUE;
saThread.nLength = sizeof(saThread);
saThread.lpSecurityDescriptor = NULL;
saThread.bInheritHandle = FALSE;
cout << "The command is " << command << ":)\n";
// HANDLE hToken;
//
hwinsta = OpenWindowStation(
"winsta0",
TRUE,
READ_CONTROL | WRITE_DAC | GENERIC_ALL
);
hdesk = OpenDesktop(
"default",
0,
FALSE,
READ_CONTROL | WRITE_DAC |
DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |GENERIC_ALL
);
if (!SetProcessWindowStation(hwinsta))
cout << "Error";
CloseWindowStation(hwinsta);
CloseDesktop(hdesk);
BOOL bRetVal = CreateProcess(NULL, command, &saProcess, &saThread, FALSE,
0, NULL, NULL,&si, &piProcess);*/
PHANDLE phToken = NULL;
if (bRetVal)
cout<< "success";
else
cout << TEXT(GetLastError());
}
------------------------------------------------------------------------------------
I tried run the same application as a service it displays a part of the GUI for note pad. I have passed on "winsta0\default" as the desktop with the startup parameters to the createprocess application. The user who is running the service is same as the loggedon user.
I tried to run the same executable on a win2k machine as a service, the notepad application opens without any problems. Can anyone help me out to solve this problem.
The code looks like this and the input to this would be the application I would be launching ie notepad.exe.
I would be thankful to anyone who would helpme out with this.
------------------------------------------------------------------------------------
#include <windows.h>
#include <iostream.h>
void main (int argc , char * argv[])
{
void fnc_CreateProcess(char *);
fnc_CreateProcess(argv[1]);
}
void fnc_CreateProcess(char * command)
{
STARTUPINFO si;
HDESK hdesk;
HWINSTA hwinsta;
SECURITY_ATTRIBUTES saProcess, saThread;
PROCESS_INFORMATION piProcess;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.lpDesktop = "winsta0\\Default";
saProcess.nLength = sizeof(saProcess);
saProcess.lpSecurityDescriptor = NULL;
saProcess.bInheritHandle = TRUE;
saThread.nLength = sizeof(saThread);
saThread.lpSecurityDescriptor = NULL;
saThread.bInheritHandle = FALSE;
cout << "The command is " << command << ":)\n";
// HANDLE hToken;
//
hwinsta = OpenWindowStation(
"winsta0",
TRUE,
READ_CONTROL | WRITE_DAC | GENERIC_ALL
);
hdesk = OpenDesktop(
"default",
0,
FALSE,
READ_CONTROL | WRITE_DAC |
DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |GENERIC_ALL
);
if (!SetProcessWindowStation(hwinsta))
cout << "Error";
CloseWindowStation(hwinsta);
CloseDesktop(hdesk);
BOOL bRetVal = CreateProcess(NULL, command, &saProcess, &saThread, FALSE,
0, NULL, NULL,&si, &piProcess);*/
PHANDLE phToken = NULL;
if (bRetVal)
cout<< "success";
else
cout << TEXT(GetLastError());
}
------------------------------------------------------------------------------------