1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 #include "quickstarter.hxx"
4 #pragma warning(push, 1) /* disable warnings within system headers */
12 std::string
GetOfficeInstallationPath(MSIHANDLE handle
)
16 LPTSTR dummy
= TEXT("");
18 if (MsiGetProperty(handle
, TEXT("INSTALLLOCATION"), dummy
, &sz
) == ERROR_MORE_DATA
)
20 sz
++; // space for the final '\0'
21 DWORD nbytes
= sz
* sizeof(TCHAR
);
22 LPTSTR buff
= reinterpret_cast<LPTSTR
>(_alloca(nbytes
));
23 ZeroMemory(buff
, nbytes
);
24 MsiGetProperty(handle
, TEXT("INSTALLLOCATION"), buff
, &sz
);
30 std::string
GetOfficeProductName(MSIHANDLE handle
)
32 std::string productname
;
34 LPTSTR dummy
= TEXT("");
36 if (MsiGetProperty(handle
, TEXT("ProductName"), dummy
, &sz
) == ERROR_MORE_DATA
)
38 sz
++; // space for the final '\0'
39 DWORD nbytes
= sz
* sizeof(TCHAR
);
40 LPTSTR buff
= reinterpret_cast<LPTSTR
>(_alloca(nbytes
));
41 ZeroMemory(buff
, nbytes
);
42 MsiGetProperty(handle
, TEXT("ProductName"), buff
, &sz
);
48 std::string
GetQuickstarterLinkName(MSIHANDLE handle
)
50 std::string quickstarterlinkname
;
52 LPTSTR dummy
= TEXT("");
54 if (MsiGetProperty(handle
, TEXT("Quickstarterlinkname"), dummy
, &sz
) == ERROR_MORE_DATA
)
56 sz
++; // space for the final '\0'
57 DWORD nbytes
= sz
* sizeof(TCHAR
);
58 LPTSTR buff
= reinterpret_cast<LPTSTR
>(_alloca(nbytes
));
59 ZeroMemory(buff
, nbytes
);
60 MsiGetProperty(handle
, TEXT("Quickstarterlinkname"), buff
, &sz
);
61 quickstarterlinkname
= buff
;
63 else if (MsiGetProperty(handle
, TEXT("ProductName"), dummy
, &sz
) == ERROR_MORE_DATA
)
65 sz
++; // space for the final '\0'
66 DWORD nbytes
= sz
* sizeof(TCHAR
);
67 LPTSTR buff
= reinterpret_cast<LPTSTR
>(_alloca(nbytes
));
68 ZeroMemory(buff
, nbytes
);
69 MsiGetProperty(handle
, TEXT("ProductName"), buff
, &sz
);
70 quickstarterlinkname
= buff
;
72 return quickstarterlinkname
;
75 inline bool IsValidHandle( HANDLE handle
)
77 return NULL
!= handle
&& INVALID_HANDLE_VALUE
!= handle
;
80 static DWORD WINAPI
_GetModuleFileNameExA( HANDLE hProcess
, HMODULE hModule
, LPSTR lpFileName
, DWORD nSize
)
82 typedef DWORD (WINAPI
*FN_PROC
)( HANDLE hProcess
, HMODULE hModule
, LPSTR lpFileName
, DWORD nSize
);
84 static FN_PROC lpProc
= NULL
;
88 HMODULE hLibrary
= LoadLibrary("PSAPI.DLL");
91 lpProc
= reinterpret_cast< FN_PROC
>(GetProcAddress( hLibrary
, "GetModuleFileNameExA" ));
95 return lpProc( hProcess
, hModule
, lpFileName
, nSize
);
101 std::string
GetProcessImagePath( DWORD dwProcessId
)
103 std::string sImagePath
;
105 HANDLE hProcess
= OpenProcess( PROCESS_QUERY_INFORMATION
| PROCESS_VM_READ
, FALSE
, dwProcessId
);
107 if ( IsValidHandle( hProcess
) )
109 CHAR szPathBuffer
[MAX_PATH
] = "";
111 if ( _GetModuleFileNameExA( hProcess
, NULL
, szPathBuffer
, sizeof(szPathBuffer
) ) )
112 sImagePath
= szPathBuffer
;
114 CloseHandle( hProcess
);
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */