#209785 - 2015-01-06 02:03 PM
Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing
[Re: Jochen]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
Okay... so...
This is the current code... and based on yours (and others) tests, $workdir must be specified. When I was testing this originally, I did not run into this, however I was only testing locally and not actually in a GPO script.
if $workdir
if exist($workdir)
$action.WorkingDirectory = '"' + $workdir + '"'
else
exit 2
endif
endif
Idea 1 Change $kixscript to required, and use path of of script as workdir by default... ie Function RunAsInteractiveUser($KixPath, $kixscript, optional $workdir optional $taskname, optional $donotdelete)
if $workdir=""
$workdir=left($kixscript,instrrev($kixscript,"\"))
endif
if exist($workdir)
$action.WorkingDirectory = '"' + $workdir + '"'
else
exit 2
endif
Idea 2 By default just set the workdir to the scriptdir
if $workdir=""
$workdir=@scriptdir
endif
if exist($workdir)
$action.WorkingDirectory = '"' + $workdir + '"'
else
exit 2
endif
Comments, Suggestions?
|
Top
|
|
|
|
#209794 - 2015-01-08 06:09 PM
Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing
[Re: Jochen]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
Okay... well here is the updated version, if you would be so kind to test it
Function RunAsInteractiveUser($KixPath, optional $kixscript, optional $workdir, optional $taskname, optional $donotdelete)
Dim $service, $rootfolder, $taskdefinition, $triggers,$trigger,$action, $settings
Dim $TriggerTypeRegistration, $ActionTypeExectuable,$flagtaskcreate,$logontypeinteractive
if $taskname=""
$taskname = "Run As Interactive User - " + @ticks
endif
$TriggerTypeRegistration = 7
$ActionTypeExecutable = 0
$FlagTaskCreate = 2
$LogonTypeInteractive = 3
if exist($KixPath)
$service=CreateObject("Schedule.Service")
$service.Connect()
$rootFolder=$service.GetFolder("\")
$rootFolder.DeleteTask($taskname, 0)
$taskDefinition = $service.NewTask(0)
$triggers = $taskDefinition.Triggers
$trigger = $triggers.Create($TriggerTypeRegistration)
$settings=$taskDefinition.Settings
$settings.DisallowStartIfOnBatteries = not 1
$settings.StopIfGoingOnBatteries = not 1
$Action = $taskDefinition.Actions.Create($ActionTypeExecutable)
$Action.Path = $KixPath
if $kixscript
if $exist($kixscript)
$Action.Arguments = '"' + $kixscript + '"'
else
exit 2
endif
endif
if $workdir=""
$workdir=@scriptdir
endif
if exist($workdir)
$action.WorkingDirectory = '"' + $workdir + '"'
else
exit 2
endif
$rc=$rootFolder.RegisterTaskDefinition($taskname, $taskDefinition, $FlagTaskCreate,,, $LogonTypeInteractive)
if not $donotdelete
sleep 1
$rootFolder.DeleteTask($taskname, 0)
endif
else
exit 2
endif
endfunction
|
Top
|
|
|
|
#209800 - 2015-01-09 02:01 PM
Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing
[Re: Allen]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
BTW... nice catch and sorry for the drama of figuring it out.
|
Top
|
|
|
|
#209807 - 2015-01-09 04:32 PM
Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing
[Re: Jochen]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
You still would probably want to exit if the workdir doesnt exists, I would think... which would produce the same code produced in the post on 2/16/14... WhatchuThink?
Edit... Opps... added your suggestion of the $workdir without quotes
Function RunAsInteractiveUser($KixPath, optional $kixscript, optional $workdir, optional $taskname, optional $donotdelete)
Dim $service, $rootfolder, $taskdefinition, $triggers,$trigger,$action, $settings
Dim $TriggerTypeRegistration, $ActionTypeExectuable,$flagtaskcreate,$logontypeinteractive
if $taskname=""
$taskname = "Run As Interactive User - " + @ticks
endif
$TriggerTypeRegistration = 7
$ActionTypeExecutable = 0
$FlagTaskCreate = 2
$LogonTypeInteractive = 3
if exist($KixPath)
$service=CreateObject("Schedule.Service")
$service.Connect()
$rootFolder=$service.GetFolder("\")
$rootFolder.DeleteTask($taskname, 0)
$taskDefinition = $service.NewTask(0)
$triggers = $taskDefinition.Triggers
$trigger = $triggers.Create($TriggerTypeRegistration)
$settings=$taskDefinition.Settings
$settings.DisallowStartIfOnBatteries = not 1
$settings.StopIfGoingOnBatteries = not 1
$Action = $taskDefinition.Actions.Create($ActionTypeExecutable)
$Action.Path = $KixPath
if $kixscript
if exist($kixscript)
$Action.Arguments = '"' + $kixscript + '"'
else
exit 2
endif
endif
if $workdir
if exist($workdir)
$action.WorkingDirectory = $workdir
else
exit 2
endif
endif
$rc=$rootFolder.RegisterTaskDefinition($taskname, $taskDefinition, $FlagTaskCreate,,, $LogonTypeInteractive)
if not $donotdelete
sleep 1
$rootFolder.DeleteTask($taskname, 0)
endif
else
exit 2
endif
endfunction
Edited by Allen (2015-01-09 04:59 PM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 700 anonymous users online.
|
|
|