完成path添加

This commit is contained in:
cxykevin 2024-02-10 16:15:59 +08:00
parent 6df3c9a197
commit 287afeca04
5 changed files with 45 additions and 11 deletions

1
package/cli/cli/1.bat Normal file
View File

@ -0,0 +1 @@
echo helloworld

View File

@ -29,10 +29,10 @@ import config
import utils import utils
import pickle import pickle
import log import log
import uuid
import shutil import shutil
import subprocess import subprocess
import makelnk import makelnk
import regwrite
def force_copy(pkg_path, pkg_name, data_list, froms, tos): def force_copy(pkg_path, pkg_name, data_list, froms, tos):
@ -161,4 +161,10 @@ def do_action(actions_list):
except: except:
actionlogs = actionlogs + \ actionlogs = actionlogs + \
f" make shortcut \"{i[1]}\" failed: {repr(exp)}\r\n" f" make shortcut \"{i[1]}\" failed: {repr(exp)}\r\n"
elif i[0] == 7:
try:
regwrite.add_path(i[1])
except:
actionlogs = actionlogs + \
f" add path \"{i[1]}\" failed: {repr(exp)}\r\n"
return actionlogs return actionlogs

View File

@ -261,6 +261,12 @@ def load_package(pkg_name):
"/"+file_json["start"]["icon"]["command"] "/"+file_json["start"]["icon"]["command"]
actions["onload"].append( actions["onload"].append(
(6, file_json["start"]["icon"]["command"], file_json["start"]["icon"]["icon"], file_json["start"]["icon"]["name"])) (6, file_json["start"]["icon"]["command"], file_json["start"]["icon"]["icon"], file_json["start"]["icon"]["name"]))
if "path" in file_json["start"]:
for i in file_json["start"]["path"]:
if len(i) < 2 or i[1] != ':':
i = pkg_path + \
"/"+i
actions["onload"].append((7, i))
def load(): def load():

View File

@ -1,3 +1,7 @@
#####################################
## PEinjector/makelnk ##
#####################################
import os import os
import log import log
import pylnk3 import pylnk3
@ -14,8 +18,6 @@ for i in os.listdir(f"{sysdrive}\\Users"):
def makelnk(name, exepath, iconpath): def makelnk(name, exepath, iconpath):
print(f"{sysdrive}\\Users\\{username}" +
f"\\Desktop\\{name}.lnk")
log.info(f"make shortcut \"{name}\"") log.info(f"make shortcut \"{name}\"")
pylnk3.for_file(exepath, pylnk3.for_file(exepath,
lnk_name=f"{sysdrive}\\Users\\{username}" + lnk_name=f"{sysdrive}\\Users\\{username}" +

19
src/regwrite.py Normal file
View File

@ -0,0 +1,19 @@
#####################################
## PEinjector/regwrite ##
#####################################
import winreg
import log
def add_path(path):
log.info(f"add path \"{path}\"")
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", 0, winreg.KEY_READ) as key:
old_path = winreg.QueryValueEx(key, "Path")[0]
if old_path[-1] != ';':
old_path = old_path+";"
new_path = old_path+path.replace("/", "\\")
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", 0, winreg.KEY_WRITE) as key:
winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, new_path)