English 中文(简体)
出口 受联合国保护的纸张驱动器的差错?
原标题:ShellExecuteEx error on a write protected USB drive?

我试图测试关于纸张保护金星的申请书,我想使用壳牌ExecuteEx AP(我需要使用该份标语,因为我需要LpVerb:=“runas”)呼吁执行第二个方案,但我仍要用壳牌ExecuteEx电话获得“Write Protect Error”。 http://www.microsoft.com/downloads/D3.pdf 这里是我留下的错误:

<>> 书面保护

“Write

以下法典中的任何规定都试图写到这一运动中,就是壳牌。 排他性反应会给我错想做什么呢? 否则,我如何能够从偷窃中找到这一错误。 任何帮助都将受到高度赞赏。

<>strong>[WP-ON.reg]

REGEDIT4

[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlStorageDevicePolicies]
"WriteProtect"=dword:00000001

<>strong>[WP-OFF.reg]

REGEDIT4

[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlStorageDevicePolicies]
"WriteProtect"=dword:00000000

<>光> 每次更新登记册时,你必须照搬和重新安装。

<>strong>[项目1.dpr]

program project1;

{.$APPTYPE CONSOLE}

uses
  Windows, SysUtils;

begin
  Windows.MessageBox(Windows.GetActiveWindow(),
    PChar( Hello World! ), PChar( project1 ), MB_OK);
end.

[ launch.manifest ]

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

<>strong>[发射]

program launch;

uses
  Windows, ShellAPI;

{$R  MANIFEST.RES }

procedure ShellEx(const theFilename, theParams: string);

  function RunAsAdmin(): Boolean;
  var
    OSVerInfo: TOSVersionInfo;
  begin
    OSVerInfo.dwOSVersionInfoSize := System.SizeOf(OSVerInfo);
    Result := (Windows.GetVersionEx(OSVerInfo)) and (OSVerInfo.dwMajorVersion > 5);
  end;

var
  ShellExInfo: TShellExecuteInfo;
  Directory: array[0..MAX_PATH] of Char;
begin
  Windows.ZeroMemory(@ShellExInfo, System.SizeOf(ShellExInfo));
  ShellExInfo.cbSize := System.SizeOf(TShellExecuteInfo);
  ShellExInfo.Wnd := Windows.GetActiveWindow();
  ShellExInfo.nShow := SW_SHOWNORMAL;
  ShellExInfo.fMask := SEE_MASK_FLAG_NO_UI;

  if (RunAsAdmin()) then  // If OS is greater than Windows XP
    ShellExInfo.lpVerb := PChar( runas );

  Windows.ZeroMemory(@Directory, System.SizeOf(Directory));
  Windows.GetCurrentDirectory(SizeOf(Directory), Directory);
  ShellExInfo.lpDirectory := PChar(string(Directory));
  ShellExInfo.lpFile := PChar( "  + string(Directory) +    + theFilename +  " );
  ShellExInfo.lpParameters := PChar( "  + theParams +  " );

  //
  // ShellExecuteEx causes a "Write Protect" error to popup.
  //
  if (not ShellAPI.ShellExecuteEx(@ShellExInfo)) then
    Windows.MessageBox(Windows.GetActiveWindow(),
      PChar( File   + ShellExInfo.lpFile +   not found! ),
      PChar( asInvoker Launch ), MB_OK or MB_ICONERROR);
end;

begin
  ShellEx( project1.exe , System.ParamStr(1));

end.
最佳回答

The issue comes from the fact ShellExecuteEx is quite a complex process, starting a new background thread, then calling a lot of COM stuff. Write should be enabled somewhere, for security reasons.

你可能会试图使欧盟理事会解体。 但这不是一个好的解决方案。

When you look at the corresponding solutions to elevate a process rights programatically (wired manifest is another static way of elevation), you can only find the two quoted in this SO answer:

  • Use ShellExecuteEx with runas parameter;
  • Create an elevated COM Object with the magic "Elevation:Administrator!new:" prefix.

http://www.codeproject.com/KB/vista-security/UAC_The_Definitive_Guide.aspx”rel=“nofollow noreferer”ista UAC: The Definitive Guide” article to Understanding how ShellExecuteEx work.

因此,我的答复是:由于你需要运行一个高权利的程序,而且没有现有的“CreateProcess Elevated”的APIC,但只有一个好的大的ShellExecute,最容易的是使用第2号可执行文件。

如果您希望获得项目1.exe文档,以“AsInvoker”权利为标题,但只有行政权,你有两种可能性:

  • Use an external .manifest file, and do not embed the file to the exe as a resource - then replace the .manifest content with one version with either "AsInvoker" or "requireAdministrator" parameter - but difficult on a read-only media, isn t it :;
  • Use an external 3nd executable (we ll call it Elevate.exe), containing a manifest with the "requireAdministrator" level, which will launch the 2nd executable. You could provide the exe and command line as a parameter to this Elevate.exe program.
问题回答

暂无回答




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签