[ DART_VEJDER @ 22.08.2006. 09:43 ] @
Pozdrav svima!

Moze li mo ko pomoci oko sljedece stvari:

Potrebno mi je da na klik dugmeta program ubaci u registry kljuc koji ce uciniti da se taj program ( npr. "Moj_Program.exe" ) pokrece prilikom podizanja windowsa....

i potrebno mi je da na drugo dugme provjerim da li u registy-u postoji u startup-u taj kljuc (da li je izbrisan)....


Pretpostavljam da ova 2 koda nisu velika, pa ako bi mi ko pomogao sa gotovim kodom - bilo bi fenomenalno....

(Kod mi treba za BCB)
[ prog @ 22.08.2006. 10:48 ] @
www.wingides.com/registry sranica koja ce ti sigurno pomoci,

dolje je dio gdje se pohranjuju i izvlace podaci za podesavanje startanja neka aplikacije za vrijeme podizanja sistema.



Manage the Programs Run at Windows Startup (All Windows) Popular
You can automatically start programs whenever Windows launches. If you have programs automatically starting that you have not loaded then you can remove them using this tip as well.

Add a new startup application
Open your registry and find the key [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run].
For each program you want to start automatically create a new string value using a descriptive name, and set the value of the string to the program executable.

For example, to automatically start Notepad, add a new entry of "Notepad"="c:\windows\notepad.exe".

Remove a startup application
If you're trying to remove a program and can not find it in the StartUp folder (usually C:\WINDOWS\Start Menu\Programs\StartUp), then it may be launching from one of the registry keys below. To remove it, delete the value associated with the program you want to remove.

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit]

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServices]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce]
[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows]

It may also be loaded from the [Load] or [Run] sections of your WIN.INI file, found in the Windows directory.

Note: Remember to include the full path to the file, if the directory is not included in your default search path.

[ NrmMyth @ 22.08.2006. 10:49 ] @
Postoji Startup folder da se registry ne bi bespotrebno oneciscavao.
Citat:
C:\Documents and Settings\All Users\Start Menu\Programs\Startup

Podcrtano ide prema tvojim zeljama - dali zelis za sve korisnike ili samo za nekoga.
npr.
Citat:
C:\Documents and Settings\DART_VEJDER\Start Menu\Programs\Startup
[ X Files @ 22.08.2006. 14:35 ] @
Ova sam izvukao iz nekog svog programa, valjda radi:

Code:

bool TDiMainForm::HandleAutostart( bool Action )
{
   bool SystemOk = true;

   TRegistry *pReg = NULL;

  
   AnsiString AUTOSTART = C(IDS_SER_MAIN_REG_AUTO);
   AnsiString KEY = C(IDS_SER_MAIN_REG_KEY);

   // Ovo C() je funkcija koja vraca String iz Resursnog fajla,
   // ti samo direktno zameni...
   
   //   IDS_SER_MAIN_REG_AUTO,
   //      "\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
   //   IDS_SER_MAIN_REG_KEY,
   //      "Di dictionary";

   try
   {
      try
      {
         pReg = new TRegistry;
         pReg->RootKey = HKEY_LOCAL_MACHINE;
         if ( Action )
         {
            if ( pReg->OpenKey( AUTOSTART, true ) )
               pReg->WriteString( KEY, "\"" + ParamStr(0) + "\"" );
            else
               SystemOk = false;
         }
         else
         {
            if ( pReg->OpenKey( AUTOSTART, true ) )
               SystemOk = pReg->DeleteValue( KEY );
            else
               SystemOk = false;

         }

      }
      catch ( const Exception &e )
      {
         SystemOk = false;
      }
   }
   __finally
   {
      if ( pReg )
      {
         pReg->CloseKey();
         delete pReg;
      }
   }

   return ( SystemOk );
}


Ono true ili false kao argument treba da kazu da li da postavis ili uklonis upis.


[Ovu poruku je menjao X Files dana 22.08.2006. u 17:41 GMT+1]
[ DART_VEJDER @ 23.08.2006. 16:14 ] @
Citat:
Ono true ili false kao argument treba da kazu da li da postavis ili uklonis upis.


Da, iskoristio sam na ovaj nacin (ako se nesto ne varam):

Code:

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(HandleAutostart(true));
ShowMessage("Uspjesno upisan");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(HandleAutostart(false));
ShowMessage("Uspjesno obrisan");
}
//---------------------------------------------------------------------------


Hvala, X Files, ovo (jednom sam probao) super radi!

A kako da provjerim da li je kljuc za taj program vec upisan, posto zelim da pri svakom OnClose se upise kljuc (MORA se podizati sa windowsom) ??

Ili, koliko mi se cini, u bazu ce se i upisati samo ako nema tog kljuca vec, a ako ga ima, nece se ni upisati.. (ne moze biti vise istih kljuceva??) pa nema ni potrebe za provjerom, vec samo HandleAutostart(true) ?
[ X Files @ 23.08.2006. 16:33 ] @
Citat:

A kako da provjerim da li je kljuc za taj program vec upisan, posto zelim da pri svakom
OnClose se upise kljuc (MORA se podizati sa windowsom) ??

U principu mozes iskoristiti metodu: TRegistry::KeyExists(), pogledaj u Helpu,
mada nije neophodno, jer:

Citat:

Ili, koliko mi se cini, u bazu ce se i upisati samo ako nema tog kljuca vec, a ako ga ima,
nece se ni upisati.. (ne moze biti vise istih kljuceva??) pa nema ni potrebe za provjerom,
vec samo HandleAutostart(true) ?


TRegistry::WriteString()

Description

Call WriteString to store a string value in a data value associated with the current key.

Name is a string containing the name of the data value in which to store data.

If Name already exists, its current value is overwritten by WriteString. If Name does not exist, it is created.

Value is a string value to store in the registry.

If WriteString fails, an exception is thrown, and the value is not written to the registry.