首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

关于CreateProcessWithLogonW,该怎么解决

2011-12-28 
关于CreateProcessWithLogonW我在Debug的时候提示未定义,头大了.....Compiling...abcdDlg.cppC:\Documents

关于CreateProcessWithLogonW
我在Debug的时候提示未定义,头大了.....

Compiling...
abcdDlg.cpp
C:\Documents and Settings\Administrator\桌面\提升权限\abcd\abcdDlg.cpp(197) : error C2065: 'CreateProcessWithLogonW' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\提升权限\abcd\abcdDlg.cpp(197) : error C2065: 'LOGON_WITH_PROFILE' : undeclared identifier
Error executing cl.exe.

PSDK我也有安装,并且设置正确

请问有人愿意提供 CreateProcessWithLogonW() 函数使用的完整代码吗?先谢了,各位帮帮忙吧

[解决办法]
在stdafx.h中,包含所有头文件之前,加上:
#define _WIN32_WINNT 0x0500
[解决办法]
呵呵不行你就把原型重新声明一下不就得了:
BOOL CreateProcessWithLogonW(
LPCWSTR lpUsername, // user's name
LPCWSTR lpDomain, // user's domain
LPCWSTR lpPassword, // user's password
DWORD dwLogonFlags, // logon option
LPCWSTR lpApplicationName, // executable module name
LPWSTR lpCommandLine, // command-line string
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // new environment block
LPCWSTR lpCurrentDirectory, // current directory name
LPSTARTUPINFOW lpStartupInfo, // startup information
LPPROCESS_INFORMATION lpProcessInfo // process information
);

[解决办法]
用的是VC6吧?
请先安装XPSP2PSDK,微软网站上有下
VC6自带的Winbase.h上没有这个定义
[解决办法]
vc6好使,可是自带的sdk库太久了,可以下载新的SDK,然后添加到include目录中
[解决办法]
加不加unicode编译这个到不一定,可能是要装SDK2003,因为VC6自带的SDK太旧了。
[解决办法]
有个例子:
将子进程以User权限运行,xp sp2 + VS2005测试通过

#define _WIN32_WINNT 0x0500

#include <Windows.h>
#include <WinBase.h>
#include <stdio.h>
#include <lm.h>
#include <Lmaccess.h>


#pragma comment(lib,"Netapi32.lib")
#pragma comment(lib,"Advapi32.lib")


int APIENTRY WinMain(HINSTANCE hInstance, 
HINSTANCE hPrevInstance, 
LPSTR lpCmdLine, 
int nCmdShow = SW_SHOW) 
{
STARTUPINFOW starinfo={0};
PROCESS_INFORMATION proinfo={0};

USER_INFO_1 user;
DWORD dwLevel = 1;
DWORD dwError = 0;
NET_API_STATUS nStatus;

user.usri1_name = L"abcde";
user.usri1_password = L"11222";
user.usri1_priv = USER_PRIV_USER;
user.usri1_home_dir = NULL;
user.usri1_comment = NULL;
user.usri1_flags = UF_SCRIPT;
user.usri1_script_path = NULL;

nStatus=NetUserAdd(NULL,dwLevel,(LPBYTE)&user,&dwError);

if(nStatus == NERR_Success)
{
Sleep(100);
MessageBoxA(NULL,"创建成功","OK",NULL);
  
starinfo.cb = sizeof(starinfo);
CreateProcessWithLogonW(L"abcde",NULL,L"11222",LOGON_WITH_PROFILE,NULL,L"123.EXE",DEBUG_PROCESS,NULL,NULL,&starinfo,&proinfo);
  
nStatus = NetUserDel(NULL,L"abcde");
MessageBoxA(NULL,"删除成功","OK",NULL);
}

return 0;

}

热点排行