Icon auf Desktop kopieren

Onkel Schuppig

Erfahrenes Mitglied
Hallo zusammen,
ich habe ein Programm irgendwo im Netzwerk liegen. Wenn man dieses im Explorer sucht und aufruft, kommt bei Erstbenutzung ein Dialog mit Abfrage nach Arbeitsverzeichnis und ein Schalter für "Icon auf Desktop erzeugen."
Um letzteres geht es: Das Kopieren einer Verknüpfung nach C:\dokumente und einstellungen\<username>\desktop ist ja noch einfach. Aber wie setze ich dort programmgesteuert das "Ausführen in"?

Grüße OS
 
Das auf die saubere Weise zu machen ist etwas aufwendiger:

Code:
bool CreateLink( const GR::tChar* szPath, 
                                 const GR::tChar* szDescription, 
                                 const GR::tChar* szFile, 
                                 const GR::tChar* szIconPath, 
                                 GR::u32 dwIconIndex, 
                                 const GR::tChar* szParameter )
{

  HRESULT       hRes;

  IShellLink      *pISL;

  IPersistFile    *pIPF;

  GR::tChar       szTemp[1000];

  bool            bResult;


  if ( !SUCCEEDED( CoInitialize( NULL ) ) )
  {
    return false;
  }
  hRes = CoCreateInstance( CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&pISL );
  if ( !SUCCEEDED( hRes ) )
  {
    CoUninitialize();
    return false;
  }
  hRes = pISL->QueryInterface( IID_IPersistFile, (void **)&pIPF );
  if ( !SUCCEEDED( hRes ) )
  {
    //MessageBox( NULL, "failed to query isl", "error", MB_OK | MB_APPLMODAL );
    CoUninitialize();
    return false;
  }

  pISL->SetPath( szFile );
  wsprintf( szTemp, szFile );
  do
  {
    if ( _tcslen( szTemp ) )
    {
      szTemp[_tcslen( szTemp ) - 1] = 0;
    }
    else
    {
      break;
    }
  }
  while ( szTemp[_tcslen( szTemp ) - 1] != 92 );
  pISL->SetWorkingDirectory( szTemp );

  if ( szParameter )
  {
    pISL->SetArguments( szParameter );
  }

  if ( szIconPath != NULL )
  {
    pISL->SetIconLocation( szIconPath, dwIconIndex );
  }

  GR::tString       strDummy;


  strDummy = szPath;
  if ( strDummy.length() > 0 )
  {
    if ( strDummy[strDummy.length() - 1] != 92 )
    {
      strDummy += '\\';
    }
  }
  strDummy += szDescription;
  strDummy += _T( ".lnk" );

  // falls der Shortcut schon existiert, löschen, sonst klappt Save nicht!
  DeleteFile( strDummy.c_str() );

#ifdef UNICODE
  std::wstring    wString( strDummy );
#else
  std::wstring    wString = GR::Convert::ToWString( strDummy );
#endif

  hRes = pIPF->Save( wString.c_str(), STGM_READ );
  
  if ( SUCCEEDED( hRes ) )
  {
    bResult = true;
  }
  else
  {
    bResult = false;
  }
  pIPF->Release();
  pISL->Release();

  CoUninitialize();
  return bResult;

}



bool CreateProgramLink( const GR::tChar* szDescription, 
                                        const GR::tChar* szFile, 
                                        const GR::tChar* szParameter, 
                                        const GR::tChar* szIconPath, 
                                        GR::u32 dwIconIndex, 
                                        bool bCurrentUser )
{

  GR::tChar       szStartMenuPath[MAX_PATH],
                  szTemp[1000];

  HKEY            hKey,
                  hChildKey;

  DWORD           dwType,
                  dwSize;

  GR::tString      strShellFolder = _T( "Programs" );



  if ( bCurrentUser )
  {
    hKey = HKEY_CURRENT_USER;
  }
  else
  {
    hKey = HKEY_LOCAL_MACHINE;
    strShellFolder = _T( "Common Programs" );
  }
  wsprintf( szTemp, _T( "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" ) );
  hChildKey = NULL;

  if ( RegOpenKeyEx( hKey, szTemp, 0, KEY_QUERY_VALUE, &hChildKey ) != ERROR_SUCCESS )
  {
    return false;
  }
  dwSize = sizeof( szStartMenuPath );
  RegQueryValueEx( hChildKey, strShellFolder.c_str(), NULL, &dwType, (unsigned char*)szStartMenuPath, &dwSize );
  RegCloseKey( hChildKey );
  RegCloseKey( hKey );

  return CreateLink( szStartMenuPath, szDescription, szFile, szIconPath, dwIconIndex, szParameter );

}



bool CreateDesktopLink( const GR::tChar* szDescription, 
                                        const GR::tChar* szFile, 
                                        const GR::tChar* szIconPath, 
                                        GR::u32 dwIconIndex, 
                                        bool bCurrentUser )
{

  GR::tChar       szTemp[1000],
                  szDesktopPath[MAX_PATH];

  HKEY            hKey,
                  hChildKey;

  DWORD           dwType,
                  dwSize;



  if ( bCurrentUser )
  {
    hKey = HKEY_CURRENT_USER;
  }
  else
  {
    hKey = HKEY_LOCAL_MACHINE;
  }
  wsprintf( szTemp, _T( "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" ) );
  hChildKey = NULL;

  if ( RegOpenKeyEx( hKey, szTemp, 0, KEY_QUERY_VALUE, &hChildKey ) != ERROR_SUCCESS )
  {
    return false;
  }
  dwSize = sizeof( szDesktopPath );
  RegQueryValueEx( hChildKey, _T( "Desktop" ), NULL, &dwType, (unsigned char*)szDesktopPath, &dwSize );
  RegCloseKey( hChildKey );
  RegCloseKey( hKey );

  return CreateLink( szDesktopPath, szDescription, szFile, szIconPath, dwIconIndex );

}

Da sind einige selbstge-typedef-te Typen drin, sollte aber nicht zu schwer sein, das anzupassen.
 
Zurück