Deliberately Bringing Up the Windows UAC Dialog ("Do you trust this program?")

smarty3b

Programmer
Veteran
Joined
Aug 14, 2014
Messages
35
Reaction score
0
Primarily Uses
I want to be able to run a script and have Windows' "Allow this program to make changes?" thing pop up. Like this:
1622693947735.png
My findings thus far:
* It's called "UAC," or "User Account Control." It's triggered by a program wanting to run as administrator — so that's what I need to make happen.
* Ruby does indeed have the ability, but it uses "win32ole," which isn't included in RGSS. The former is shown here: https://stackoverflow.com/questions/8268154/run-ruby-script-in-elevated-mode/27954953 and the latter is shown here: https://forums.rpgmakerweb.com/inde...uby-does-the-following-idea-make-sense.21574/
* If I'm not mistaken, I could do system(<something>, cmd.exe, and run a batch file that gets the job done. I assume there's a batch script in existence that would do what I want, but even if there were, I'm worried about it getting intercepted by security. I also don't want a CMD window visible in the background, although I'd be willing to sacrifice that if the rest of it could be made to work.
* I could also switch to MV (although I've never used it before) if being able to work with JavaScript instead of rgss would solve the problem. But right now, I'm stumped.
 

cremnophobia

Veteran
Veteran
Joined
Dec 10, 2013
Messages
234
Reaction score
104
Primarily Uses
ShellExecute can also be invoked via win32api. You don't need win32ole:
Ruby:
shellexecute = Win32API.new('shell32', 'ShellExecuteA', 'IPPPPI', 'I')
shellexecute.call(0, 'runas', 'calc.exe', nil, nil, 1)
 

smarty3b

Programmer
Veteran
Joined
Aug 14, 2014
Messages
35
Reaction score
0
Primarily Uses
ShellExecute can also be invoked via win32api. You don't need win32ole:
Ruby:
shellexecute = Win32API.new('shell32', 'ShellExecuteA', 'IPPPPI', 'I')
shellexecute.call(0, 'runas', 'calc.exe', nil, nil, 1)
Spectacular, thank you very much!
 

smarty3b

Programmer
Veteran
Joined
Aug 14, 2014
Messages
35
Reaction score
0
Primarily Uses
Posting the rest of my solution here in case anyone needs it:
I wanted an executable that didn't do anything, and for its name to show in the UAC prompt. I also wanted it to be stored in the game directory, so it'd always have it on hand.
By default, the command above runs executables in the System32 folder. I found out about rundll32.exe, which does nothing when you simply click on it — it expects arguments, and ends without a fuss when it doesn't get them. I then copy-pasted rundll32.exe into my game directory, renamed it "TRUST.exe," and used the following code in an event script to run it as an admin from the directory:
Code:
shellexecute = Win32API.new('shell32', 'ShellExecuteA', 'IPPPPI', 'I')
path = File.expand_path(File.dirname(__FILE__))+"/"
puts path
shellexecute.call(0, 'runas', path+'TRUST.exe', nil, nil, 1)
Thank you!
 

Latest Threads

Latest Profile Posts

oneOfUs.jpg
Streaming more Poppet Quest game even in about 12 minutes.
Some dog owners really impress me. I'm pushing 2-3 metric tons of garbage containers that destroy everything they hit. What do you think is going to happen to your tiny dog when I run it over? And why are you crossing my path to argue with me? Have you never been hit by 200kgs of garbage?

Lesson for you folks. Never mess with an angry garbage container. Or its driver.
I didn't dispose of a file properly and now my whole game won't start: I get a script error in the Scene Manager stage of game launch. What to do? Transfer it all to a new project? That's going to be tedious. Fortunately I am only nine workdays into it.
Makin' stuff on a broken laptop yay

Forum statistics

Threads
131,680
Messages
1,222,165
Members
173,424
Latest member
filfes
Top