English 中文(简体)
为什么要 有时没有完成行动?
原标题:Why does ShellExecuteA sometimes not complete an action?
  • 时间:2024-05-13 17:53:00
  •  标签:
  • c++
  • winapi

I m using RAD Studio C++ Builder. I am not yet using their clang compiler (long story), so my code cannot use C++17 functions. (Since this is a standard VCL application, I believe CoInitialize is run automatically)

I m trying to make a shortcut (button) to open "Internet Information Services (IIS) Manager", from within one of my applications. I m using some code that s been working to do open applications for years, however, it s not working with :

  • %windir%system32inetsrvInetMgr.exe (this is taken from The administrative tools shortcut)
  • C:WINDOWSsystem32inetsrvInetMgr.exe (same thing without variables)

I have checked and the File does exist.
This is the code I m using:

void __fastcall TLaunch::OpenApplication ( const AnsiString& Location 
                                         , const AnsiString& FileName
                                         )
{
    HWND       hwnd         = NULL;
    LPCSTR     lpOperation  = "open";
    LPCSTR     lpFile       = FileName.c_str();   
    LPCSTR     lpParameters = "";
    LPCSTR     lpDirectory  = Location.c_str();   
    INT        nShowCmd     = SW_SHOWNORMAL;   
    HINSTANCE AppHandle = ShellExecuteA ( hwnd
                                        , lpOperation
                                        , lpFile
                                        , lpParameters
                                        , lpDirectory
                                        , nShowCmd
                                        );
}

// This Does nothing
OpenApplication ( "C:Windowssystem32inetsrv" 
                , "InetMgr.exe" 
                );
// This also Does nothing (the Administrative tools shortcut does not specify a "Start In")
OpenApplication ( "" 
                , "C:Windowssystem32inetsrvInetMgr.exe" 
                );

When I looked at the Administrative tools shortcut to get the file details the target did not include any quotes or Parameters, so I ve not included any within my call.
I also tried running C:WINDOWSsystem32inetsrvInetMgr.exe manually from a CMD opened without Admin rights. The app was displayed, so I shouldn t need to use "runas". I m therefore a bit confused as to why this does not work through ShellExecuteA. (Like I said, this code happily opens other applications).

Can anyone shed some light on what I m doing wrong?
or why this App behaves differently from everything else I ask ShellExecuteA to open?

Perhaps??? this might be related to why I had problems signing my apps using ShellExecuteA?
Opening the App is my question , this is just something that might be related. If I use signtool.exe installed from the MS Windows 10 SDK to sign my applications, I have to use a command line script similar to the one below

 "C:Program Files (x86)Windows Kits10App Certification Kitsigntool.exe" sign /a /f "C:Development( RESOURCE )\_CertsV12.pfx" /p "PasswordExample" /d "Company Name : App" /tr "http://timestamp.digicert.com" /td sha256 /fd sha256 /v "R:(Distribute)V12.1.1 [24-05](2024-05-03)ACMS V1211.2405 (x86-Distro)MyApp.exe" 

However, if I run this using ShellExecuteA no digital signature gets assigned to my applications. If I instead save the (exact) text I sent to ShellExecuteA to a batch file and run it manually, no errors are received and the the app ends up with a digital signature. I m baffled.com
(I deleted my attempts at the ShellExecute code signing thing ages ago so I can t provide any broken examples)

Any help you can provide will be gratefully received. Cheers :)

问题回答

I cannot reproduce with some changes to your code.

#include <Windows.h>

void OpenApplication(const char* Location
    , const char* FileName
)
{
    HWND       hwnd = NULL;
    LPCSTR     lpOperation = "open";
    LPCSTR     lpFile = FileName;
    LPCSTR     lpParameters = "";
    LPCSTR     lpDirectory = Location;
    INT        nShowCmd = SW_SHOWNORMAL;
    HINSTANCE AppHandle = ShellExecuteA(hwnd
        , lpOperation
        , lpFile
        , lpParameters
        , lpDirectory
        , nShowCmd
    );
}


int main()
{
    OpenApplication("C:\Windows\system32\inetsrv\" 
        , "InetMgr.exe"
    );

    OpenApplication(""
        , "C:\Windows\system32\inetsrv\InetMgr.exe"
    );
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签