84 lines
3.5 KiB
Python
84 lines
3.5 KiB
Python
import winreg
|
|
import os
|
|
|
|
def get_browser_path(browser_name):
|
|
try:
|
|
# 레지스트리 경로 설정
|
|
reg_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
|
|
# 레지스트리 키 열기
|
|
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, f"{reg_path}\\{browser_name}.exe") as key:
|
|
# 브라우저 설치 경로 가져오기
|
|
browser_path = winreg.QueryValue(key, None)
|
|
return browser_path
|
|
except FileNotFoundError:
|
|
return None
|
|
|
|
def get_specific_profile_path(browser_name, profile_name="Default"):
|
|
base_profile_path = get_browser_profile_path(browser_name)
|
|
if base_profile_path:
|
|
# 기본 프로파일 확인
|
|
specific_profile_path = os.path.join(base_profile_path, profile_name)
|
|
if os.path.exists(specific_profile_path):
|
|
return specific_profile_path
|
|
else:
|
|
# 기본 프로파일이 없으면 Profile 1 확인
|
|
fallback_profile_path = os.path.join(base_profile_path, "Profile 1")
|
|
return fallback_profile_path if os.path.exists(fallback_profile_path) else None
|
|
return None
|
|
|
|
def get_browser_profile_path(browser_name):
|
|
try:
|
|
# 레지스트리 경로 설정
|
|
reg_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
|
|
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, f"{reg_path}\\{browser_name}.exe") as key:
|
|
# 브라우저 설치 경로 가져오기
|
|
browser_path = winreg.QueryValue(key, None)
|
|
# 설치 경로에서 기본 프로파일 경로 추정
|
|
if browser_name == "chrome":
|
|
profile_path = os.path.expandvars(r"%LOCALAPPDATA%\Google\Chrome\User Data")
|
|
elif browser_name == "whale":
|
|
profile_path = os.path.expandvars(r"%LOCALAPPDATA%\Naver\Naver Whale\User Data")
|
|
else:
|
|
return None
|
|
|
|
return profile_path if os.path.exists(profile_path) else None
|
|
except FileNotFoundError:
|
|
return None
|
|
|
|
if __name__ == "__main__":
|
|
# Chrome 브라우저 경로 가져오기
|
|
chrome_path = get_browser_path("chrome")
|
|
if chrome_path:
|
|
print(f"Chrome 설치 경로: {chrome_path}")
|
|
else:
|
|
print("Chrome 브라우저가 설치되어 있지 않습니다.")
|
|
|
|
# Whale 브라우저 경로 가져오기
|
|
whale_path = get_browser_path("whale")
|
|
if whale_path:
|
|
print(f"Whale 설치 경로: {whale_path}")
|
|
else:
|
|
print("Whale 브라우저가 설치되어 있지 않습니다.")
|
|
|
|
# Chrome 브라우저 프로파일 경로 가져오기
|
|
chrome_profile = get_browser_profile_path("chrome")
|
|
if chrome_profile:
|
|
print(f"Chrome 프로파일 경로: {chrome_profile}")
|
|
else:
|
|
print("Chrome 브라우저 프로파일 경로를 찾을 수 없습니다.")
|
|
|
|
# Whale 브라우저 프로파일 경로 가져오기
|
|
whale_profile = get_browser_profile_path("whale")
|
|
if whale_profile:
|
|
print(f"Whale 프로파일 경로: {whale_profile}")
|
|
else:
|
|
print("Whale 브라우저 프로파일 경로를 찾을 수 없습니다.")
|
|
|
|
# Chrome의 기본 프로파일 경로
|
|
chrome_default_profile = get_specific_profile_path("chrome")
|
|
print(f"Chrome 기본 프로파일 (Default 없으면 Profile 1): {chrome_default_profile}")
|
|
|
|
# Whale의 기본 프로파일 경로
|
|
whale_default_profile = get_specific_profile_path("whale")
|
|
print(f"Whale 기본 프로파일 (Default 없으면 Profile 1): {whale_default_profile}")
|