Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes the problem seems to be the user, under the host process is running. To resolve this issue you can create the new user with the administrator privileges (for example with the help of start up task, when the role is starting) and impersonate the executed code. You can see the sample implementation <a href="http://kalcik.net/2013/08/02/monitoring-ftp-server-file-shares-on-windows-azure/" rel="nofollow">here</a>.</p> <pre><code>public class WorkerRole : RoleEntryPoint { public sealed class SafeTokenHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeTokenHandle() : base(true) { } [DllImport("kernel32.dll")] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool CloseHandle(IntPtr handle); protected override bool ReleaseHandle() { return CloseHandle(handle); } } [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)] public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, out SafeTokenHandle phToken); [DllImport("kernel32.dll", CharSet = CharSet.Auto)] public extern static bool CloseHandle(IntPtr handle); public override void Run() { // This is a sample worker implementation. Replace with your logic. Trace.WriteLine("TestWorkerRole entry point called", "Information"); while (true) { try { SafeTokenHandle safeTokenHandle; var returnValue = LogonUser("username", Environment.MachineName, "password", 2, 0, out safeTokenHandle); if (returnValue) { using (safeTokenHandle) { using (var impersonatedUser = WindowsIdentity.Impersonate(safeTokenHandle.DangerousGetHandle())) { const string networkSharePath = @"UNCPath"; Directory.GetFiles(networkSharePath).ToList().ForEach(file =&gt; Trace.TraceInformation(file)); } } } Thread.Sleep(10000); Trace.WriteLine("Working", "Information"); } catch (Exception ex) { Trace.TraceError(ex.ToString()); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload