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

smarty3b

Programmer
Regular
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

Regular
Regular
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
Regular
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
Regular
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

Curiosity kills cats. Not people. Remain ever curious!
"You dont have to negotiate if they dont have a hostage" :kaopride:
sketch1701194888871.png
Spiffing up maps is actually a lot of fun.
So the concept for my Game Jam project is way more than I can complete before the deadline. But I think I found a way to get the core done and make the incomplete parts either not really noticeable or make them a part of the story for now. That sneaky, dastardly Krampus! Then I can complete the rest. Did I mention that this is fun?

Forum statistics

Threads
136,551
Messages
1,267,452
Members
180,226
Latest member
Stormswinds
Top