我想构建一棵树,按照开始菜单里程序那样,列出所有可执行文件来。请问有什么方法可以做到?还有,如何获得所有系统服务进程呢?是不是在注册表中?谢谢!

解决方案 »

  1.   

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartMenu下所有键值和
    nt以上系统在:
    系统所在盘:\Documents and Settings\All Users\Start Menu
    系统所在盘:\Documents and Settings\你的用户名\Start Menu这个文件夹下的所有文件和子文件
      

  2.   

    获得所有系统服务进程使用列举服务,EnumServicesStatus,
    QueryServiceConfig可以查询出指定服务的进程路径.
    ------------------------------------------------------------
    按照开始菜单里程序那样,列出所有可执行文件来:
    可以先SHGetSpecialFolderPath得到开始菜单的目录,列举出其中的所有shortcut,然后使用下列方法得到路径:
    HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath) 

        HRESULT hres; 
        IShellLink* psl; 
        char szGotPath[MAX_PATH]; 
        char szDescription[MAX_PATH]; 
        WIN32_FIND_DATA wfd; 
     
        *lpszPath = 0; // assume failure 
     
        // Get a pointer to the IShellLink interface. 
        hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, 
                                IID_IShellLink, (LPVOID*)&psl); 
        if (SUCCEEDED(hres)) 
        { 
            IPersistFile* ppf; 
     
            // Get a pointer to the IPersistFile interface. 
            hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf); 

            if (SUCCEEDED(hres)) 
            { 
                WCHAR wsz[MAX_PATH]; 
     
                // Ensure that the string is Unicode. 
                MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH); 
     
                // TODO: Check return value from MultiByteWideChar to ensure 
                         success.
     
                // Load the shortcut. 
                hres = ppf->Load(wsz, STGM_READ); 
                
                if (SUCCEEDED(hres)) 
                { 
                    // Resolve the link. 
                    hres = psl->Resolve(hwnd, 0);                 if (SUCCEEDED(hres)) 
                    { 
                        // Get the path to the link target. 
                        hres = psl->GetPath(szGotPath, 
                                            MAX_PATH, 
                                            (WIN32_FIND_DATA*)&wfd, 
                                            SLGP_SHORTPATH);                     if (SUCCEEDED(hres)) 
                        { 
                            // Get the description of the target. 
                            hres = psl->GetDescription(szDescription, MAX_PATH);                         if (SUCCEEDED(hres)) 
                            {
                                hres = StringCbCopy(lpszPath, sizeof(lpszPath), 
                                                    szGotPath);
                                if (SUCCEEDED(hres))
                                {
                                    // Handle success
                                }
                                else
                                    // application-defined function
                                    HandleErr(hres); 
                            }
                        }
                    } 
                }             // Release the pointer to the IPersistFile interface. 
                ppf->Release(); 
            }         // Release the pointer to the IShellLink interface. 
            psl->Release(); 
        } 
        return hres; 
    }
      

  3.   

    谢谢wangk(倒之),我想问一下“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartMenu下所有键值”是什么意思?我看了一下,这下面的键值好像都没有什么用。我找到一个函数,SHGetSpecialFolderPath,用这个应该可以获得当前用户开始菜单的位置。是不是除了读快捷方式,没有其他方法了呢?那快捷方式怎么读?
      

  4.   

    谢谢idAnts(你才无聊呢),我去试试,回来结贴。
      

  5.   

    这个函数是从msdn里扒下来的,你用的时候要在开头加上CoInitialize(NULL);
    结束加上CoUninitialize();
      

  6.   

    键值描述的是特殊菜单,比如help,管理工具等。
    idAnts(你才无聊呢) 的方法应该是可行的。
      

  7.   

    这个问题以前有人讨论过,可以参考一下
    http://community.csdn.net/Expert/topic/3765/3765897.xml?temp=.4314081
      

  8.   

    谢谢大家,我也查到好多关于快捷方式操作的贴子,有的我看了:)那除了快捷方式以外,还有没有其他方法呢?我问的第二问题除了用EnumServicesStatus,有没有在注册表中有记录呢?
      

  9.   

    放在这个下面:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services但是这么做没那个科学。
      

  10.   

    呵呵,我看了一下,好像更麻烦:)谢谢idAnts(你才无聊呢),这贴我结了,有问题再来问!