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.
Related
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
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
We have an application that allows a user to drag a picture to a window and that window is a drop target (using OLE). When this code is run in the debugger and the Visual Studio instance is run as administrator (right click from desktop) then the target drop is not allowed.
If the exe is run on its own it works fine.
If the visual studio instance is run NOT as an admin the functionality works fine in the debugger. (Same solution/project files/etc)
Win7 OS. Visual Studio 2008. Unmanaged C++
I find it very odd. Not sure why it is happening. In fact I would have guessed the OPPOSITE regarding running VS as an admin.
Has anyone seen this or does anyone have links to workarounds or explanations?
This is most likely happening due to UIPI (User Interface Privilage Isolation).
In the case where you've launched your processes as Admin (due to the parent process (Visual Studio) being run as admin), UIPI isn't going to let non-elevated (admin) processes send any messages to your app. Drag and Drop between applications is implemented using Windows messages.
To work around this, you can use the ChangeWindowMessageFilterEx() API to opt into the appropriate drag and drop messages.
If you want to really and truly fix it, then you would need to
Detect when your process is running elevated
Spawn a non-elevated helper process which registers as the drop target
Pass the dropped data through IPC to the elevated process, using a method that's safe to use across privilege boundaries (i.e. no active objects which carry code)
This is a LOT of extra work when the workaround could be as simple as dropping from another elevated app (to get an elevated Explorer, just call up the File->Open dialog of any elevated app), but has the advantage that drag-and-drop will work properly if any of your customers ever run the app elevated.
Unfortunately this looks like a flaw in the OS:
http://blogs.msdn.com/b/patricka/archive/2010/01/28/q-why-doesn-t-drag-and-drop-work-when-my-application-is-running-elevated-a-mandatory-integrity-control-and-uipi.aspx
Oh well.
I find this whole issue appalling. MS has screwed up on this IMO. Essentially we can't debug an app correctly if I want to run MSVC in elevated mode (for example when I build the solution it registers COM servers).
http://social.msdn.microsoft.com/forums/en-US/windowsuidevelopment/thread/2fa935cf-be57-4bcc-9b96-7ee5a6b2b7a5/