6

I have written a database app that imports data from an excel file into a Access database.

I have never had trouble to run the app, to insert records into the database, but as soon as I run the function to import data from the Excel into the Access I get the following warning:

The requested operation requires elevation - by die code:

LAccess := CreateOleObject('Access.Application');

What is causing this and is there a way to get around it

4

1 回答 1

8

CreateOleObjectdelphi 函数内部调用需要提升的CoCreateInstance WinApi方法。你有几个选择来处理这个问题。

1) 向您的应用添加清单,包括请求的执行级别 requireAdministrator

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    name="Your app name goes here"
    processorArchitecture="x86"
    version="5.1.0.0"
    type="win32"/>
<description>your app description goes here</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
           type="win32"
           name="Microsoft.Windows.Common-Controls"
           version="6.0.0.0"
           processorArchitecture="x86"
           publicKeyToken="6595b64144ccf1df"
           language="*"
        />
     </dependentAssembly>
  </dependency>
   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
      <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
      </requestedPrivileges>
    </security>
   </trustInfo>
</assembly>

2) 您可以启动一个提升的辅助进程来执行该任务或创建一个运行提升的 COM 对象,您可以在这些 MSDN 条目中找到更多信息

于 2012-05-06T22:10:44.647 回答