首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CreateProcessAsUser,调用dll函数

CreateProcessAsUser,调用dll函数
EN

Stack Overflow用户
提问于 2012-06-25 20:31:33
回答 2查看 551关注 0票数 0

使用CreateProcessAsUser,我可以调用硬盘上某处的.exe文件:

代码语言:javascript
复制
CreateProcessAsUser(IntPtr hToken, string lpApplicationName, string lpCommandLine,
                      ref SECURITY_ATTRIBUTES lpProcessAttributes, ref SECURITY_ATTRIBUTES lpThreadAttributes,
                      bool bInheritHandle, Int32 dwCreationFlags, IntPtr lpEnvrionment,
                      string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo,
                      ref PROCESS_INFORMATION lpProcessInformation);

我在web上找到的每个示例都使用lpCommandLine参数来调用程序。我想调用dll中的函数。有没有人知道这是否可能?如果能举个例子就好了。

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-06-25 21:20:06

您不能以不同的用户身份直接调用DLL,因为用户/执行级别是针对每个进程的,而不是针对DLL或线程的。必须启动一个新进程,然后调用DLL。这是COM elevation等使用的技术。如果DLL具有正确的签名,您可以尝试使用rundll32.exe调用它。

票数 2
EN

Stack Overflow用户

发布于 2012-06-25 20:44:15

我不认为使用该功能是可能的。在dll中调用方法的标准方式是使用LoadLibraryGetProcAddress方法,如下例所示:

(摘自MSDN)

代码语言:javascript
复制
// A simple program that uses LoadLibrary and 
// GetProcAddress to access myPuts from Myputs.dll. 

#include <windows.h> 
#include <stdio.h> 

typedef int (__cdecl *MYPROC)(LPWSTR); 

int main( void ) 
{ 
    HINSTANCE hinstLib; 
    MYPROC ProcAdd; 
    BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 

    // Get a handle to the DLL module.

    hinstLib = LoadLibrary(TEXT("MyPuts.dll")); 

    // If the handle is valid, try to get the function address.

    if (hinstLib != NULL) 
    { 
        ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts"); 

        // If the function address is valid, call the function.

        if (NULL != ProcAdd) 
        {
            fRunTimeLinkSuccess = TRUE;
            (ProcAdd) (L"Message sent to the DLL function\n"); 
        }
        // Free the DLL module.

        fFreeResult = FreeLibrary(hinstLib); 
    } 

    // If unable to call the DLL function, use an alternative.
    if (! fRunTimeLinkSuccess) 
        printf("Message printed from executable\n"); 

    return 0;

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11189447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档