windows - Network address inaccessible if ran by the Task Scheduler -


i have c# program this:

directory.exists(@"\\pcname\somedir"); 

and prints whether path accessible (exists) or not.

this problem: run app via task scheduler right after log-in (auto-log-in user), using "on login" trigger, , returns false, although path is accessible! (i manage open path using explorer.exe few seconds before app starts). marked to:

run highest privileges 

if run manually runs ok, when right click task , select "run" via task scheduler!

  • if deselect "run highest privileges", there no problem, must ran highest privileges (accesses registry , whole lot other stuff)

  • it runs under same user if run manually or automatically task scheduler - made sure using process explorer

  • it happens on machines (win8x64, admin-privileges-user no password, auto-log-in, workgroup machines, not domain), not on anothers (same: win8x64, admin-privileges-user no password, auto-log-in, workgroup machines, not domain).

  • even if insert thread.sleep(timespan.fromminutes(1)); or enter 1-min delay in task (in task scheduler) still says path not exist

problem solved. had "impersonate", although i’m not sure why: if use scheduler without restarting, accesses remote share – same settings, 1 one. after restart fails access share (and moment later, again – same settings, able access).

the difference in running after restart app-process’s parent services.exe , not explorer.exe usual. guess has log in after restart, must use services.exe (explorer.exe not supposed exist @ stage, if i'm not mistaken).

below solution in c#, roughly, whom may concern:

// logonuser "p/invoked" api: // http://www.pinvoke.net/default.aspx/advapi32/logonuser.html // solution works logon32_logon_new_credentials 4th parameter: using (var h = logonuser(username, domain, password,      logontype.logon32_logon_new_credentials,      logonprovider.logon32_provider_default)) {     using (var winimperson8ctx = windowsidentity.impersonate(h.dangerousgethandle())) {         return directory.exists(path); // works fine...         } } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -