 Hey, everybody, it's Brian. Welcome to the 132nd Qt tutorial with C++ and GUI programming. All right, this has been requested like 100 million zillion times. So finally, we're just going to do it and get it over with. How do you run a Windows application as an administrator? And how do you set the icon? That's a load. Well, the administrator, or is UAC, it's user account control. It determines whether or not you're an administrator. There's a whole big API behind this. But it's actually pretty easy to use. Basically, if you want to run a program, it'll say yes or no. Sometimes you'll see something like this, where it'll prompt you for the administrative password. Other times you'll see, are you sure you want to run this, continue, et cetera, et cetera. So there's a couple of different ways this thing could look. But in short, you have your normal program, and then you have an administrative program. Here's some examples. You see these down here. These are just normal programs. And this guy with the shield in front of it, that tells you it's going to prompt you with UAC, meaning it's going to say, hey, this needs to be run as an administrator. So be aware that in Windows, it's different than pretty much all the other operating systems, where you run, sorry, you compile a PE executable, or a .exe file, meaning all the resources are embedded inside of that file. There's a special file format that needs to actually be in place. Fortunately, all that's under the hood. You don't have to mess with it. You just need to know how to get the resources in there. So start cute. Now I should say, you need to right click the cute icon and run as administrator, otherwise you're going to get an error message later. Let's just call this winadmin. Put it where you normally put it. And no, I do not want to compile for all those kits. And we're just going to do a standard, next, next, finished. Nothing real snazzy about this thing. I mean, we'll just build it. Tick tock, tick tock. And if we run it, you can see that it just runs. Not a big deal, right? We're going to be working in the project file. That's where the bulk of this is going to live. Now, before we do that, there's some files that we need to copy. And I'll include these in the zip file. We're going to do an icon file, a manifest, and a resource. And we'll go over these. So where's winadmin? There you are. I'm just going to copy and paste these in here. Notice how I strategically use the Qt icon. Now, some things you should be aware. Notice how this says winicon, and our project's actually winadmin. So we need to actually rename these. Very important that you do that for your project. Otherwise, it just will not work. You'll get like an error negative 1 or some weird thing that makes no sense whatsoever. All right, so we're going to actually crack open this RC file. Select a program from list, notepad. And this is what an RC file looks like. You notice how it hasn't included. It looks just like C++. Well, surprise, it is C++. So you could actually embed just about what you want. But it has custom commands. So we need to actually modify this to have the correct icon name and the correct manifest name. Save that. Now, in case you're wondering, this line right here, the ID icon, ID icon, discardable, blah, blah, blah, that's the actual icon itself that we're going to set. This create process manifest resource ID, RT manifest. This just gives a pass to a manifest file. And that's what it handles the run as admin. So if you just want the icon, you can just use this line. If you want the icon and run as admin, you need to include this. Remember to change the icon name and the manifest name. Now, if we save that, let's crack open this manifest file. And as you can see, the manifest is just simply XML. So if you're familiar with XML, you're pretty much an expert. What you really need to understand here is the name. So let's just call this winadmin.myapp, why not? And then give it a description here. My really cool, awesome, man, I misspelled awesome. That was not awesome. And give it a good save. Now, the real magic that happens in here is this level require administrator. That's what's going to really force this thing into using the UAC prompt. So let's save that. Once those are in there, and you're pretty well sure everything's been renamed, then you just go into your project file here. And we're just going to, say, add a little comment because I love comments. And we're going to say win32. Now, this is a little fickle on some systems. And what I mean with fickle is if you're like me and you like it like that, sometimes it won't work. And it has to actually be on that line. So just be aware. We're just going to say RC file. Notice how it automatically knows what you're looking for. And we're going to say winadmin.rc, because that's the name of our RC, our resource file. See, winadminrc. And let's give it a good build. Actually, let's jump back out here. Winadmin, debug. You can see, let's actually blow this up. Let's really blow this up. Let's go gigantic. There we go. You see, here's our winadmin.exe file. He's just got a standard generic windows icon, and there's no little shield. So we're going to actually build this. And with any luck, see, there's that resource error. So I did something wrong. And that's the problem is it doesn't really tell you a whole lot. Winres can't open winicon.exe. That's why, winicon.exe. All right, so that tells me, winres tells me there's something wrong with our resource file. So let's go back out here. And let's go to winadminrc. Ah, yes, see, winicon. There we go. We're going to change that to winadmin. Honestly, that was great for demonstration purposes, but I did not plan that. That was just me being stupid. So let's just double check so we don't waste your time again. We've got the right icon name. We've got the right manifest. And now notice how the manifest name is the name of the executable and dot manifest. That's how it's impending it inside of the executable. And we've got the cute. We've got the manifest. Let's just crack that open again just because I'm paranoid because I already had a bad build. And la-ba-dee, blah, blah, blah, looks good. Required administrators got our stuff in there. And let's go back to our snazzy little. There we go. Now I'm going to give this a build here. And it built. Notice how now it's got the cute icon and it's got the shield. Now that's a giant icon. That's going to just murder my eyes there. That's better. Now the thing you need to know about icons is not all icons are created equal, meaning an icon file is actually a bunch of images compressed into one file. You have like a 16 by 16, a 32 by 32, 64 by 64. That's how the image can scale in size. So really pick your icon accordingly. That shield means it will prompt for UAC. If I double click this, you won't see it in the recording because the recorder I use kind of sucks. But it will actually prompt you for UAC. Now if you go to run this in cute, notice how for me it runs. If it says failure, warning failure, wrong permissions question mark, that means you didn't run cute creator itself as an administrator. And that's a key concept you need to understand. That's a mouthful. That's all for this tutorial. I'm going to try and get this up on my website because I'm sure a couple of you really want this. Be sure to visit my website, voidrealms.com, for the source code for this and other tutorials. Just go to tutorials, filter by cute, and we're going to be way at the end of this. Way, way, way. Gosh, there's a lot of these. Page 14, something. And if this was helpful, especially if you're a business, this site's 100% funded by your donations. So please consider donating. But if you're a poor college kid that's eating ramen noodles, don't donate. Please just save it for your ramen noodles. That's it. Thanks for watching.