plat/win_inst.rs (Windows)#
Source: lib/plat/win_inst.rs
win_inst -- the Windows calls of the setup (apps/installer): the own exe path, known
folders, .lnk shortcuts through COM IShellLinkW, the HKCU registry key of the "installed
apps" entry (HKLM for a setup for all users), starting a command line
(r12-inst) [apps/installer/src/shell.s]
exe_path() -> Some(path) GetModuleFileNameW of the running exe as UTF-8 (None when
it does not fit PATH_CAP wide chars) [self_path]
known_folder(which) -> Some(p) 0 = desktop, 1 = start menu "Programs", 2 / 3 = the same of
all users, 4 = "C:\Program Files" (SHGetKnownFolderPath,
dirs.rs)
shell_link(lnk, target, dir, desc) -> bool a shortcut file lnk -> target (working
folder dir, icon 0 of the target, comment desc) [sh_link]
shell_link_id(lnk, target, dir, desc, app_id) -> bool the same with the AppUserModelID
app_id ("" = none) as the link's System.AppUserModel.ID
(the program's explicit id, taskbar.rs: its button, jump
list and notifications then belong to the link)
link_read(lnk) -> Some((target, app_id)) a shortcut's target and System.AppUserModel.ID
("" = none)
link_set_app_id(lnk, app_id) -> bool that id written into an existing shortcut
pins_set_app_id(dir, exe, app_id) -> usize the shortcuts in dir and its folders that start
exe and carry no id get app_id (pins made before the
program ran under its id no longer match its button);
Explorer is told of each (SHChangeNotify)
pinned_dir() -> Some(path) the user's pinned items (FOLDERID_UserPinned: TaskBar,
ImplicitAppShortcuts)
reg_create(subkey) -> Some(RegKey) HKCU\subkey opened for writing (created when missing);
RegKey::set_sz / set_dword, closed when dropped
reg_delete(subkey) -> bool RegDeleteKeyW(HKCU, subkey)
reg_delete_tree(subkey) -> bool RegDeleteTreeW: the key and everything below it (only a
key below Software\Classes or a browser's below
Software\Clients\StartMenuInternet; other names are refused)
reg_delete_value(subkey, name) -> bool RegDeleteKeyValueW (name "" = the default value)
reg_create_in / reg_delete_in / reg_delete_tree_in / reg_delete_value_in(Root, ..) the
same in HKCU (Root::User) or HKLM (Root::Machine: a setup
for all users, with administrator rights)
reg_exists_in(root, subkey) / reg_get_sz_in(root, subkey, name) reading: whether a key is
there, a string value
secure_dir(path) -> bool (administrator rights) a folder for all users: created, or
taken over, with the administrators as owner and a DACL of
its own -- SYSTEM and the administrators full, the users read
and run (what the folder had from above does not count)
assoc_changed() SHChangeNotify(SHCNE_ASSOCCHANGED): Explorer re-reads the
file types and URL schemes
run_cmdline(cmdline, dir, hidden) -> bool CreateProcessW (dir None = the current one,
hidden = CREATE_NO_WINDOW; the whole line, up to 32767
wide chars; outside this process's job when it lets go)
[sh_run]
run_cmdline_wait(cmdline, dir, hidden) -> Some(exit code) the same, waited for
ole32 / shell32 / advapi32 are loaded with LoadLibraryA on the first use (inst_load, as the
asm's sh_load): only kernel32 / user32 / gdi32 are linked. Paths are converted with the
asm's capacities (utf8_to_w with PATH_CAP wide chars, w_to_utf8 with PATH_CAP bytes). The
test mode (ASMINST_SHELL_DIR) is the app's business: these functions always touch the real
shell / registry.
/// the capacity of the asm's path buffers: bytes of UTF-8 / wide chars (inst.inc PATH_CAP)
PATH_CAP: usize = 520
fn exe_path() -> Option<String>the running exe's path, UTF-8 [self_path]fn known_folder(which: u32) -> Option<String>0 = the desktop, 1 = the start menu's "Programs" folder, 2 = the desktop of all users, 3 = the start menu's "Programs" of all users, 4 = the programs folder ("C:\Program Files") (dirs.rs; backslashes, at most PATH_CAP - 1 bytes; None for another number) [sh_folder, real mode]fn shell_link(lnk: &str, target: &str, dir: &str, desc: &str) -> boola shortcut lnk -> target (working folder dir, icon 0 of the target, comment desc) [sh_link]fn shell_link_id(lnk: &str, target: &str, dir: &str, desc: &str, app_id: &str) -> boola shortcut as shell_link, with the AppUserModelID app_id ("" = none)fn link_read(lnk: &str) -> Option<(String, String)>a shortcut's target (backslashes) and its System.AppUserModel.ID ("" = none)fn link_set_app_id(lnk: &str, app_id: &str) -> boolthe AppUserModelID app_id written into the existing shortcut lnkfn pinned_dir() -> Option<String>the user's pinned items (FOLDERID_UserPinned; backslashes)fn pins_set_app_id(dir: &str, exe: &str, app_id: &str) -> usizethe shortcuts in dir and in its folders (two levels: TaskBar, ImplicitAppShortcuts/<hash> below pinned_dir()) that start exe and carry no AppUserModelID get app_id -> how many were changedstruct RegKey(isize)an open registry key (closed when dropped)enum Rootthe part of the registry an installation writes to: the current user's (HKEY_CURRENT_USER, a setup for one user) or the computer's (HKEY_LOCAL_MACHINE, a setup for all users; writing there needs administrator rights)UserMachine
fn reg_create(subkey: &str) -> Option<RegKey>HKCU\subkey opened for writing, created when missing [sh_reg_begin, real mode]fn reg_create_in(root: Root, subkey: &str) -> Option<RegKey>root\subkey opened for writing, created when missing (Root::Machine: None without administrator rights)
impl RegKey
fn set_sz(&self, name: &str, value: &str)a REG_SZ value (UTF-8 in, UTF-16 stored, PATH_CAP wide chars) [sh_reg_sz]fn set_dword(&self, name: &str, value: u32)a REG_DWORD value [sh_reg_dword]fn reg_exists_in(root: Root, subkey: &str) -> boolwhether root\subkey exists (and may be read)fn reg_get_sz_in(root: Root, subkey: &str, name: &str) -> Option<String>a string value of root\subkey ("" = its default value; REG_EXPAND_SZ as stored) -> None when it or the key is missing, or of another typefn secure_dir(path: &str) -> boolthe folder of an installation for all users (administrator rights): created with, or (when it is there) given, the administrators as owner and a protected DACL -- SYSTEM and the administrators full access, the users read and run, inherited by what is made in it. A folder chosen elsewhere than in Program Files kept what its parent gave (on D:\ the authenticated users may change files): a user could swap the program or the uninstaller that runs with administrator rights. What lies in an existing folder keeps its own rightsfn reg_delete(subkey: &str) -> boolRegDeleteKeyW(HKCU, subkey) [sh_reg_delete, real mode]fn reg_delete_in(root: Root, subkey: &str) -> boolRegDeleteKeyW(root, subkey): a key without keys below itfn reg_delete_tree(subkey: &str) -> boolHKCU\subkey with all its keys and values (RegDeleteTreeW, then RegDeleteKeyW). Only a key below Software\Classes (a ProgID, a URL scheme: what file types and schemes add) or below Software\Clients\StartMenuInternet (a web browser's key) -- any other name is refused: an empty one would clear HKCU itself, "Software" every program's settings, and such a name is what a damaged or cut list of an uninstaller holdsfn reg_delete_tree_in(root: Root, subkey: &str) -> boolreg_delete_tree in root: the same names only (Root::Machine: what a setup for all users added, below HKLM)fn reg_delete_value(subkey: &str, name: &str) -> boolone value of HKCU\subkey ("" = its default value) (RegDeleteKeyValueW)fn reg_delete_value_in(root: Root, subkey: &str, name: &str) -> boolone value of root\subkey ("" = its default value)fn assoc_changed()tell the shell that file types or URL schemes changed (SHCNE_ASSOCCHANGED, SHCNF_IDLIST)fn run_cmdline(cmdline: &str, dir: Option<&str>, hidden: bool) -> boolstart a command line (UTF-8, at most 32767 wide chars: CreateProcessW's limit; an older version cut it at PATH_CAP) in dir (None = the current folder); hidden = CREATE_NO_WINDOW. It outlives a job of this process that lets it go (a tool that ends its children with itself) [sh_run]fn run_cmdline_wait(cmdline: &str, dir: Option<&str>, hidden: bool) -> Option<u32>run_cmdline and wait for the process -> its exit code (None: it did not start)