我是这样写的
WCHAR *path=(L"C:\\windows\\system32\\cmd.exe /c ping www.baidu.com");//无法执行!
if (CreateProcessAsUser(hDuplicatedToken,path, NULL, NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT,
lpEnvironment, NULL, &si, &pi) == FALSE)
{
LogEvent(L"创建新进程失败");
}
会在日志中输出 创建新进程失败,这里我已经给服务提升权限了,如果没有后面的命令,只写WCHAR *path=(L"C:\\windows\\system32\\cmd.exe ")是可以正常打开的,这是怎么回事呢
7 个解决方案
#1
刚刚用getlasterror试了一下 ,返回3 也就是系统找不到指定的路径。是用法不对还是不能这么用
#2
用法不对吧,看windows核心编程,进程里有讲,详细的参数
#3
把ping www.baidu.com等放到函数的参数中,path只放cmd.exe的路径
#4
BOOL WINAPI CreateProcessAsUser(
_In_opt_ HANDLE hToken,
_In_opt_ LPCTSTR lpApplicationName,
_Inout_opt_ LPTSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCTSTR lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
lpApplicationName 进程路径
lpCommandLine 进程参数
_In_opt_ HANDLE hToken,
_In_opt_ LPCTSTR lpApplicationName,
_Inout_opt_ LPTSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCTSTR lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
lpApplicationName 进程路径
lpCommandLine 进程参数
#5
_Inout_opt_
LPTSTR lpCommandLine,
#6
TCHAR szCmdLine[] = TEXT("cmd.exe /c ping www.baidu.com");
if (!CreateProcessAsUser(hDuplicatedToken, NULL, szCmdLine, NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT,
lpEnvironment, NULL, &si, &pi))
{
// ......
}
#7
感谢各位!可以了
WCHAR *path=(L"C:\\windows\\system32\\cmd.exe");
WCHAR *command=(L"cmd.exe /c ping www.baidu.com");
if (CreateProcessAsUser(hDuplicatedToken,path, command, NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT,
lpEnvironment, NULL, &si, &pi) == FALSE)
#1
刚刚用getlasterror试了一下 ,返回3 也就是系统找不到指定的路径。是用法不对还是不能这么用
#2
用法不对吧,看windows核心编程,进程里有讲,详细的参数
#3
把ping www.baidu.com等放到函数的参数中,path只放cmd.exe的路径
#4
BOOL WINAPI CreateProcessAsUser(
_In_opt_ HANDLE hToken,
_In_opt_ LPCTSTR lpApplicationName,
_Inout_opt_ LPTSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCTSTR lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
lpApplicationName 进程路径
lpCommandLine 进程参数
_In_opt_ HANDLE hToken,
_In_opt_ LPCTSTR lpApplicationName,
_Inout_opt_ LPTSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCTSTR lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
lpApplicationName 进程路径
lpCommandLine 进程参数
#5
_Inout_opt_
LPTSTR lpCommandLine,
#6
TCHAR szCmdLine[] = TEXT("cmd.exe /c ping www.baidu.com");
if (!CreateProcessAsUser(hDuplicatedToken, NULL, szCmdLine, NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT,
lpEnvironment, NULL, &si, &pi))
{
// ......
}
#7
感谢各位!可以了
WCHAR *path=(L"C:\\windows\\system32\\cmd.exe");
WCHAR *command=(L"cmd.exe /c ping www.baidu.com");
if (CreateProcessAsUser(hDuplicatedToken,path, command, NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT,
lpEnvironment, NULL, &si, &pi) == FALSE)