質問

前述の私の問題は、こちらのドキュメンテーションは、プログラム(IHExplorer.exe私はwritting:

これはC ープに適用することができます

のIHExplorer用するのに、どのようにWindows Explorerにオーバーラッピングウィンドウが可能です。一つの例外は、やはり立ち上げからファイル内のこのクウィンドウを復号して初めて、ユーザーのtempフォルダに、そのアプリを起動し、ファイル拡張子を削除し、ファイルを閉じます。

の問題なんです、自動削除ファイルが閉じられます。このシナリオ:

  1. ユーザーのダブルクリックするだけでリンクは、暗号化して送信します。txtファイルIHExplorer.
  2. IHExplorer復号化ます。txtファイルをメモリに、書き込みま%温度を利用したい::、CreateFileを返す対応のファイル(IHExplorerって通行しなければなこの取扱い開放転できます。txtファイルはシェルの実行).

  3. IHExplorerシェルを実行します。txtファイルを呼び出し::ShellExecuteからで温ます。

  4. 今IHExplorer、メモ帳とハンドルのファイルが開きます。
  5. のファイルの自動削除がIHExplorer、メモ帳が閉その対応のファイルの場合でも、IHExplorerを閉じます。

ok。これはbasicalユーザーの場合ただきたいと思う。の問題にしていをするのがとても楽しみでした::ShellExecute()、メモ帳"とのアクセスできないファイルが利用されています。" (IHExplorer).さんがこのとしてメモ帳を開いてもらい、取り扱開IHExplorer.

ここでの私に電話で::、CreateFile次のように記述されています。

DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE;
HANDLE hFile = ::CreateFile(strTempFile.c_str(), GENERIC_WRITE, dwShareMode, &sa, CREATE_NEW, dwFlagsAndAttributes, NULL);

通知を使用したFILE_SHARE_DELETEすることにより、他のプロセス(メモ帳)を開き、ファイルを削除します。

通知そのものを使いFILE_ATTRIBUTE_TEMPORARY|FILE_FLAG_DELETE_ON_CLOSE属性indicicateのファイルはすべて削除される。

また通知にはsaパラメータとします。このSECURITY_ATTRIBUTES構造を私が使っていると思う(希望)ここで私の問題があると考えています。こちらのコードで、今回はポスト全体の機能がりを見て頂く事が出来かに記載のSECURITY_ATTRIBUTES構造:

int CIHExplorerDoc::OpenFile(std::string strFileName, bool bIsFullPath) {
    std::string strFullFilePath;
    if(bIsFullPath) {
        strFullFilePath = strFileName;
        strFileName = IHawk::RemovePath(strFileName);
    }else {
        strFullFilePath = m_strDirectory + strFileName;
    }

    if(!HasEncryptionFileExtension(strFullFilePath)) {
        LaunchFile(strFullFilePath);
    }else {
        //it's an encrypted file, so open it and copy unencrypted file to temp.
        IHawk::EncryptedFileHandle hEncryptedFile(strFullFilePath.c_str(), true, theApp.GetKeyServer());
        if(hEncryptedFile.IsValid()) {
            std::string strTempFile = g_strTempFolder + IHawk::ChangeFileExtension(strFileName, "");

            //TODO: Determine what the LPSECURITY_ATTRIBUTES should be.

            SECURITY_ATTRIBUTES sa;
            SECURITY_DESCRIPTOR sd;

            if(!InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION)) {
                DWORD dwLastError = ::GetLastError();
                LOG4CPLUS_ERROR(m_Logger, "Cannot launch file '" << strFullFilePath << "'.  Failed to initialize security descriptor.  GetLastError=" << dwLastError);
                return dwLastError;
            }

            if(!SetSecurityDescriptorDacl(
                &sd,    // A pointer to the SECURITY_DESCRIPTOR structure to which the function adds the DACL
                TRUE,   // presence of a DACL in the security descriptor
                NULL,   // allows all access to the object
                FALSE   // DACL has been explicitly specified by a user
            )) 
            {
                DWORD dwLastError = ::GetLastError();
                LOG4CPLUS_ERROR(m_Logger, "Cannot launch file '" << strFullFilePath << "'.  Failed to set security descriptor DACL.  GetLastError=" << dwLastError);
                return dwLastError;
            }

            if(!SetSecurityDescriptorGroup(
                &sd,    // A pointer to the SECURITY_DESCRIPTOR structure whose primary group is set by this function
                NULL,   // no primary group
                FALSE   // Indicates whether the primary group information was derived from a default mechanism
            ))
            {
                DWORD dwLastError = ::GetLastError();
                LOG4CPLUS_ERROR(m_Logger, "Cannot launch file '" << strFullFilePath << "'.  Failed to set security descriptor primary group.  GetLastError=" << dwLastError);
                return dwLastError;
            }

            if(!SetSecurityDescriptorOwner(
                &sd,    // A pointer to the SECURITY_DESCRIPTOR structure whose owner is set by this function.
                NULL,   // If this parameter is NULL, the function clears the security descriptor's owner information. This marks the security descriptor as having no owner.
                FALSE   // Indicates whether the owner information is derived from a default mechanism.
            ))
            {
                DWORD dwLastError = ::GetLastError();
                LOG4CPLUS_ERROR(m_Logger, "Cannot launch file '" << strFullFilePath << "'.  Failed to set security descriptor owner information.  GetLastError=" << dwLastError);
                return dwLastError;
            }

            if(!SetSecurityDescriptorSacl(
                &sd,    // A pointer to the SECURITY_DESCRIPTOR structure to which the function adds the SACL
                FALSE,  // the security descriptor does not contain a SACL
                NULL,   // security descriptor has a NULL SACL
                FALSE   // A pointer to a flag that is set to the value of the SE_SACL_DEFAULTED flag in the SECURITY_DESCRIPTOR_CONTROL structure if a SACL exists for the security descriptor
            ))
            {
                DWORD dwLastError = ::GetLastError();
                LOG4CPLUS_ERROR(m_Logger, "Cannot launch file '" << strFullFilePath << "'.  Failed to set security descriptor SACL.  GetLastError=" << dwLastError);
                return dwLastError;
            }

            sa.nLength = sizeof(SECURITY_ATTRIBUTES);
            sa.lpSecurityDescriptor = &sd;
            sa.bInheritHandle = TRUE;

            DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
//          DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
            DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE;
            HANDLE hFile = ::CreateFile(strTempFile.c_str(), GENERIC_WRITE, dwShareMode, &sa, CREATE_NEW, dwFlagsAndAttributes, NULL);

            //verify we created the file.
            if(hFile == INVALID_HANDLE_VALUE) {
                DWORD dwLastError = ::GetLastError();
                return dwLastError;
            }

            //copy to temp
            char buffer[64*1024];
            size_t nBytesRead = hEncryptedFile.Read(buffer, sizeof(buffer));
            while(nBytesRead) {
                DWORD numBytesWritten;
                if(!::WriteFile(hFile, buffer, nBytesRead, &numBytesWritten, (LPOVERLAPPED) NULL)) {
                    DWORD dwLastError = ::GetLastError();
                    LOG4CPLUS_ERROR(m_Logger, "Failed to write file to %TEMP% folder.  GetLastError=" << dwLastError);
                    return dwLastError;
                }
                nBytesRead = hEncryptedFile.Read(buffer, sizeof(buffer));
            }
            hEncryptedFile.Close();

            //execute the file from temp.
            LaunchFile(strTempFile);
        }
    }
    return 0;
}

と思いれば正しく設定するSECURITY_DESCRIPTOR渡::では、createfileる場合のようにしたいということです。を参考にしてください。

ちなみにLaunchFile機能だけなの呼び出し::ShellExecuteのファイルです。

役に立ちましたか?

解決

再読み込みにmsdn doc、恐怖いの答えは、自分の質問です。FILE_FLAG_DELETE_ON_CLOSEのファイルを削除する直後にそのすべてのハには、指定された取扱いその他の開または複製するためのリンクですがある場合は、既存の開取り扱うファイルに失敗しない限り、すべてのFILE_SHARE_DELETEシェアモードになります。その後の開放要求のためのファイルに失敗する場合を除き、FILE_SHARE_DELETE共有モードを指定します。私の場合、ものかどうか疑問を持つものメモ帳"に当FILE_SHARE_DELETE許可できないファイルを開く

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top