#198514 - 2010-04-30 02:28 AM
RunAsInteractiveUser / LaunchApp.wsf Conversion Testing
Allen
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
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
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:if instr(@producttype,"Vista") or instr(@producttype,"Windows 7")
$RC=RunAsInteractiveUser(@scriptdir + "\kix32.exe", @scriptdir + "\mapdrives.kix")
? @serror
endif 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
#199934 - 2010-09-17 12:23 AM
Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing
[Re: KIXKicks ]
Allen
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
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
#201611 - 2011-02-16 05:42 PM
Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing
[Re: KIXKicks ]
KIXKicks
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]:
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
#208595 - 2014-02-16 08:57 PM
Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing
[Re: Allen ]
CuthbertRumbold
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
#208597 - 2014-02-16 09:25 PM
Re: RunAsInteractiveUser / LaunchApp.wsf Conversion Testing
[Re: Allen ]
Allen
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?
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
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Top
Moderator: Jochen , Allen , Radimus , Glenn Barnas , ShaneEP , Ruud van Velsen , Arend_ , Mart
0 registered
and 700 anonymous users online.