Start program when Vista starts



Up until now, I've given the user the option to start programs with
Windows the CreateShellLink function found in LibWinShell. This works
fine up to XP but Vista gives me a 'Permission denied' message when it
tries to create the .lnk file.

Apparently one workaround is to create a separate program which uses
the CreateShellLink function and then call that program from the
original one using ShellExecuteEx() API and supply the "runas" verb as
one of its parameters.

A C++ programmer told me that none of this is necessary - that the
'start with Windows' setting can be controlled with a Registry entry
and he sent me the following function. I understand most of it, but
what is the Delphi equivalent of SHSetValue()?

If someone could tranlate this function to Delphi, it would be a real
help. Thanks.


void SetAutoRestartApp( bool bOnOrOff )
{
    static TCHAR * pKey = 
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
    static TCHAR * pValue = _T("MyProg_1");
    CString csX;

    // Get the full path to the running executable
    // e.g. C:\Program Files\MyProg\MyProg.exe
    GlbGetApplicationFilename( csX );

    // Insert double quotes before
    // and after the full path
    csX.Insert( 0, _T('"') );
    csX += _T('"');

    if ( bOnOrOff ) {
        SHSetValue( HKEY_CURRENT_USER, pKey, pValue, REG_SZ,
(LPCTSTR)csX, 
csX.GetLength() );
    } else {
        SHDeleteValue( HKEY_CURRENT_USER, pKey, pValue );
    }
}

--
Brad Blanchard
http://www.braser.com

.