VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxService/VBoxVMInfoAdditions.cpp@ 13351

最後變更 在這個檔案從13351是 11982,由 vboxsync 提交於 16 年 前

All: license header changes for 2.0 (OSE headers, add Sun GPL/LGPL disclaimer)

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 4.0 KB
 
1/* $Id: VBoxVMInfoAdditions.cpp 11982 2008-09-02 13:09:44Z vboxsync $ */
2/** @file
3 * VBoxVMInfoAdditions - Guest Additions information for the host.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * Sun Microsystems, Inc. confidential
10 * All rights reserved
11 */
12
13#include "VBoxService.h"
14#include "VBoxUtils.h"
15#include "VBoxVMInfo.h"
16#include "VBoxVMInfoAdditions.h"
17
18int getAddVersion(VBOXINFORMATIONCONTEXT* a_pCtx)
19{
20 Assert(a_pCtx);
21 if (FALSE == a_pCtx->fFirstRun) /* Only do this at the initial run. */
22 return 0;
23
24 char szInstDir[_MAX_PATH] = {0};
25 char szRev[_MAX_PATH] = {0};
26 char szVer[_MAX_PATH] = {0};
27
28 HKEY hKey = NULL;
29 int rc = 0;
30 DWORD dwSize = 0;
31
32 rc = RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
33 if ((rc != ERROR_SUCCESS ) && (rc != ERROR_FILE_NOT_FOUND))
34 {
35 Log(("vboxVMInfoThread: Failed to open registry key! Error: %d\n", GetLastError()));
36 return 1;
37 }
38
39 /* Installation directory. */
40 dwSize = sizeof(szInstDir);
41 rc = RegQueryValueExA (hKey, "InstallDir", 0, 0, (BYTE*)(LPCTSTR)szInstDir, &dwSize);
42 if ((rc != ERROR_SUCCESS ) && (rc != ERROR_FILE_NOT_FOUND))
43 {
44 RegCloseKey (hKey);
45 Log(("vboxVMInfoThread: Failed to query registry key! Error: %d\n", GetLastError()));
46 return 1;
47 }
48
49 /* Flip slashes. */
50 for (char* pszTmp = &szInstDir[0]; *pszTmp; ++pszTmp)
51 if (*pszTmp == '\\')
52 *pszTmp = '/';
53
54 /* Revision. */
55 dwSize = sizeof(szRev);
56 rc = RegQueryValueExA (hKey, "Revision", 0, 0, (BYTE*)(LPCTSTR)szRev, &dwSize);
57 if ((rc != ERROR_SUCCESS ) && (rc != ERROR_FILE_NOT_FOUND))
58 {
59 RegCloseKey (hKey);
60 Log(("vboxVMInfoThread: Failed to query registry key! Error: %d\n", GetLastError()));
61 return 1;
62 }
63
64 /* Version. */
65 dwSize = sizeof(szVer);
66 rc = RegQueryValueExA (hKey, "Version", 0, 0, (BYTE*)(LPCTSTR)szVer, &dwSize);
67 if ((rc != ERROR_SUCCESS ) && (rc != ERROR_FILE_NOT_FOUND))
68 {
69 RegCloseKey (hKey);
70 LogRel(("vboxVMInfoThread: Failed to query registry key! Error: %Rrc\n", GetLastError()));
71 return 1;
72 }
73
74 /* Write information to host. */
75 vboxVMInfoWriteProp(a_pCtx, "GuestAdd/InstallDir", szInstDir);
76 vboxVMInfoWriteProp(a_pCtx, "GuestAdd/Revision", szRev);
77 vboxVMInfoWriteProp(a_pCtx, "GuestAdd/Version", szVer);
78
79 RegCloseKey (hKey);
80
81 return 0;
82}
83
84int getComponentVersions(VBOXINFORMATIONCONTEXT* a_pCtx)
85{
86 Assert(a_pCtx);
87 if (FALSE == a_pCtx->fFirstRun) /* Only do this at the initial run. */
88 return 0;
89
90 char szVer[_MAX_PATH] = {0};
91 char szPropPath[_MAX_PATH] = {0};
92 TCHAR szSysDir[_MAX_PATH] = {0};
93 TCHAR szWinDir[_MAX_PATH] = {0};
94 TCHAR szDriversDir[_MAX_PATH + 32] = {0};
95
96 GetSystemDirectory(szSysDir, _MAX_PATH);
97 GetWindowsDirectory(szWinDir, _MAX_PATH);
98 swprintf(szDriversDir, (_MAX_PATH + 32), TEXT("%s\\drivers"), szSysDir);
99
100 /* The file information table. */
101 VBOXFILEINFO vboxFileInfoTable[] =
102 {
103 { szSysDir, TEXT("VBoxControl.exe"), },
104 { szSysDir, TEXT("VBoxHook.dll"), },
105 { szSysDir, TEXT("VBoxDisp.dll"), },
106 { szSysDir, TEXT("VBoxMRXNP.dll"), },
107 { szSysDir, TEXT("VBoxService.exe"), },
108 { szSysDir, TEXT("VBoxTray.exe"), },
109
110 { szDriversDir, TEXT("VBoxGuest.sys"), },
111 { szDriversDir, TEXT("VBoxMouse.sys"), },
112 { szDriversDir, TEXT("VBoxSF.sys"), },
113 { szDriversDir, TEXT("VBoxVideo.sys"), },
114
115 {
116 NULL
117 }
118 };
119
120 VBOXFILEINFO* pTable = vboxFileInfoTable;
121 Assert(pTable);
122 while (pTable->pszFileName)
123 {
124 vboxGetFileVersionString(pTable->pszFilePath, pTable->pszFileName, szVer, sizeof(szVer));
125 RTStrPrintf(szPropPath, sizeof(szPropPath), "GuestAdd/Components/%ls", pTable->pszFileName);
126 vboxVMInfoWriteProp(a_pCtx, szPropPath, szVer);
127 pTable++;
128 }
129
130 return 0;
131}
132
133int vboxVMInfoAdditions(VBOXINFORMATIONCONTEXT* a_pCtx)
134{
135 Assert(a_pCtx);
136
137 getAddVersion(a_pCtx);
138 getComponentVersions(a_pCtx);
139
140 return 0;
141}
142
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette