Skip to content

Commit b8b9d10

Browse files
committed
test
1 parent 61e3a08 commit b8b9d10

2 files changed

Lines changed: 87 additions & 86 deletions

File tree

ci/installer/ODBCDriverForBigQuery/Assets/delete_dsns_all_users.ps1

Lines changed: 78 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,110 @@
11
param (
2-
[string]$DriverName = "ODBC Driver for BigQuery",
2+
[string]$BaseDriverName = "ODBC Driver for BigQuery",
33
[string[]]$SystemDsnRoots = @(
44
"Registry::HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI",
55
"Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBC.INI"
66
),
77
[string]$Platform = ""
88
)
99

10-
$shouldDeleteUserDSNs = $true
11-
if ($Platform -eq "x64" -and (Test-Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI\$DriverName")) {
12-
$shouldDeleteUserDSNs = $false
13-
} elseif (($Platform -eq "x86" -or $Platform -eq "x32" -or $Platform -eq "") -and (Test-Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\$DriverName")) {
14-
$shouldDeleteUserDSNs = $false
10+
if ($Platform -eq "x64") {
11+
$DriverName = "$BaseDriverName (64-bit)"
12+
} elseif ($Platform -eq "x86" -or $Platform -eq "x32" -or $Platform -eq "") {
13+
$DriverName = "$BaseDriverName (32-bit)"
14+
} else {
15+
$DriverName = $BaseDriverName
1516
}
1617

17-
if ($shouldDeleteUserDSNs) {
18-
# Get all user SIDs under HKEY_USERS, excluding system _Classes keys
19-
$all_sids = Get-ChildItem "Registry::HKEY_USERS" | Where-Object {
20-
$_.Name -notmatch "_Classes$"
21-
}
18+
# Get all user SIDs under HKEY_USERS, excluding system _Classes keys
19+
$all_sids = Get-ChildItem "Registry::HKEY_USERS" | Where-Object {
20+
$_.Name -notmatch "_Classes$"
21+
}
22+
23+
foreach ($sid_entry in $all_sids) {
24+
$sid = ($sid_entry.Name -split '\\')[-1] # Extract SID
25+
26+
$dsn_path_root = "Registry::HKEY_USERS\$sid\Software\ODBC\ODBC.INI"
27+
$odbc_sources_path = "$dsn_path_root\ODBC Data Sources"
28+
29+
if (Test-Path $odbc_sources_path) {
30+
try {
31+
$dsns = Get-ItemProperty -Path $odbc_sources_path
32+
foreach ($property in $dsns.PSObject.Properties) {
33+
$name = $property.Name
34+
if ($name -notmatch "^PS.*") {
35+
$driver = $property.Value
2236

23-
foreach ($sid_entry in $all_sids) {
24-
$sid = ($sid_entry.Name -split '\\')[-1] # Extract SID
25-
26-
$dsn_path_root = "Registry::HKEY_USERS\$sid\Software\ODBC\ODBC.INI"
27-
$odbc_sources_path = "$dsn_path_root\ODBC Data Sources"
28-
29-
if (Test-Path $odbc_sources_path) {
30-
try {
31-
$dsns = Get-ItemProperty -Path $odbc_sources_path
32-
foreach ($property in $dsns.PSObject.Properties) {
33-
$name = $property.Name
34-
if ($name -notmatch "^PS.*") {
35-
$driver = $property.Value
36-
37-
if ($driver -eq $DriverName) {
38-
# Delete DSN-specific registry entries
39-
Remove-Item -Path "$dsn_path_root\$name" -Recurse -Force -ErrorAction SilentlyContinue
40-
Remove-ItemProperty -Path $odbc_sources_path -Name $name -ErrorAction SilentlyContinue
41-
}
37+
if ($driver -eq $DriverName) {
38+
# Delete DSN-specific registry entries
39+
Remove-Item -Path "$dsn_path_root\$name" -Recurse -Force -ErrorAction SilentlyContinue
40+
Remove-ItemProperty -Path $odbc_sources_path -Name $name -ErrorAction SilentlyContinue
4241
}
4342
}
44-
} catch {
4543
}
44+
} catch {
4645
}
4746
}
47+
}
4848

49-
function Load_UserHive {
50-
param (
51-
[string]$Sid,
52-
[string]$UserProfilePath
53-
)
54-
$ntuser_dat = Join-Path $UserProfilePath "NTUSER.DAT"
55-
if (Test-Path $ntuser_dat) {
56-
reg load "HKU\$Sid" "$ntuser_dat" | Out-Null
57-
}
49+
function Load_UserHive {
50+
param (
51+
[string]$Sid,
52+
[string]$UserProfilePath
53+
)
54+
$ntuser_dat = Join-Path $UserProfilePath "NTUSER.DAT"
55+
if (Test-Path $ntuser_dat) {
56+
reg load "HKU\$Sid" "$ntuser_dat" | Out-Null
5857
}
58+
}
5959

60-
function Unload_UserHive {
61-
param (
62-
[string]$Sid
63-
)
64-
reg unload "HKU\$Sid" | Out-Null
65-
}
60+
function Unload_UserHive {
61+
param (
62+
[string]$Sid
63+
)
64+
reg unload "HKU\$Sid" | Out-Null
65+
}
6666

67-
# User DSNs (HKU)
68-
$hku_path = "Registry::HKEY_USERS"
69-
$sids = Get-ChildItem -Path $hku_path | Where-Object { $_.Name -notmatch "_Classes$" }
67+
# User DSNs (HKU)
68+
$hku_path = "Registry::HKEY_USERS"
69+
$sids = Get-ChildItem -Path $hku_path | Where-Object { $_.Name -notmatch "_Classes$" }
7070

71-
# Supplement with user profiles
72-
$user_profiles = Get-ChildItem "C:\Users" | Where-Object {
73-
Test-Path "$($_.FullName)\NTUSER.DAT"
74-
}
71+
# Supplement with user profiles
72+
$user_profiles = Get-ChildItem "C:\Users" | Where-Object {
73+
Test-Path "$($_.FullName)\NTUSER.DAT"
74+
}
7575

76-
foreach ($user in $user_profiles) {
77-
$user_path = $user.FullName
78-
$user_sid = (Get-CimInstance -Class Win32_UserAccount | Where-Object { $_.Name -eq $user.Name }).SID
79-
if ($user_sid -and -not ($sids.Name -match [regex]::Escape($user_sid))) {
80-
if (Load_UserHive -Sid $user_sid -UserProfilePath $user_path) {
81-
$sids += Get-Item "Registry::HKEY_USERS\$user_sid"
82-
}
76+
foreach ($user in $user_profiles) {
77+
$user_path = $user.FullName
78+
$user_sid = (Get-CimInstance -Class Win32_UserAccount | Where-Object { $_.Name -eq $user.Name }).SID
79+
if ($user_sid -and -not ($sids.Name -match [regex]::Escape($user_sid))) {
80+
if (Load_UserHive -Sid $user_sid -UserProfilePath $user_path) {
81+
$sids += Get-Item "Registry::HKEY_USERS\$user_sid"
8382
}
8483
}
84+
}
8585

86-
foreach ($sid in $sids) {
87-
$sid_name = $sid.PSChildName
88-
$user_dsn_root = "Registry::HKEY_USERS\$sid_name\Software\ODBC\ODBC.INI"
89-
$odbc_sources_path = "$user_dsn_root\ODBC Data Sources"
86+
foreach ($sid in $sids) {
87+
$sid_name = $sid.PSChildName
88+
$user_dsn_root = "Registry::HKEY_USERS\$sid_name\Software\ODBC\ODBC.INI"
89+
$odbc_sources_path = "$user_dsn_root\ODBC Data Sources"
9090

91-
if (Test-Path $odbc_sources_path) {
92-
$sources_key = Get-Item -Path $odbc_sources_path
93-
$sources = $sources_key.GetValueNames()
94-
} else {
95-
continue
96-
}
91+
if (Test-Path $odbc_sources_path) {
92+
$sources_key = Get-Item -Path $odbc_sources_path
93+
$sources = $sources_key.GetValueNames()
94+
} else {
95+
continue
96+
}
9797

98-
foreach ($dsn in $sources) {
99-
$driver = $sources_key.GetValue($dsn)
100-
if ($driver -eq $DriverName) {
101-
Remove-Item -Path "$user_dsn_root\$dsn" -Recurse -Force -ErrorAction SilentlyContinue
102-
Remove-ItemProperty -Path $odbc_sources_path -Name $dsn -ErrorAction SilentlyContinue
103-
}
98+
foreach ($dsn in $sources) {
99+
$driver = $sources_key.GetValue($dsn)
100+
if ($driver -eq $DriverName) {
101+
Remove-Item -Path "$user_dsn_root\$dsn" -Recurse -Force -ErrorAction SilentlyContinue
102+
Remove-ItemProperty -Path $odbc_sources_path -Name $dsn -ErrorAction SilentlyContinue
104103
}
104+
}
105105

106-
if ($user_profiles.Name -contains $sid_name) {
107-
Unload_UserHive -Sid $sid_name
108-
}
106+
if ($user_profiles.Name -contains $sid_name) {
107+
Unload_UserHive -Sid $sid_name
109108
}
110109
}
111110

ci/installer/ODBCDriverForBigQuery/Components.wsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ limitations under the License.
1717
<?if $(var.Platform) = x64 ?>
1818
<?define Win64 = "yes" ?>
1919
<?define SystemDsnRoot = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI" ?>
20+
<?define ArchDriverName = "!(loc.DriverName) (64-bit)" ?>
2021
<?else?>
2122
<?define Win64 = "no" ?>
2223
<?define SystemDsnRoot = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBC.INI" ?>
24+
<?define ArchDriverName = "!(loc.DriverName) (32-bit)" ?>
2325
<?endif?>
2426

2527
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
@@ -82,7 +84,7 @@ limitations under the License.
8284

8385
<Component Id="ODBCRegistrySettings" Guid="*" Win64="$(var.Win64)">
8486
<!-- ODBC Data Sources -->
85-
<RegistryValue Root="HKLM" Key="SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources" Name="[DSNNAME]" Type="string" Value="!(loc.DriverName)" />
87+
<RegistryValue Root="HKLM" Key="SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources" Name="[DSNNAME]" Type="string" Value="$(var.ArchDriverName)" />
8688
<RemoveRegistryKey Root="HKLM" Key="SOFTWARE\ODBC\ODBC.INI\[DSNNAME]" Action="removeOnUninstall" />
8789

8890
<!-- Additional Google-specific registry entries -->
@@ -96,9 +98,9 @@ limitations under the License.
9698

9799
<!-- DSN Configuration -->
98100
<RegistryKey Root="HKLM" Key="SOFTWARE\ODBC\ODBC.INI\[DSNNAME]">
99-
<RegistryValue Name="Description" Type="string" Value="!(loc.DriverName)" />
101+
<RegistryValue Name="Description" Type="string" Value="$(var.ArchDriverName)" />
100102
<RegistryValue Name="Catalog" Type="string" Value="" />
101-
<RegistryValue Name="Driver" Type="string" Value="!(loc.DriverName)" />
103+
<RegistryValue Name="Driver" Type="string" Value="$(var.ArchDriverName)" />
102104
<RegistryValue Name="SQLDialect" Type="string" Value="1" />
103105
<RegistryValue Name="OAuthMechanism" Type="string" Value="0" />
104106
<RegistryValue Name="Min_TLS" Type="string" Value="1.2" />
@@ -109,17 +111,17 @@ limitations under the License.
109111
</RegistryKey>
110112

111113
<!-- ODBC Drivers -->
112-
<RegistryValue Root="HKLM" Key="SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" Name="!(loc.DriverName)" Type="string" Value="Installed" />
114+
<RegistryValue Root="HKLM" Key="SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" Name="$(var.ArchDriverName)" Type="string" Value="Installed" />
113115

114116
<!-- ODBC Driver Configuration -->
115-
<RegistryKey Root="HKLM" Key="SOFTWARE\ODBC\ODBCINST.INI\!(loc.DriverName)">
116-
<RegistryValue Name="Description" Type="string" Value="!(loc.DriverName)" />
117+
<RegistryKey Root="HKLM" Key="SOFTWARE\ODBC\ODBCINST.INI\$(var.ArchDriverName)">
118+
<RegistryValue Name="Description" Type="string" Value="$(var.ArchDriverName)" />
117119
<RegistryValue Name="Driver" Type="string" Value="[INSTALLFOLDER]!(loc.DLLName).dll" />
118120
<RegistryValue Name="Setup" Type="string" Value="[INSTALLFOLDER]!(loc.DLLName).dll" />
119121
</RegistryKey>
120122

121123
<RemoveRegistryKey Root="HKLM"
122-
Key="SOFTWARE\ODBC\ODBCINST.INI\!(loc.DriverName)"
124+
Key="SOFTWARE\ODBC\ODBCINST.INI\$(var.ArchDriverName)"
123125
Action="removeOnUninstall" />
124126
</Component>
125127
</DirectoryRef>

0 commit comments

Comments
 (0)