使用CreateProcessAsUser,我可以调用硬盘上某处的.exe文件:
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中的函数。有没有人知道这是否可能?如果能举个例子就好了。
谢谢!
发布于 2012-06-25 21:20:06
您不能以不同的用户身份直接调用DLL,因为用户/执行级别是针对每个进程的,而不是针对DLL或线程的。必须启动一个新进程,然后调用DLL。这是COM elevation等使用的技术。如果DLL具有正确的签名,您可以尝试使用rundll32.exe调用它。
发布于 2012-06-25 20:44:15
我不认为使用该功能是可能的。在dll中调用方法的标准方式是使用LoadLibrary和GetProcAddress方法,如下例所示:
(摘自MSDN)
// 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;
}https://stackoverflow.com/questions/11189447
复制相似问题