I finally got around to trying to figure out what was a better way of implementing drive mappings without having to go around to each computer to disable the UAC in Vista. For most people using the computer in the office, this is a good thing as it usually helps prevent unwanted things from running and in the long run saving me time from having to do maintenance on it. When I last looked at trying to get Vista to run my GPO scripts that mounted the drives in my UNC, I had to disable the UAC before it would run them. Apparently this is because the scripts run at a higher privilege level during the login process, and because UAC is running at that time the scripts don’t get executed. Because of this it is necessary to run the scripts after the login process. The techcenter post from Microsoft is a bit cryptic at best and doesn’t cover mixed environments where you have XP and Vista machines running. So the best thing to do is to add in this script that I found on the Internet that is a modified version of Microsoft’s launchapp.wsf. Place this in your GPO’s scripts logon area. And then under the script path, enter in the location of your working XP script one at a time. Essentially this wsf script becomes a wrapper for your vbs code that will determine if the machine you are logging on to is a XP or Vista machine, and then execute the drive mapping script code appropriately. Below you can find the code to implement.

Note: Remember to be patient as when you implement the new GPOs it might take time to replicate over your system. Other things might affect the update such as DFS, network lag, etc. You can force the PC to update their GPO by running the command:

gpupdate /force

Script wrapper code:


<job>

<script language="VBScript">
'---------------------------------------------------------
' This script launches a provided logon script as
' interactive user if the client OS is Vista, otherwise
' the script is directly executed.
'---------------------------------------------------------

' A constant that specifies a registration trigger.
const TriggerTypeRegistration = 7

' A constant that specifies an executable action.
const ActionTypeExecutable = 0

' A constant that specifies the flag in RegisterTaskDefinition.
const FlagTaskCreate = 2

' A constant that specifies an executable action.
const LogonTypeInteractive = 3

' Event Log
Const EVENT_SUCCESS = 0

Dim wshShell

If WScript.Arguments.Length <> 1 Then
     WScript.Echo "Usage: cscript launchapp_v2.wsf <apppath>"
     WScript.Quit
End If

strAppPath = WScript.Arguments(0)

'********************************************************
' Check if the client OS is Vista.
'********************************************************
Set wshShell = CreateObject("WScript.Shell")

If IsVista() = True Then
     ' Create a scheduled task
     StartTask strAppPath
Else
     ' Execute the logon script directly
     wshShell.Run strAppPath
End If

Function IsVista
     IsVista= False
     Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!.rootcimv2")
     Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
     For Each objOS in colOSes
          osCaption = objOS.Caption
          If instr(osCaption, "Vista") Then
                IsVista = True
                Exit For
            End If
     Next
End Function

'********************************************************
' Create the TaskService object.
'********************************************************
Sub StartTask(strAppPath)
     Dim rootFolder
     Dim taskDefinition
     Dim triggers
     Dim trigger
     Dim Action
     Dim objShell

     Set objShell = Wscript.CreateObject("Wscript.Shell")
     Set service = CreateObject("Schedule.Service")
     call service.Connect()

     ' Display name for the new task
     strTaskName = "Launch App As Interactive User"

     '********************************************************
     ' Get a folder to create a task definition in.
     '********************************************************
     Set rootFolder = service.GetFolder("")

     'Delete the task if already present
     On Error Resume Next
     call rootFolder.DeleteTask(strTaskName, 0)
     Err.Clear

     '********************************************************
     ' Create the new task
     '********************************************************
     Set taskDefinition = service.NewTask(0)

     '********************************************************
     ' Create a registration trigger.
     '********************************************************
     Set triggers = taskDefinition.Triggers
     Set trigger = triggers.Create(TriggerTypeRegistration)

     ' Add an action to the task. The action executes the app.
     Set Action = taskDefinition.Actions.Create( ActionTypeExecutable )
     Action.Path = strAppPath
     objShell.LogEvent EVENT_SUCCESS, "Logon Script: Task definition created. About to submit the task..."

     '***********************************************************
     ' Register (create) the task.
     '***********************************************************
     call rootFolder.RegisterTaskDefinition( strTaskName, taskDefinition, FlagTaskCreate, , , LogonTypeInteractive)

     objShell.LogEvent EVENT_SUCCESS, "Logon script: Task submitted."
End Sub
</apppath></script>

</job>
Tags Categories: Computers, Programming, Vista, Windows Posted By: Matt
Last Edit: 29 Jun 2007 @ 03 02 PM

E-mailPermalinkComments (0)
\/ More Options ...
Change Theme...
  • Users » 71
  • Posts/Pages » 90
  • Comments » 18
Change Theme...
  • VoidVoid
  • LifeLife « Default
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LiteLight
  • No Child Pages.
  • No Child Pages.
  • No Child Pages.