Page 2 of 3 <123>
Topic Options
#209780 - 2015-01-05 04:52 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
See the UDF post right above yours... it was an attempt to fix that problem. Is it still not working right?
Top
#209782 - 2015-01-05 05:30 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I think I was missing the point yours and the prior poster's comment of the WORKDIR Being REQUIRED. Anyway, would you clarify on this, and also provide an example of how you are using the RunAsInteractiveUser() UDF?

Thanks.

Top
#209784 - 2015-01-06 10:20 AM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
sure thing ...
[disclaimer: nothing verified properly yet, just started to use it yesterday (locally) and today is a public holiday around here]

at this very moment I call it as follows:
 Code:
$ = RunAsInteractiveUser(@scriptdir + "\wkix32.exe", @scriptdir + "\logon.kix", @scriptdir)

while the gpo will call only wkix32.exe (having the above line and the udf in 'kixtart.kix')

Allthough this looks not natural the udf should be this:
 Code:
Function RunAsInteractiveUser($KixPath, $workdir, optional $kixscript, optional $taskname, optional $donotdelete)


btw.: nice effort of yours, especially the chinese transscript ;\) .. Came just in time for me


Edited by Jochen (2015-01-06 10:41 AM)
_________________________



Top
#209785 - 2015-01-06 02:03 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
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.
 Code:
    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)
 Code:
    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
 Code:
    if $workdir=""
      $workdir=@scriptdir
    endif
    if exist($workdir)
      $action.WorkingDirectory = '"' + $workdir + '"'
    else
      exit 2
    endif	


Comments, Suggestions?

Top
#209790 - 2015-01-08 03:37 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Jochen, I was hoping for your comments on the suggestions above. What do you think?
Top
#209791 - 2015-01-08 03:53 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Hey Allen,

not yet tested as GPO script .. Maybe tomorrow when the AD guy has time ;\)

Ok, on your ideas. I'd prefer #2 with a twist:

Let $workdir be optional as well as $kixscript but set $workdir to @scriptdir if not given.
_________________________



Top
#209792 - 2015-01-08 04:01 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
That's exactly what I was thinking on #2. Okay...

So my only other concern was the fact that when I originally wrote/tested this, it worked, completely without the workdir setting. It sounds as though you are testing the same way i did, locally, not in a gpo script.... so I wonder what changed?

Top
#209793 - 2015-01-08 04:52 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
apart from the OS?
can't really tell, except that I did try on Windows 6.1 Build 7601 SP1 which translates to Win 7 Enterprise (x64)
_________________________



Top
#209794 - 2015-01-08 06:09 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Okay... well here is the updated version, if you would be so kind to test it \:\)

 Code:
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
#209797 - 2015-01-09 01:20 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Odd!

 Code:
$ = RunAsInteractiveUser(@scriptdir + "\wkix32.exe", @scriptdir + "\logon.kix")
@serror
get $


results in file not found error [exit 2] due to $kixscript



Attachments
345.png
Description: screenshot of @scriptdir




Edited by Jochen (2015-01-09 01:44 PM)
_________________________



Top
#209798 - 2015-01-09 01:48 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
whoops,

@Allen, typo:

line 25:
 Code:
      if $exist($kixscript)
_________________________



Top
#209799 - 2015-01-09 01:55 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Lol.... ahhhhh so MAYBE when this typo was made the WORKDIR requirement was introduced.... hmmm

Top
#209800 - 2015-01-09 02:01 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
BTW... nice catch and sorry for the drama of figuring it out. \:\)
Top
#209801 - 2015-01-09 02:04 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
still doesnt work though \:\/
_________________________



Top
#209802 - 2015-01-09 03:17 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Ok, partly my fault. Incorporated probably illegal characters in the taskname with @date and @time macros

still after reverting to original I get Error 2147942667 in the scheduler event log when trying to start the task.
_________________________



Top
#209803 - 2015-01-09 03:23 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
This error translates to 267 "Invalid Directory" and happens when the working directory is handed to registration while being enclosed in quotes ..

so the obvious change is
line 35 to be:

 Code:
      $Action.WorkingDirectory = $workdir
_________________________



Top
#209805 - 2015-01-09 03:45 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
and a bit deeper down the rabbit hole:
Working Directory is actually truly optional for scheduled tasks. So no need to force it by default.. could successfully schedule one with lines 31-38 commented,

m(


Edited by Jochen (2015-01-09 03:50 PM)
_________________________



Top
#209806 - 2015-01-09 04:06 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Recommendation:

change lines 31 - 38 to:

 Code:
    if exist($workdir)
      $Action.WorkingDirectory = $workdir
    endif


sorry for the 'workingdir-being-required-suspicion' confusion
_________________________



Top
#209807 - 2015-01-09 04:32 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Jochen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
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

 Code:
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
#209808 - 2015-01-09 04:35 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
I'm cool with it.

Edited by Jochen (2015-01-09 04:36 PM)
_________________________



Top
Page 2 of 3 <123>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 464 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.117 seconds in which 0.068 seconds were spent on a total of 15 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org