1 #include "quickstarter.hxx"
3 #pragma warning(push, 1) /* disable warnings within system headers */
12 std::string
GetOfficeInstallationPath(MSIHANDLE handle
)
16 LPTSTR dummy
= TEXT("");
18 if (MsiGetProperty(handle
, TEXT("OFFICEINSTALLLOCATION"), 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("OFFICEINSTALLLOCATION"), 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
;
81 static HANDLE WINAPI
_CreateToolhelp32Snapshot( DWORD dwFlags
, DWORD th32ProcessID
)
83 typedef HANDLE (WINAPI
*FN_PROC
)( DWORD dwFlags
, DWORD th32ProcessID
);
84 static FN_PROC lpProc
= NULL
;
86 HANDLE hSnapshot
= NULL
;
90 HMODULE hLibrary
= GetModuleHandle("KERNEL32.DLL");
93 lpProc
= reinterpret_cast< FN_PROC
>(GetProcAddress( hLibrary
, "CreateToolhelp32Snapshot" ));
97 hSnapshot
= lpProc( dwFlags
, th32ProcessID
);
102 static BOOL WINAPI
_Process32First( HANDLE hSnapshot
, PROCESSENTRY32
*lppe32
)
104 typedef BOOL (WINAPI
*FN_PROC
)( HANDLE hSnapshot
, PROCESSENTRY32
*lppe32
);
105 static FN_PROC lpProc
= NULL
;
107 BOOL fSuccess
= FALSE
;
111 HMODULE hLibrary
= GetModuleHandle("KERNEL32.DLL");
114 lpProc
= reinterpret_cast< FN_PROC
>(GetProcAddress( hLibrary
, "Process32First" ));
118 fSuccess
= lpProc( hSnapshot
, lppe32
);
123 static BOOL WINAPI
_Process32Next( HANDLE hSnapshot
, PROCESSENTRY32
*lppe32
)
125 typedef BOOL (WINAPI
*FN_PROC
)( HANDLE hSnapshot
, PROCESSENTRY32
*lppe32
);
126 static FN_PROC lpProc
= NULL
;
128 BOOL fSuccess
= FALSE
;
132 HMODULE hLibrary
= GetModuleHandle("KERNEL32.DLL");
135 lpProc
= reinterpret_cast< FN_PROC
>(GetProcAddress( hLibrary
, "Process32Next" ));
139 fSuccess
= lpProc( hSnapshot
, lppe32
);
144 static std::string
GetProcessImagePath_9x( DWORD dwProcessId
)
146 std::string sImagePath
;
148 HANDLE hSnapshot
= _CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS
, 0 );
150 if ( IsValidHandle( hSnapshot
) )
152 PROCESSENTRY32 pe32
= { 0 };
154 pe32
.dwSize
= sizeof(PROCESSENTRY32
);
156 BOOL fSuccess
= _Process32First( hSnapshot
, &pe32
);
159 while ( !found
&& fSuccess
)
161 if ( pe32
.th32ProcessID
== dwProcessId
)
164 sImagePath
= pe32
.szExeFile
;
168 fSuccess
= _Process32Next( hSnapshot
, &pe32
);
171 CloseHandle( hSnapshot
);
177 static DWORD WINAPI
_GetModuleFileNameExA( HANDLE hProcess
, HMODULE hModule
, LPSTR lpFileName
, DWORD nSize
)
179 typedef DWORD (WINAPI
*FN_PROC
)( HANDLE hProcess
, HMODULE hModule
, LPSTR lpFileName
, DWORD nSize
);
181 static FN_PROC lpProc
= NULL
;
185 HMODULE hLibrary
= LoadLibrary("PSAPI.DLL");
188 lpProc
= reinterpret_cast< FN_PROC
>(GetProcAddress( hLibrary
, "GetModuleFileNameExA" ));
192 return lpProc( hProcess
, hModule
, lpFileName
, nSize
);
198 static std::string
GetProcessImagePath_NT( DWORD dwProcessId
)
200 std::string sImagePath
;
202 HANDLE hProcess
= OpenProcess( PROCESS_QUERY_INFORMATION
| PROCESS_VM_READ
, FALSE
, dwProcessId
);
204 if ( IsValidHandle( hProcess
) )
206 CHAR szPathBuffer
[MAX_PATH
] = "";
208 if ( _GetModuleFileNameExA( hProcess
, NULL
, szPathBuffer
, sizeof(szPathBuffer
) ) )
209 sImagePath
= szPathBuffer
;
211 CloseHandle( hProcess
);
217 std::string
GetProcessImagePath( DWORD dwProcessId
)
219 return (LONG
)GetVersion() < 0 ? GetProcessImagePath_9x( dwProcessId
) : GetProcessImagePath_NT( dwProcessId
);