AutoHotkey Community

It is currently May 27th, 2012, 12:12 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: UAC Reduce Priveliges
PostPosted: May 2nd, 2011, 5:38 pm 
Offline

Joined: October 3rd, 2007, 9:32 pm
Posts: 157
Location: UK
There have been may posts on elevating privileges, but I was wondering if it's possible for a script to reduce its own privileges? That is, to go from A_IsAdmin = True to A_IsAdmin = False.

Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2011, 8:18 pm 
Offline

Joined: October 3rd, 2007, 9:32 pm
Posts: 157
Location: UK
Had an idea to use task scheduler. Perhaps not very elegant, but does the job. As it turns out, most of the work was already done for me by Shajul in this wonderful post.

Code:
RunAsStd(Target) {
   ; http://www.autohotkey.com/forum/topic65768.html
   TriggerType = 1    ; specifies a time-based trigger.
   ActionTypeExec = 0    ; specifies an executable action.
   LogonType = 3   ; Set the logon type to interactive logon
   TaskCreateOrUpdate = 6

   ;********************************************************
   ; Create the TaskService object.
   service := ComObjCreate("Schedule.Service")
   service.Connect()

   ;********************************************************
   ; Get a folder to create a task definition in.
   rootFolder := service.GetFolder("\")

   ; The taskDefinition variable is the TaskDefinition object.
   ; The flags parameter is 0 because it is not supported.
   taskDefinition := service.NewTask(0)

   ;********************************************************
   ; Define information about the task.

   ; Set the registration info for the task by
   ; creating the RegistrationInfo object.
   regInfo := taskDefinition.RegistrationInfo
   regInfo.Description := "System Task"
   regInfo.Author := "System"

   ;********************************************************
   ; Set the principal for the task
   principal := taskDefinition.Principal
   principal.LogonType := LogonType  ; Set the logon type to interactive logon

   ; Set the task setting info for the Task Scheduler by
   ; creating a TaskSettings object.
   settings := taskDefinition.Settings
   settings.Enabled := True
   settings.StartWhenAvailable := True
   settings.Hidden := False

   ;********************************************************
   ; Create a time-based trigger.
   triggers := taskDefinition.Triggers
   trigger := triggers.Create(TriggerType)

   ; Trigger variables that define when the trigger is active.
   startTime += 1, Seconds  ;start 1s from now
   FormatTime,startTime,%startTime%,yyyy-MM-ddTHH`:mm`:ss

   endTime += 2, Seconds  ;end time = 2s from now
   FormatTime,endTime,%endTime%,yyyy-MM-ddTHH`:mm`:ss

   trigger.StartBoundary := startTime
   trigger.EndBoundary := endTime
   trigger.ExecutionTimeLimit := "PT1M"    ; 1 minute
   trigger.Id := "TimeTriggerId"
   trigger.Enabled := True

   ;***********************************************************
   ; Create the action for the task to execute.

   ; Add an action to the task to run notepad.exe.
   Action := taskDefinition.Actions.Create( ActionTypeExec )
   Action.Path := Target
   
   ;***********************************************************
   ; Register (create) the task.
   rootFolder.RegisterTaskDefinition("System Task", taskDefinition, TaskCreateOrUpdate ,"","", 3)
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, Yahoo [Bot] and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group