Page 1 of 3 123>
Topic Options
#198514 - 2010-04-30 02:28 AM RunAsInteractiveUser / LaunchApp.wsf Conversion Testing
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
A while back a thread was posted that revealed a reghack for mapping drives with a GPO Script and UAC on, was not supported by Microsoft.
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Main=26719&Number=197754

The reghack required changing EnableLinkedConnections - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Main=26424&Number=195765

Since these threads I've been wanting to revisit this. I remembered another post that discussed running your mapped drives via a vbscript called launchapp.wsf.
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=1&Number=192303

After looking over the script, I decided I would try to convert it for kix purposes. I had to add the ablility to accept arguments and a little error testing. It appears to run for me on my computer, but none of my clients use a GPO Script.

I was wondering if someone with a GPO Script could test it and post back their results. The point of the the function is to map drives and printers in the context of the user with the UAC on (Vista, Win7) while running in a GPO script. Just create a simple mapdrives.kix file to go along with this.

if instr(@producttype,"Vista") or instr(@producttype,"Windows 7")
  $RC=RunAsInteractiveUser(@scriptdir + "\kix32.exe", @scriptdir + "\mapdrives.kix")
  ? @serror
endif
 

Function RunAsInteractiveUser($FQFN, optional $arguments, 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($fqfn) $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 = $fqfn if exist($arguments) $Action.Arguments = '"' + $arguments + '"' else exit 2 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
#198564 - 2010-05-07 04:55 AM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Got to be kidding me... no one uses a GPO script? \:\(
Top
#199084 - 2010-07-23 07:38 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
KIXKicks Offline
Starting to like KiXtart

Registered: 2002-07-26
Posts: 177
Loc: Vancouver, WA
Allen,

What about using it to do something like this?

Instead of:
 Code:
if instr(@producttype,"Vista") or instr(@producttype,"Windows 7")
  $RC=RunAsInteractiveUser(@scriptdir + "\kix32.exe", @scriptdir + "\mapdrives.kix")
  ? @serror
endif


 Code:
if instr(@producttype,"Vista") or instr(@producttype,"Windows 7")
  $RC=RunAsInteractiveUser(shell '%COMSPEC% /C xcopy "\\$ipserver\netlogon\*.bmp" "c:\network" /d /r /y')
  ? @serror
endif


BTW, it seems to work for the original purpose. Thanks!


Edited by KIXKicks (2010-07-23 07:48 PM)

Top
#199092 - 2010-07-23 10:53 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: KIXKicks]
KIXKicks Offline
Starting to like KiXtart

Registered: 2002-07-26
Posts: 177
Loc: Vancouver, WA
Allen,

Would it be possible to run this as another user (one with Admin Rights) if the Interactive User doesn't have Admin Rights?

Top
#199093 - 2010-07-23 11:05 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: KIXKicks]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
I would say yes... When I was working on this, I got the impression that you could pretty much set up any scheduled task with any user. However, that is not the point of THIS particular UDF.

If you can make it work, post your code and maybe we can work on the UDFs to make it a new UDF that takes both a user and program.

Top
#199932 - 2010-09-16 10:49 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
KIXKicks Offline
Starting to like KiXtart

Registered: 2002-07-26
Posts: 177
Loc: Vancouver, WA
Allen,

Fails to run if on a laptop and not plugged in...is there a way to modify this so the power options under the Conditions tab is disabled or not check?

Top
#199934 - 2010-09-17 12:23 AM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: KIXKicks]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Interesting... that would have never crossed my mind as something to look out for... the bad news is, I'm not seeing anything obvious to fix it... here is msdn's page on this...

http://msdn.microsoft.com/en-us/library/aa383607%28VS.85%29.aspx

Top
#199935 - 2010-09-17 12:30 AM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Found it!... heading out for dinner though... will see what I can come up with afterwards...

http://msdn.microsoft.com/en-us/library/aa383480%28v=VS.85%29.aspx
DisallowStartIfOnBatteries
StopIfGoingOnBatteries

Top
#199936 - 2010-09-17 01:04 AM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
You want to talk about a needle in a hay stack... I found, count them, ONE page in my google searches with an example of how to use the SETTINGS, and it was in Chinese. Nothing on MSDN explaining how to use it.

The good news is, the top most post contains the updated function. See if it works any better.

Top
#199939 - 2010-09-17 02:15 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
 Originally Posted By: Allen
and it was in Chinese
Wassamatta? * Your Chinese a tad rusty?

* "wassamatta" is North-Jerseyan/Brooklyneese for "What is the matter", since we're talking about foreign languages. \:D

G-
_________________________
Actually I am a Rocket Scientist! \:D

Top
#199944 - 2010-09-17 04:51 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Glenn Barnas]
KIXKicks Offline
Starting to like KiXtart

Registered: 2002-07-26
Posts: 177
Loc: Vancouver, WA
Allen,

It is good to see your Chinese is still good enough to update your code...yes, it is working now. Thanks!

Top
#199945 - 2010-09-17 04:56 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: KIXKicks]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Curious, do you use a GPO script with this or something else?
Top
#199946 - 2010-09-17 05:02 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
KIXKicks Offline
Starting to like KiXtart

Registered: 2002-07-26
Posts: 177
Loc: Vancouver, WA
Both...

I have a script which updates the GPO and a local folder on the user's computer when they log in. Alot of times they are remote and so they need their drives via VPN connection.

Top
#201611 - 2011-02-16 05:42 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: KIXKicks]
KIXKicks Offline
Starting to like KiXtart

Registered: 2002-07-26
Posts: 177
Loc: Vancouver, WA
Allen,

I have modified your code [adding the important Working Directory setting]:

 Code:
Function RunAsInteractiveUser($FQFN, optional $ARGUMENTS, optional $WORKDIR, optional $TASKNAME, optional $DONOTDELETE)
	Dim $SERVICE, $ROOTFOLDER, $TASKDEFINITION, $TRIGGERS, $TRIGGER, $ACTION, $SETTINGS
	Dim $TriggerTypeRegistration, $ActionTypeExecutable, $FlagTaskCreate, $LogonTypeInteractive

	? "TASK EXECUTE: " + $FQFN ?
	? "TASK ARGUMENTS: " + $ARGUMENTS ?
	? "TASK WORKING DIRECTORY: " + $WORKDIR ?
	? "TASK NAME: " + $TASKNAME ?
	? "TASK DELETE: " + $DONOTDELETE ?
	? "TASK USERNAME: " + $UPPERUSERNAME ?
	;$NUL = PAUSE(15)

	If $TASKNAME = ""
		$TASKNAME = "Run As Interactive User - " + @ticks
	EndIf

	$TriggerTypeRegistration = 7
	$ActionTypeExecutable = 0
	$FlagTaskCreate = 2
	$LogonTypeInteractive = 3

	If Exist($FQFN)
		$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 = $FQFN

		If Exist($ARGUMENTS)
			$Action.Arguments = '"' + $ARGUMENTS + '"'
		Else
			Exit 2
		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
#201631 - 2011-02-22 03:41 AM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: KIXKicks]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Thanks for the suggestion. I'll update the top post when I get a few spare minutes.
Top
#206132 - 2012-11-07 06:46 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Top post updated to reflect KIXKicks suggestion.
Top
#208595 - 2014-02-16 08:57 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
CuthbertRumbold Offline
Just in Town

Registered: 2012-11-05
Posts: 4
Loc: USA
I've just implemented this in order to get away from the aforementioned registry hack - it works great. THANKS!!

One minor comment, the $workdir parameter is marked optional but if you omit it (as in the example) the function will fail ("exit 2").


Edited by CuthbertRumbold (2014-02-16 08:57 PM)

Top
#208596 - 2014-02-16 09:17 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: CuthbertRumbold]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Thanks for letting me know you are using it. The working directory setting was added after I initially wrote this, and I see what you mean. I'll see what I can do to fix it.
Top
#208597 - 2014-02-16 09:25 PM Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Would you mind trying this and see if it takes care of the problem with workdir?

 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

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

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

I was given the task to create my first logon script in the current millennium ;\)
Your function works a treat, albeit Cuthbert from 3 posts above is right:

You have to provide a $workdir parameter for this to work

So, this one should be REQUIRED ;\)
Care to post this in the udf lib?

Greetz
_________________________



Top
Page 1 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 505 anonymous users online.
Newest Members
Raoul, Timothy, Jojo67, MaikSimon, kvn317
17875 Registered Users

Generated in 0.151 seconds in which 0.101 seconds were spent on a total of 14 queries. Zlib compression enabled.

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