请问如何编程以其他用户的身份来运行一个程序?

chenzb 2003-09-12 06:14:40
rt,如何编程才能以其他用户的身份(比如说管理员的身份)来运行一个程序,前提我知道管理员的用户名和密码
请大伙指导我一下,最好给我一个例子多谢
ice7369110@sohu.com
...全文
101 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenzb 2003-09-16
  • 打赏
  • 举报
回复
多谢了
ahao 2003-09-15
  • 打赏
  • 举报
回复
比较简单的方法是调用
BOOL CreateProcessWithLogonW(
LPCWSTR lpUsername,
LPCWSTR lpDomain,
LPCWSTR lpPassword,
DWORD dwLogonFlags,
LPCWSTR lpApplicationName,
LPWSTR lpCommandLine,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCWSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInfo
);

chenzb 2003-09-15
  • 打赏
  • 举报
回复
我的是在win2000中运行的
feeboby 2003-09-15
  • 打赏
  • 举报
回复
gz
up
chenzb 2003-09-15
  • 打赏
  • 举报
回复
出错的号码是:1314(A required privilege is not held by the client. )
救救我了!
还有什么途径?方法?
chenzb 2003-09-15
  • 打赏
  • 举报
回复
可以的,我记得在安装某些程序的时候,有一个选择,如果要用管理员的的身份运行的话,则要输入管理员的用户名和密码

Kevin_qing() :我在poweruser中运行logonuser()函数,好像的不到token,总是出错,有什么好办法吗?
ahao 2003-09-15
  • 打赏
  • 举报
回复
看这个:

To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0500 or later. For more information, see Using the SDK Headers.

Using the SDK Headers

This version of the Microsoft® Platform SDK enables you to create applications that run on Microsoft® Windows® Server 2003 family, Windows XP, Windows 2000, Windows Millennium Edition (Windows Me), Windows 98, Windows NT® 4.0, and Windows 95. You can also create 64-bit applications. The header files use data types that allow you to build both 32- and 64-bit versions of your application from a single source code base. For more information, see Getting Ready for 64-bit Windows.


Microsoft® Visual C++® includes content from the edition of the Platform SDK that was current at the time Visual C++ was released. Therefore, if you install the latest Platform SDK, you may end up with multiple versions of the same header files on your computer. To ensure that you are using the latest version of the SDK header files, follow the directions included in Installing the Platform SDK with Visual Studio. Otherwise, you will receive the following error when compiling code that uses features that were introduced after Visual C++ was released: error C2065: undeclared identifier.

Certain functions that depend on a particular version of Windows are declared using conditional code. This enables you to use the compiler to detect whether your application uses functions that are not supported on its target version(s) of Windows. To compile an application that uses these functions, you must define the appropriate macros. Otherwise, you will receive the C2065 error message. The following table indicates the macros you must define to target each system.

Minimum system required Macros to define
Windows Server 2003 family _WIN32_WINNT>=0x0502
Windows XP _WIN32_WINNT>=0x0501
Windows 2000 _WIN32_WINNT>=0x0500
Windows NT 4.0 _WIN32_WINNT>=0x0400
Windows Me _WIN32_WINDOWS=0x0490
Windows 98 _WIN32_WINDOWS>=0x0410
Internet Explorer 6.0 _WIN32_IE>=0x0600
Internet Explorer 5.01, 5.5 _WIN32_IE>=0x0501
Internet Explorer 5.0, 5.0a, 5.0b _WIN32_IE>=0x0500
Internet Explorer 4.01 _WIN32_IE>=0x0401
Internet Explorer 4.0 _WIN32_IE>=0x0400
Internet Explorer 3.0, 3.01, 3.02 _WIN32_IE>=0x0300


For example, to use the features specifically marked for Windows 2000 in the header files, you need to explicitly define _WIN32_WINNT as 0x0500 or greater. You can define the symbols using the #define statement in each source file, or by specifying the /D_WIN32_WINNT=0x0500 compiler option supported by Visual C++.


Visual C++ 6.0: To specify compiler options, go to the Projects menu and click Settings, then select the C/C++ tab.



Visual C++ 7.0: To specify compiler options, go to the Projects menu and click Properties.


The macros in Win32.mak can help you define the correct macros. The value of _WIN32_WINNT depends on the platform you choose to target. For more information, see Building Applications Using Win32.mak.

chenzb 2003-09-15
  • 打赏
  • 举报
回复
多谢ahao、NowCan,
还有一个问题,我使用的时vc6.0,它本身的include中没有CreateProcessWithLogonW()函数,所以我到微软的网站上下载了sdk(2003年的)安装,我已经在vc中按要求设置好了,然后就有几点疑问:
1、但是编译的时候提示:undeclared identifier,在那里出错了?
2、vc原来的头文件、库文件等和win sdk的头文件、库文件有些名字是一样的,要怎样才能解决他们的冲突?
NowCan 2003-09-15
  • 打赏
  • 举报
回复
http://asp.6to23.com/nowcan/newweb/list.asp?id=260

logonuser()需要有TCB权限才能成功,而这个权限默认时没有哪个用户有。
Kevin_qing 2003-09-13
  • 打赏
  • 举报
回复
先用logonuser()得到token,如果为impersonation token需要用duplicatetokenex转换为primary token,然后调用createprocessasuser建立新进程。需要nt3.51以上系统
vagabondkq 2003-09-13
  • 打赏
  • 举报
回复
应该是不允许吧
gzshd 2003-09-13
  • 打赏
  • 举报
回复
不可能在普通用户里得到管理员的权限的

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧