Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

New Post: Task creation issue and login issue

$
0
0
dahall wrote:
When no user information is provided to the RegisterTaskDefinition method, it first looks to those provided to the Principal property and then uses the credentials of those provided to the TaskService constructor. It cannot give privileges higher than those provided to the TaskService instance. When no user information is provided to the TaskService constructor, it uses those of the executing assembly. Unless you have specifically setup a manifest file for your executable or run it using "Run as Administrator", then UAT will step in and reduce the account privileges dramatically.

I believe the following will correct your code:
' Create a new task definition and assign propertiesDim td As TaskDefinition = TaskService.Instance.NewTask
td.RegistrationInfo.Description = "Test Startup"'Create trigger that fires 1 minutes after the system starts.Dim lt As LogonTrigger = New LogonTrigger()
lt.Delay = TimeSpan.FromMinutes(1)
'Set trigger to only fire for this account so elevated permissions are not needed
lt.UserId = Environment.UserName
td.Triggers.Add(lt)
'The Add method assumes an ExecAction when the parameters are strings
td.Actions.Add("C:\test.exe")
td.Principal.RunLevel = TaskRunLevel.Highest
td.Settings.Compatibility = TaskCompatibility.V2_1
TaskService.Instance.RootFolder.RegisterTaskDefinition("test app", td)
Hi dahl,

I'm still having the issue Where the task is registering the as System and not the username, I am using the code you supplied but still no go.

When people install the App it asks for UAC prompt so it does install under administrator. but when I check the task it says system. If I restart my app and register the task it works as it should with the username and not SYSTEM.

It seems at install I'm having the issue. I'm using the a manifest file. I'll post it as well for you too see., It just a simple msi installer.
<?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.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            Specifying requestedExecutionLevel node will disable file and registry virtualization.
            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
  
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->

      <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
      
    </application>
  </compatibility>
  
  <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
  <!-- <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>-->

</asmv1:assembly>


thank you for your help
Brock

Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>