Home > Software engineering >  On the outside of the service using CreateProcessAsUser running EXE can't create a shortcut
On the outside of the service using CreateProcessAsUser running EXE can't create a shortcut

Time:09-27

In service program using CreateProcessAsUser run external EXE cannot create desktop shortcuts and start menu bar shortcut, other directory file to read and write is no problem, interact with the desktop is also no problem,
Is not the problem of external EXE, direct manually run external EXE didn't appear these problems,
The following is the code:
 
HANDLE hToken;
//create a snapshot process
PROCESSENTRY32 pe32={0};
Pe32. DwSize=sizeof (pe32);
HANDLE hSnapShot=CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
If (hSnapShot!=0 & amp; & HSnapShot!=INVALID_HANDLE_VALUE)
{
BOOL bRet=Process32FirstW (hSnapShot, & amp; Pe32);
While (bRet)
{
If (_tcsicmp (pe32 szExeFile, L "Explorer. EXE")==0)
{
HANDLE hProcess=OpenProcess (PROCESS_ALL_ACCESS, false, pe32 th32ProcessID);

If (hProcess!=NULL)
{
BOOL flag=OpenProcessToken (hProcess, TOKEN_ALL_ACCESS, & amp; HToken);
The CloseHandle (hProcess);
}
break;
}
BRet=Process32Next (hSnapShot, & amp; Pe32);
}
The CloseHandle (hSnapShot);
}

STARTUPINFO si={sizeof (si)};
PROCESS_INFORMATION PI;
//TCHAR FileName [256] external EXE the full path of the
BOOL bSuccess=CreateProcessAsUser (hToken, FileName, NULL, NULL, NULL, FALSE, NULL, NULL, NULL, & amp; Si, & amp; PI);

The great god, please give advice or comments

CodePudding user response:

Search "Session0 through"

CodePudding user response:

reference 1st floor zhao4zhong1 response:
search "Session0 through"

He couldn't do it on XP, let alone Windows 7

CodePudding user response:

reference 1st floor zhao4zhong1 response:
search "Session0 through"

Xp has Session isolation?

CodePudding user response:

refer to the second floor wuyouba9345 response:
Quote: refer to 1st floor zhao4zhong1 response:

Search "Session0 through"

He couldn't do it on XP, let alone Windows 7

Please check the return value of each function call,

CodePudding user response:

Close the anti-virus software,...

CodePudding user response:

This generally written in the current user directory, your program starts, take a look at user permissions etc is correct, then is to have a look at the write the error information returned failure

CodePudding user response:

Using a debugger (OD, WINDBG) debugging service program
To debug the initialization code of a service application, the debugger must be attached when the service is started. This is accomplished by creating a registry key:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Image File Execution Options \ ProgramName


The ProgramName is The image file for The service application you are was debugging. Do not specify a path. For example, The ProgramName took look like MyService. Exe.

Under this key The create a string data value called The Debugger. The value of this string should be set to The full path of The Debugger that will be 2. For example,

C: \ Debuggers \ windbg exe



In addition to setting this registry key, the service application must be marked as "interactive". This allows your service to interact with the desktop, and allows the debugger window to appear on your desktop.

This again requires modifying a registry key, you must bitwise - or the type entry for service with 0 x100 (This is the value for SERVICE_INTERACTIVE_PROCESS "according to Winnt. H). The exact location and the name of This registry entry around the for example:

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ MyServiceKey


Finally, you need to adjust the service application timeout. Otherwise, the service application will kill the debugger within 20 seconds after starting, Adjusting the timeout involves setting an entry in the following registry key:

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control


Under this key, the create a DWORD data value called ServicesPipeTimeout. Set this entry to the amount of time in milliseconds that want the service to wait before timing out. For example, 60000 is one minute, while 86400000 is 24 hours.

Set to come into force after ServicesPipeTimeout need to restart the system

Now, when the service is started, the debugger will also start. When the debugger starts, it will stop at the initial process breakpoint, before the service has begun running. This allows you to set breakpoints or otherwise configure your debugging session to let you monitor the startup of your service. Another option is to place calls to the DebugBreak function in your service from the point at which you would like to break into the debugger. (For more information, see DebugBreak in the Platform SDK documentation.)

If your service is running with other services in a service Host Process, you may need to isolate the service into its own service Host Process.

CodePudding user response:

I improve the code,
 BOOL bSuccess=FALSE; 
STARTUPINFO si={0};
//process information
PROCESS_INFORMATION PI={0};
Si. Cb=sizeof (si);

//get the current Session ID
DWORD dwSessionID=WTSGetActiveConsoleSessionId ();
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related