-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch_vmrc.pyw
41 lines (30 loc) · 1.3 KB
/
launch_vmrc.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
"""
Script to support different connection proxy settings for different VM instances.
Change the constants at the top of the file, and then save this script.
Use the file extension *.pyw in order to suppress the Python console
window from launching when using this script as a shortcut.
"""
from fileinput import FileInput
from subprocess import call
# CHANGE: Server Address + Port
PROXY_URI = "http://rmcg.wins.cyber.x:9001/"
# CHANGE: VMRC URL for remote VM
MACHINE_IP = "vmrc://123.456.789.000/?moid=000"
# CHANGE: Absolute path to the preferences.ini file used by VMRC
CONFIG_PATH = r"C:\Users\Charlie\AppData\Roaming\VMware\preferences.ini"
# NO CHANGE (on default install): Absolute path to VMRC executable
VMRC_PATH = r"C:\Program Files (x86)\VMware\VMware Remote Console\vmrc.exe"
def modify(file, key):
"""Replace config key with user-defined value"""
for line in file:
if key in line:
print(f"{key} = {PROXY_URI}", end="")
else:
print(line, end="")
def main():
"""Modify config, launch VMRC"""
with FileInput(files=CONFIG_PATH, encoding="utf-8", inplace=True) as config:
modify(config, "pref.remoteVMConnProxy.uri")
call([VMRC_PATH, MACHINE_IP])
if __name__ == "__main__":
main()