RoleEnvironment.IsAvailable == false when running exe in Azure if the user is not an administrator

I have a web role deployed to Azure, and as part of the startup process, I plan to run .exe periodically to do some background work (a bit like this or this ). This works very well and means that I do not need a separate Worker role that would be relatively redundant for what I need to do for my background task.

I performed the scheduled task as a user in the local administrators group, but I want to pull it up a bit, but if I remove the user from the local administrators group and run .exe, then RoleEnvironment.IsAvailable returns false. Is there any good reason for this? What privileges should the user be able to get the correct value for RoleEnvironment.IsAvailable ?

Someone had a similar problem here when starting the Windows service as a non-admin, but without permission.

(Also asked the MSDN forum )

UPDATE . I recently noticed that the documentation for the RoleEnvironment class states

The RoleEnvironment class can be used on stand-alone components in an Azure VM outside the Azure role. [...] These processes must be run with elevated privileges to access the RoleEnvironment class.

which is probably the reason that my scheduled tasks need to be run using and administrator login.

+4
source share
1 answer

I find this really frustrating. Are you sure that this is only the security group in which the executing user works? You check this with RDP in the machine, or just expect startup tasks. Because if you are RDP and you are doing something there, it is executed in the context of the connected user, and I have never seen any of the RoleEnvironment variables available in my context when I am RDP.

However, I have an offer for you. While the individual role of the worker may be excessive, how about just implementing RoleEntryPoint in the same WebRole? This is a fully valid and supported scenario. And I saw how many customers do it. Just create a public class inside your WebRole that inherits from RoleEntryPoint, overrides the methods you want (OnStart, OnStop, Run or even less) and you're done. The only tiny caveat is that if you need a configuration file, web.config will not help. But you have to add the WaaIISHost.config file where you can put all the configuration related to the code that works in RoleEntryPoint.

Now you will have the whole context that you need, all the configurations you need, all the resources you need, and will work in the same Web role. With improved diagnostics, troubleshooting and debugging options, and then with a scheduled task.

0
source

Source: https://habr.com/ru/post/1485001/


All Articles