I am having an EXE of C++ program which takes one EXE as input searches for symbol in it and replace it with some value from user through command prompt.
I am using Eclipse IDE and MinGW compiler for development.I have also set linker flag to '-static'. but when I run EXE on some other machine I got with the problem of UAC popup window, which is asking for administrative privileges.
I also tried with the option of setting 'Run this program as an administrator',but it is also not working.
Please help me out..Thanks in advance.
Unless you have taken steps to add the requireAdministrator option to your requestedExecutionLevel application manifest setting, you would not expect to receive a UAC prompt. However, there are backwards compatibility options in Windows that will result in the UAC prompt being shown for certain applications.
These backwards compatibility UAC prompts only happen for executable files that do not include the requestedExecutionLevel application manifest setting. In that scenario the system uses heuristics to determine whether or not to show the UAC prompt. For instance, non-manifested applications named setup.exe or patch.exe will get the UAC prompt.
The way to avoid being subject to this backwards compatibility behaviour is to link an application manifest to your executable.
This question covers the topic in rather more detail: How does Windows decide whether to display the UAC prompt?
Apart from what #David Heffernan has written, you can also trigger UAC window when you launch your application from folders like Program Files etc., which require administrative privileges. The same applies if you try to manipulate files located in such folders. Wikipedia has nice section regarding events triggering the window: http://en.wikipedia.org/wiki/User_Account_Control#Tasks_that_trigger_a_UAC_prompt
Related
in a VS C++ program we have to create and delete a windows share (dynamically). We use the NetShareAdd(...) and NetShareDel(...) functions to do so.
Since we switched to Win10, I need to run this program in elevated admin level ("run as Administrator") or change the UAC Execution Level in Project/Properties/Linker/Manifest File. Else the functions return with ERROR_ACCESS_DENIED (no matter, if the shared directory is in the users home or elsewhere on the disk).
The same thing I experienced, when I try to share the directory on commandline with net share .... Cmd has to be started "as Administrator". Else I get "access denied". Maybe the security rules have changed from Win7 to Win10. As far as well.
My question is: how does the Windows Explorer share directories. When I share the same directory with the Explorer (RightClick on Directory/Properties/Share/Extended Share) I can do this as the "normal" user, without elevation, no question from UAC, no "run as Administrator" needed. Which functions does the explorer use. Or is this some "microsoft magic"?
Thank you.
Is there any thing I can do to make sure that the shell/command prompt does not show up when I run my C++ program, it is meant to be a background program? While it isn't a huge deal if it displays because it quickly closes, I would prefer it doesn't display at all. Program will run on windows xp/vista/7 OS
Configure your compiler or linker to mark your program as a GUI application.
Windows recognizes two main types of programs: GUI and console. If the EXE header is marked as a console program, then the OS creates a console window prior to executing it. Otherwise, it doesn't. This isn't something you can control at run time; you need to set it at link time. (You can call ShowWindow(GetConsoelWindow(), SW_HIDE) to try to control it at run time, but that doesn't prevent the window from flickering on and then off again. Plus, if your program is sharing the console with another program, like cmd.exe, then you'll have just hidden the user's command-prompt window!) Even if your program doesn't have any actual GUI, that's still the mode you need to avoid having a console window created for you.
If you're starting a new project in Visual Studio, select the "Win32 Console Application" option. If you already have a project, then in your project's configuration properties, find the "Subsystem" setting of the "Linker/System" section and set it to "Console." That makes the linker use the /subsystem:console option. If you're using Mingw, use the -Wl,--subsystem,windows option.
Sounds to me like you want to create a Windows service, not a command line utility. This is why services exist. Long running background tasks that require no user interaction. A simple example here.
I have wrote a program which tries to write a file in C:\windows\ directory. I have tested the program in several PCs with winXP, win7 (64 & 32 bit).But when i install it in my client's PC it crashed with the message : TODO ( file description ) has stopped working
Please if anybudy knows any solution then reply me.
The solution is not to write to the C:\Windows folder. You're not working for the Microsoft Windows team.
It is quite awesome that you gave your client a "TODO:..." product? Please edit the version info to reflect your product name~
As for crash scenario:
Check if your application really needs Admin rights, if yes, start with "run as admin" and see it it solves the problem.
View the problem details in either "Stopped working dialog box", or in Windows event viewer. In both, you can see the exception code (like 0xC0000005) and the DLL name. For this you should enable PDB file generation by enabling /DEBUG flag in linker setting (this is not same as _DEBUG macro in compiler settings!).
Put some file-logging or message-boxing (temporary) and see till where program goes properly. Yes, you need to make few changes, build and give again to your client (and please no "TODO" as product name - be professional!).
There are a few possible causes, among them no write access(perhaps the user running the program does not have write access to C:\Windows folder. Try to manually create a file in that location.) or faulty programming.
In any case, you have a few things to try to figure out the problem. If debug is impossible you should put the sensible parts of the code in try catch blocks (for example the part where you write the file). And if error is caught you can output a message about the part where the error is. You should also include a logging solution and add logs in various places of the code. After you install the updated application, when you get an error, look up in the log file to see where the code stopped.
Is it possible you have UAC turned off, but your client doesn't? Or, would the client's user not have administrative rights? A user process would not be allowed to write to the c:\Windows folder. If that's the case, trying to create a file would throw an exception.
The proper place to create a data file would be:
Application Data under the user's folder, if the file is per user.
ProgramData (Win7) or Application Data under All Users (XP), if the file is per application (log or so).
Apart from the issue of permissions the first thing that will cause your application to crash like that is the runtimes not being installed on your client's PC. Does your install package install the MSVC runtimes? If not, have you installed the MSVC redistributable runtimes on that PC?
"I have wrote a program which tries to write a file in C:\windows\ directory. "
That's your problem right there. Don't do that.
Edit: This problem only occurs on windows 7 and vista from what I've heard.
I have a very simple app developed with an external graphics library. If I install this app into a program files directory and run it, it will crash immediately but it works fine normally, with exactly the same files. I have realised it is because you need to run the application as administrator for it to work.
I appreciate if this is a problem directly related to the graphics engine I am using, but I don't really think so (but I'm clueless). Can anyone help me?
Edit for more detail:
The application executable and files that are needed to run it are installed into the default program directory - for me, C:\Program Files (x86). If you try and run with without clicking run as administrator, it will simple freeze and say "App has stopped working. Windows is checking for a solution to the problem..." My question is basically, how can I make it so run as administrator isn't necessary?
When a program cannot perform an operation, it (the operation) should fail gracefully. My guess is your application is attempting to do something that it cannot do as a normal user and then fails to check for a return code, and then subsequently crashes. You need to identify what it is your program is doing that it should not be able to do as a normal user. For example (off the top of my head):
Write a file to Program Files (x86)
Write to HKLM
(Without more details) The problem is most likely related to the fact that your program tries to write into the directory and then excepts the file creation/modification to actually have an effect. UAC prevents applications from writing the Program Files directories without administrator privilages. The solution is to redesign your application to not rely on such behavior or store the files in question in one of the intended locations (AppData, etc. folders).
If you right-click on the EXE and go to Properties -> Compatibility there are some options that might help. You could try running the app in compatibility mode for a previous Windows version or if that doesn't work at least mark the EXE to run as administrator by default.
I am having an interesting problem when compiling my programs on win32 (mingw).
I have 2 identical projects, both created in C::B. When compiling one, it runs just fine without requiring elevated permissions, but the other prompts the user with the "Allow program to make changes to computer etc.." dialog. I would like the app to not prompt the user, as it does not need elevated privs.
This is under Win7 x64.
Could this be a Code::Blocks issue, or a compiler issue?
Thanks!
It turns out Win7 marks files with "update" (not case sensitive) in the name as needing elevated permissions. So yea, worth knowing for future
As you have already discovered, Windows detects certain application names that it thinks are setup programs, and tries to helpfully pre-elevate them to ensure they succeed.
However, this behaviour is only enabled for executables that are missing UAC information in their Win32 manifest. So if you have a program with one of the impacted names, simply give it a manifest with the relevant UAC information, and you won't get the unwanted prompts.
e.g. Aaron's blog http://brethorsting.com/blog/2007/02/meet_uac_-_creating_a_uac_manifest/
Martyn