steven_hunter
Posts: 7
Joined: Tue May 16, 2006 2:17 pm
Location: West Lafayette, IN

Set a "Run Once" Action for all existing/future us

I want to have an icon in the quick launch toolbar for a program. I am re-packaging another application so we can distribute it via Group Policy on a Windows 2003 domain.

I tried adding a shortcut to "Application Data\Microsoft\Internet Explorer\Quick Launch\" but since the Group Policy installs as the machine, this shortcut is not created.

What I'd like to do is register some sort of "run once" entry for all future *and* existing users that will create the shortcut but I can't figure out how to do this. So that when they next login, the icon is created. Thanks in advance!
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi,
What I'd like to do is register some sort of "run once" entry for all future *and* existing users that will create the shortcut
You could add a script in the Startup folder for the "All users" profile that will create a Quick Launch shortcut if one does not exist. This script will run each time a user logs in, but the shortcut will be created only once for all current and future users. A sample script:

Code: Select all

createQLShortcut("Shortcut name"),"C:\Program Files\App\app.exe",_
  "C:\Program Files\App", "Description string"

Function createQLShortcut(strName, strTarget, strWkDir, strDesc)
  Dim fso,strShPath
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set WshShell = CreateObject("WScript.Shell")
  
  Set colEnvVars = WshShell.Environment("Volatile")
  strQLFolder = colEnvVars("APPDATA") &_
               "\Microsoft\Internet Explorer\Quick Launch"
  strShPath = strQLFolder & "\" & strName & ".lnk"
  
  If (Not fso.FileExists(strShPath)) Then 
    ' Create the shortcut
    Set oShellLink = WshShell.CreateShortcut(strShPath)
    oShellLink.TargetPath = strTarget
    oShellLink.WorkingDirectory = strWkDir
    oShellLink.Description = strDesc
    oShellLink.Save
  End If

End Function
Note that the conditional statement in line 14 is not absolutely necessary: if it is omitted and the shortcut already exists, the script will attempt to modify the properties for the existing shortcut.

Create a text file ("QLsh.vbs") containing the above script and modify it as necessary. Add this file in the Files and Folders page under "Start Menu -> Startup". If the package is installed per-machine, the script will be copied to the Startup folder for the "All users" profile.

Hope this helps.

Regards,
Ionut
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
steven_hunter
Posts: 7
Joined: Tue May 16, 2006 2:17 pm
Location: West Lafayette, IN

Thank you for the reply! I considered a script like that, but had hoped to avoid it for the simple reason that if a user deletes the icon from quick launch, it will be restored next login. Some of our users :roll: would not be pleased if that occured.

What I will likely do is just create another MSI that creates the icons, and assign it to the Users in Group Policy.

On a related note: Does anyone know how items specified in "HKLM\Software\Microsoft\Windows\CurrenVersion\RunOnce" behaves? Eg: Will this simply run once, but in the system context, at next boot? (This is my assumption.)

Thank you!
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Hi,
I considered a script like that, but had hoped to avoid it for the simple reason that if a user deletes the icon from quick launch, it will be restored next login. Some of our users would not be pleased if that occured.
In this case, the script could test whether a certain registry value exists in the current user's registry hive. If it does not exist, it is created, together with the shortcut. If the registry value exists (that is, the shortcut has been created previously), no action is taken.
What I will likely do is just create another MSI that creates the icons, and assign it to the Users in Group Policy.
This would be one solution. I am not sure about this, but another approach would be to assign the MSI for the application you are repackaging to the Users in the GPO. I believe that a MSI package distributed via Group Policy can run with elevated privileges.
Does anyone know how items specified in "HKLM\Software\Microsoft\Windows\CurrenVersion\RunOnce" behaves? Eg: Will this simply run once, but in the system context, at next boot? (This is my assumption.)
That's right.

Regards,
Ionut
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,
On a related note: Does anyone know how items specified in "HKLM\Software\Microsoft\Windows\CurrenVersion\RunOnce" behaves? Eg: Will this simply run once, but in the system context, at next boot? (This is my assumption.)
Yes this runs only once and for the first user that logs in. However I would suggest modifying the script above to create a file in a specific location (Eg: "C:\Documents and Settings\user\Application Data\myfile.tmp"). This file must be created only once and if already exist then the shortcut will not be created.

Here it is the modified script:

Code: Select all

createQLShortcut("Shortcut name"),"C:\Program Files\App\app.exe",_
  "C:\Program Files\App", "Description string" 

Function createQLShortcut(strName, strTarget, strWkDir, strDesc)
  Dim fso,strShPath
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set WshShell = CreateObject("WScript.Shell")
 
  Set colEnvVars = WshShell.Environment("Volatile")
  strQLFolder = colEnvVars("APPDATA") &_
               "\Microsoft\Internet Explorer\Quick Launch"
  strShPath = strQLFolder & "\" & strName & ".lnk"
 
  strTempFile = colEnvVars("APPDATA") & "\myfile.tmp"
  
  If ((Not fso.FileExists(strShPath)) and (not fso.FileExists(strTempFile))) Then
    ' Create the shortcut
    Set oShellLink = WshShell.CreateShortcut(strShPath)
    oShellLink.TargetPath = strTarget
    oShellLink.WorkingDirectory = strWkDir
    oShellLink.Description = strDesc
    oShellLink.Save
    fso.CreateTextFile(strTempFile)
  End If

End Function
The creation of the shortcut is conditioned be the existence of the temp file. Since the temp file is created only once the shortcut will not be created again if it was deleted.

Regards,
Gigi
_________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com

Return to “Common Problems”