So, I have an app that needs admin rights to work.
I created an app.manifest file. It works perfectly.
But now I need to set my program to autostart in Windows, and I am having trouble with this. If my program has an app.manifest file - program does not load when windows starts, but when I delete the app.manifest file - it works well.
Here is code from the app.manifest file:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="update.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
</application>
</compatibility>
</asmv1:assembly>
Thanks for your help.
It’s not running because when you request admin access, the user needs to authorize it as admin (click the UAC Allow button), if it’s not popping up, there should be something in the icon-tray where the user can load all blocked exe's by clicking through the icon to give admin rights. when you run without the manifest, it is running only because it defaults to running under standard access (non-admin access, basic user level rights) so you're app is running but without being able to make changes to the system or file/path access items that only admin elevated apps can do. Get me?
The question is, how do you get your exe to auto start with admin privileges if it was installed and initially ran with admin elevated privileges during its installation? There seems to be a few answers to this but i am still searching for which one(s) actually work and are reliable. Basically, if it was elevated once, it should continue to be elevated (automatically, without prompting user) when it’s auto-starting (right after reboots) - but it is NOT doing that, and that's the problem. Let me know if you make progress with this.
UPDATE: 2012.11.10:
I have found a solution, using windows task scheduler to
programmatically schedule as task (that being, to run an EXE during
reboot/startup) & you have the option to run it as an elevated app,
and I think you need to be elevated to begin with in order to be able
to schedule this elevated auto run entry in the windows task
scheduler. Seems weird I know, but MS has allowed for this (and only
this) as a way to auto elevate your apps during startup, and they
haven't provided another way to do this. So, use appropriate API's to
register a Windows Task Schedule which will run your app elevated.
I'm not sure but it's probably about the authentication of startup user. if you did not already, you may check there for detailed information.
Related
I have a WIX installer which creates an app pool as follows, using ApplicationPoolIdentity as a default identity.
<Component Id="MyConsoleAppPool" Guid="{my_guid_here}" KeyPath="yes" NeverOverwrite="yes" Win64="yes">
<iis:WebAppPool Id="MyAppPool"
Name="My Web Console"
ManagedPipelineMode="Integrated"
ManagedRuntimeVersion="v4.0" />
</Component>
Some of our customers choose to change the application pool user to a different (custom) IIS user after installation.
On upgrades, their app pool user is being reset to the default of ApplicationPoolIdentity. This is causing them headaches to deal with on every upgrade.
Is there a way of preserving the existing app pool user, ideally without requiring the user password to be re-entered? We would like this to occur silently during the upgrades.
Note: We have a helper library in C# which can be called via CustomAction if any supporting code is needed there.
The reason the app pool was being reset is that, since it was a component created internally from the installer, it would be fully removed and re-installed on upgrades.
Rather than build the app pool in the "iis:WebAppPool" element, I decided simply to reference the app pool as follows, outside of any WIX component:
<Fragment>
<iis:WebAppPool Id="MyAppPool" Name="My Web Console"/>
</Fragment>
Then I created the following custom actions to handle the app pool create/remove:
<CustomAction Id="CreateIISAppPool"
Directory="TARGETDIR"
ExeCommand="[SystemFolder]inetsrv\appcmd add apppool /name:"My Web Console" /managedRuntimeVersion:"v4.0" /managedPipelineMode:"Integrated"
Execute="deferred"
Return="ignore"
Impersonate="no" />
<CustomAction Id="DeleteIISAppPool"
Directory="TARGETDIR"
ExeCommand="[SystemFolder]inetsrv\appcmd delete apppool "My Web Console""
Execute="deferred"
Return="ignore"
Impersonate="no" />
And the sequencing, which states that the app pool is not touched on any upgrade scenarios:
<InstallExecuteSequence>
<Custom Action="DeleteIISAppPool" Before="CreateIISAppPool">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
<Custom Action="CreateIISAppPool" Before="InstallFiles">(NOT UPGRADINGPRODUCTCODE) AND (NOT Installed) AND (NOT REMOVE="ALL")</Custom>
<!-- continue with rest of custom actions here -->
</InstallExecuteSequence>
Note: This solution does not account for a user deleting their app pool manually (by mistake or otherwise). They will need to uninstall their current version and re-install to recreate the app pool. This can be resolved by adding another custom action to look for the app pool, and if it doesn't find it, install it on an upgrade with the UPGRADINGPRODUCTCODE condition.
I have created a C# application which creates custom log name in the event viewer, and writing entries into event viewer.
My application is working fine on Windows-7 OS machine But when i copied my binaries into another window-2012 server standard(SP1) machine its not working.
I ran my application RunAs administrator and I am seeing only custom log name but not the logging messages.
I have given full permission in the registry eventlog entry but no luck.
Could somebody suggest me how to fix the issue. Or debugging technique to fix this issue.
I have debugged the code there are no exceptions, Code is running smoothly.
my code is so simple like as below:
EventLog.CreateEventSource("MyApp", "TestingApplication")
EventLog.WriteEntry("MyApp", "Testing 123")
today i have tested with same eventsource and eventlogname, like as below
EventLog.CreateEventSource("MyApp", "MyApp")
it worked fine in window-2012 server standard(SP1), is there anything issue in Win-2012(SP1) or am I missing anything.
Even while running as an administrator, in Windows Server 2008 R2 it defaults to not having elevated privileges. You need an elevated privilege to create the source. Once the source is created, it should let you write to it.
There are a few ways to solve this, if you're building an actual application, you can modify the application manifest to require elevated privileges and admin rights:
<?xml version="1.0" encoding="utf-8" ?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator"
uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</asmv1:assembly>
Or, again if you're building a normal application, you can split the code to create the event source into a separate process. Then you can check to see if the event source exists, if it does, just use it, if it does not, you can run your new process that creates the event source.
In the Process start info you'll need the 'runas' verb.
If you're running a windows service, you're a bit more restricted, as services do not have the capability of "elevating" privileges through their manifest directly as far as I'm aware.
However, your service installer can elevate just fine, and should be running under the needed admin rights, you can create your event source inside the service installer; and then just consume it within the service itself.
I solved this problem by Stop/Start Windows Event Log services. I dont know what was the problem but like Leo saied it can be a bug.
I was having exact same issue. I am using WinServer 2012r2. Log created successfully but writing events appear in the Application Log. I read a lot of MSDN and forums and done everything up to the books and still have this problem. Seems MS has a bug in latest .Net framework which causes all messages to go to the Application Log :(
Finally after I rebooted server everything was working fine. I am not sure why would I need to reboot server if testing with eventcreate command line everything was working fine.
I have an applicaction which is running with administrative privileges.
Privileges are escalated automatically using application manifest.
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
From this app I have to execute some code as a user who started the app, but without elevation.
How can I achieve it?
You can use impersonation to achieve the desired results. In order to impersonate the current user without a password you need to find another process that the user has ran and get the token from that. Explorer is good for that. Here is full sample code.
I have researched over the internet about the UAC functionality on the form OK button but couldn't get the information. All of the information related to implementing the UAC is they relaunch the application with the administrative privileges.
My requirement is to make the application in which when user click on OK button with Shield Icon on it, user will be able to save some information in the windows Registry through elevate the user privilege but I don't want to relaunch the application with administrator rights.
Relaunching the application (or launching a helper application) is what you do. It is the requesting of elevated privileges while launching an application that causes the UAC confirmation screen to appear. The purpose of showing the shield icon is to let the user know that confirmation screen is coming up, basically.
You don't have to just relaunch your application. If your application allows multiple instances, you can launch a second copy with command-line parameters indicating the registry change to make. Or you can have a helper application that does admin things, and launch that as needed. A helper application doesn't need to create or show a window; it can be an entirely background operation.
May be you should add an application manifest and require administrator rights:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Edit
It may not be the best solution here, because the entire application is running under elevated privileges and that can be a security vulnerability.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to force C# App to run as administrator on Windows 7
I am building a WinForms C# appliction, and I need it to ask for administrator privileges so I can copy and open directories in C:\.
Is this possible?
The code I am going to use (if any one needs) is this:
if (!Directory.Exists("C:\\smm"))
{
Directory.Create("gg");
}
Or something like that, but I am sure I need administrator privilege.
Anyone know how I can do this?
You need to enable ClickOnce security settings in your project, then change the application manifest to require administrator privileges. This will cause Windows to show a UAC elevation prompt when the process starts, so the user can escalate your program to admin.
To enable ClickOnce, go into your project's properties, select the Security tab on the left, then check the "Enable ClickOnce Security Settings" box. Then go into the project's "Properties" directory, and open up the app.manifest file. In that file, there's a line that sets the required privileges:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
You can make it require administrator privileges like this:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
That'll make it require admin when the process starts.