我目前正在为Windows x86开发一个需要以管理员身份运行的Rust应用程序.因此,我编写了一个Windows list ,允许您请求管理员模式.

以下是app.manifest个(在项目的根部):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

这是Cargo.toml%的文件

[package]
name = "wrapper"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
named-lock = "0.3.0"
rand = "0.8.5"
reqwest = "0.11.24"
tokio = { version = "1.36.0", features = ["rt", "rt-multi-thread"] }
winapi = { version = "0.3.9", features = ["processthreadsapi", "securitybaseapi", "winnt", "fileapi", "minwinbase", "iphlpapi", "winsock2", "ws2def"] }
windows-service = "0.6.0"

[profile.release]
opt-level = 3

[package.metadata.win]
manifest = "app.manifest"

问题是,当我编译Via Cargo(cargo build --release --target=i686-pc-windows-gnu)时, list 似乎没有被考虑在内.

推荐答案

您可以在构建过程中使用以下参数设置 list :

一百:

您必须使用构建目标i686-pc-windows-msvcx86_64-pc-windows-msvc.

Cargo.toml:

[target.'cfg(target_os = "windows")'.build-dependencies]
winres = "0.1.12"

build.rs:

#[cfg(all(target_os = "windows"))]
fn main() {
    let mut res = winres::WindowsResource::new();
    res.set_manifest(
        r#"
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>
"#,
    );
    if let Err(error) = res.compile() {
        eprint!("{error}");
        std::process::exit(1);
    }
}

也可以有一个单独的文件,使用winres::WindowsResource::set_manifest_file()

Rust相关问答推荐

trait声明中的生命周期参数

如何仅使用http机箱发送http请求?

用 rust 蚀中的future 展望 struct 的future

取得本地对象字段的所有权

在本例中,为什么我不能一次多次borrow 可变变量?

在Rust中判断编译时是否无法访问

异步函数返回的future 生存期

正在将带有盒的异步特征迁移到新的异步_fn_in_特征功能

为什么比较Option<;字符串>;具有常数Option<&;str>;需要显式类型转换吗?

Rust中是否可以在不复制的情况下从另一个不可变向量创建不可变向量?

为什么 Rust 的临时值有时有参考性有时没有?

Rust 中的自动取消引用是如何工作的?

我什么时候应该使用特征作为 Rust 的类型?

判断对象是 PyDatetime 还是 Pydate 的实例?

为什么在 rust 中删除 vec 之前应该删除元素

当特征函数依赖于为 Self 实现的通用标记特征时实现通用包装器

通用类型,不同于输入类型,作为函数的返回值

为什么-x试图解析为文字并在声明性宏中失败?

当引用不再被borrow 时,Rust 不会得到它

Rust:为什么在 struct 中borrow 引用会borrow 整个 struct?