-
Notifications
You must be signed in to change notification settings - Fork 0
/
VS.pyw
180 lines (140 loc) · 6.72 KB
/
VS.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import tkinter as tk
from tkinter import messagebox
import winreg
import subprocess
import os
import re
from collections import defaultdict
import shutil
import webbrowser
import sys
import ctypes
# Function to check if the script is running as admin
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
# Utility function to handle the icon path in both development and bundled exe
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and PyInstaller """
try:
base_path = sys._MEIPASS # PyInstaller stores the temp path here
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def update_registry():
try:
new_drive_letter = drive_entry.get().upper() # Get and uppercase the drive letter
new_installation_path = fr"{new_drive_letter}:\Program Files (x86)\Microsoft Visual Studio\Shared"
# Open the registry key
key_path = r"SOFTWARE\Microsoft\VisualStudio\Setup"
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path, 0, winreg.KEY_SET_VALUE)
# Set the new value for SharedInstallationPath
winreg.SetValueEx(key, "SharedInstallationPath", 0, winreg.REG_SZ, new_installation_path)
# Close the registry key
winreg.CloseKey(key)
# Show the changes in the label
show_changes(new_drive_letter, new_installation_path)
except Exception as e:
messagebox.showerror("Error", str(e))
def show_current_registry():
try:
# Open the registry key
key_path = r"SOFTWARE\Microsoft\VisualStudio\Setup"
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path, 0, winreg.KEY_READ)
# Get the current value for SharedInstallationPath
current_installation_path, _ = winreg.QueryValueEx(key, "SharedInstallationPath")
# Close the registry key
winreg.CloseKey(key)
# Extract the current drive letter
current_drive_letter = current_installation_path[0] if current_installation_path else ""
# Update the label with the current contents
current_label.config(text=f"Registry:\nComputer\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\Setup\n\nDrive Letter: {current_drive_letter}\n {current_installation_path}")
except FileNotFoundError:
# Handle the case where the registry key is not found
messagebox.showwarning("Not Found",
"Microsoft Visual Studio not found on this system. Please download Microsoft Visual Studio from the following link:\n\nhttps://visualstudio.microsoft.com/downloads/")
current_label.config(text="Registry:\nMicrosoft Visual Studio not found.")
except Exception as e:
messagebox.showerror("Error", str(e))
def show_changes(new_drive_letter, new_path):
# Show the changes made to the registry
changes_label.config(text=f"Changes Made: {new_drive_letter}\n {new_path}")
def refresh_registry():
try:
# Refresh the displayed current contents of the registry
show_current_registry()
except Exception as e:
messagebox.showerror("Error", str(e))
def open_registry_editor():
try:
# Open the Registry Editor and navigate to the specified registry key
key_path = r"SOFTWARE\Microsoft\VisualStudio\Setup"
# On Windows, use the 'start' command to open the Registry Editor at a specific key
os.system(f'start regedit')
except Exception as e:
messagebox.showerror("Error", str(e))
def open_github():
webbrowser.open("https://github.com/blahpr/MS-Visual-Studio-Path-Editor")
def show_about():
# Create a new window for the About dialog
about_window = tk.Toplevel(root)
about_window.title("About MS Visual Studio Path Editor")
# Set the window size and icon
about_window.geometry("390x245")
about_window.iconbitmap(resource_path('images/R.ico'))
# Add a label with the about text
about_text = "This Application Allows you to Change the Drive Letter for the Shared Installation Path or Visual Studio 2022: Shared components, tools, and SDK's in the Windows Registry for Microsoft Visual Studio 2022.\n\nMade With Python & GPT.\n\nContact: [email protected]\n\nhttps://github.com/blahpr/MS-Visual-Studio-Path-Editor\n\n© 2024 Blahp Software"
about_label = tk.Label(about_window, text=about_text, wraplength=350, justify="left")
about_label.pack(pady=10)
# Add a GitHub button that opens the GitHub URL
github_button = tk.Button(about_window, text="GitHub", command=open_github)
github_button.pack(pady=0)
# Function to attempt to restart the script with admin privileges
def request_admin_privileges():
# Try to re-launch the script as an admin
if not is_admin():
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
sys.exit()
# Create the main Tkinter window
root = tk.Tk()
root.title("MS Visual Studio Path Editor")
# Set the window icon
root.iconbitmap(resource_path('images/R.ico'))
# Create a menu bar
menubar = tk.Menu(root)
root.config(menu=menubar)
# Create a top-level menu button
file_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label="File", menu=file_menu)
# Add an "About" menu item
file_menu.add_command(label="About", command=show_about)
# Create a label and entry for the new drive letter
drive_label = tk.Label(root, text="Change Drive Letter:\n Visual Studio 2022: Shared components, tools, and SDK's:")
drive_label.pack(pady=5)
drive_entry = tk.Entry(root)
drive_entry.pack(pady=5)
# Create a button to update the registry (this will require admin privileges)
def update_registry_with_admin():
if not is_admin():
request_admin_privileges()
update_registry()
update_button = tk.Button(root, text="Add\\Update Registry", command=update_registry_with_admin)
update_button.pack(pady=10)
# Create a button to refresh the registry display
refresh_button = tk.Button(root, text="Refresh", command=refresh_registry)
refresh_button.pack(pady=10)
# Create a button to open the Registry Editor
open_editor_button = tk.Button(root, text="Open Registry Editor", command=open_registry_editor)
open_editor_button.pack(pady=10)
# Create a label to show the current registry information
current_label = tk.Label(root, text="Registry:\n")
current_label.pack(pady=10)
# Create a label to show the changes made
changes_label = tk.Label(root, text="\n")
changes_label.pack(pady=10)
# Show the current registry information when the application starts
show_current_registry()
# Run the Tkinter main loop
root.mainloop()