Why am I getting a permissions error when adding registry values through VBScript?

421

80070005 indicates an access denied error. Just because you're an admin doesn't mean your VBS is being executed automatically with admin rights. Add the following code to the top of the script:

If WScript.Arguments.Named.Exists("elevated") = False Then
  CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1
  WScript.Quit
End If

The code will detect if the script is running elevated, else relaunch itself with admin rights (you'll still see the prompt of course).

Share:
421

Related videos on Youtube

聂小涛
Author by

聂小涛

Updated on September 18, 2022

Comments

  • 聂小涛
    聂小涛 over 1 year

    Currently, I use rust winit on macOS, but I found that sometimes it may block all threads for a few seconds without any output. In order to reproduce the problem, I provide a demo code here:

    use winit::{
        event::{Event, WindowEvent},
        event_loop::{ControlFlow, EventLoop},
        window::WindowBuilder,
    };
    use std::process;
    use std::time::SystemTime;
    use std::env;
    
    fn main() {
        let args: Vec<String> = env::args().collect();
        println!("{:?}", args);
        let _ = std::thread::Builder::new()
        .name(format!("global-timer"))
        .spawn(move ||  {
            loop {
                match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
                    Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
                    Err(_) => panic!("SystemTime before UNIX EPOCH!"),
                }
              std::thread::sleep(std::time::Duration::from_millis(1000));
            }
        });
        let event_loop = EventLoop::new();
        let window = WindowBuilder::new()
            .with_title("A fantastic window!")
            .with_transparent(true)
            .with_visible(false)
            .build(&event_loop)
            .unwrap();
    
        event_loop.run(move |event, _, control_flow| {
            *control_flow = ControlFlow::Wait;
            // println!("{:?}", event);
            match event {
                Event::WindowEvent {
                    event: WindowEvent::CloseRequested,
                    window_id,
                } if window_id == window.id() => *control_flow = ControlFlow::Exit,
                Event::MainEventsCleared => {
                    window.request_redraw();
                }
                _ => (),
            }
        });
    }
    

    In this code, there is a line that prints time Ok (n) => println! ("1970-01-01 00:00:00 UTC was {} seconds ago!", N.as_secs ()). I expected one time per second. In fact, it works as expected when it starts, but after a period of time, it will output after a few seconds or even longer:

    enter image description here

    And then I tried windows10 and did not find that problem.

    If I change eventloop to basic loop, the problem is not reproduced

    How can I make it output every one second without blocked?

    my winit version: winit = "0.20.0" or winit = "0.21.1"

    Thank you~