Article View: free.it.visual-basic
Article #2698Re: chiave registro di sistema
From: Grifisx
Date: Sat, 22 Feb 2003 11:51
Date: Sat, 22 Feb 2003 11:51
66 lines
3288 bytes
3288 bytes
Ti do un codice semplice da usare : ) cmq cerca in giro il registro.bas e
capisci come usarlo � un modulo indispensabile per agire sul registro.
' -----------Metti in un
Modulo--------
'*
' Esempio di creazione chiave per l'autopartenza di un exe tramite
registro /run
'
Attribute VB_Name = "mdlAutoRun"
'PUT THIS IN A .BAS MODULE, OR CHANGE DECLARATIONS TO PRIVATE
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" _
Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As _
String, ByVal ulOptions As Long, ByVal samDesired As Long, _
phkResult As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal _
hKey As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32.dll" _
Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName _
As String, ByVal Reserved As Long, ByVal dwType As Long, _
lpData As Any, ByVal cbData As Long) As Long
Public Const HKEY_CURRENT_USER = &H80000001
Public Const KEY_WRITE = &H20006
Public Const REG_SZ = 1
'
' ----------------------------Fine
Modulo-----------------------------
Da mettere nel codice :
' ----------Inserire nel
codice--------
'*
' Esempio di creazione chiave per l'autopartenza di un exe tramite
registro /run
'
Dim hregkey As Long
Dim subkey As String
Dim stringbuffer As String
subkey = "Software\Microsoft\Windows\CurrentVersion\Run"
retval = RegOpenKeyEx(HKEY_CURRENT_USER, subkey, 0, _
KEY_WRITE, hregkey)
If retval <> 0 Then
Debug.Print "Can't open the subkey"
Exit Sub
End If
r$ = "c:\programmi\gryfappunti"
stringbuffer = r$ & "\" & App.EXEName & ".exe" & vbNullChar
retval = RegSetValueEx(hregkey, "My App", 0, REG_SZ, _
ByVal stringbuffer, Len(stringbuffer))
RegCloseKey hregkeySub
'
' ---------Fine Codice------------
Il codice crea la kiave in "Software\Microsoft\Windows\CurrentVersion\Run"
per autoavviare il proramma "c:\programmi\gryfappunti" che ho fatto per
farmi apaprire un post it ad ogni avvio di winz ^_^ tu puoi modificare le
HKEY path a secondo di come servano a te per cgggiungere la chiave che
vuoi.
Technical Details
Message-ID:
<JuJ5a.215785$0v.6033825@news1.tin.it>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp.infostrada.it!news-out.tin.it!news-in.tin.it!news1.tin.it.POSTED!not-for-mailReferences:
<3Ij3a.119738$YG2.3383472@twister1.libero.it>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f94ee,5bfbc7578a5220bb X-Google-Attributes: gidf94ee,public X-Google-ArrivalTime: 2003-02-22 03:51:12 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp.infostrada.it!news-out.tin.it!news-in.tin.it!news1.tin.it.POSTED!not-for-mail From: "Grifisx" <Hell2@you.it> Newsgroups: free.it.visual-basic References: <3Ij3a.119738$YG2.3383472@twister1.libero.it> Subject: Re: chiave registro di sistema Lines: 68 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: <JuJ5a.215785$0v.6033825@news1.tin.it> Date: Sat, 22 Feb 2003 11:51:05 GMT NNTP-Posting-Host: 62.211.248.235 X-Complaints-To: newsmaster@tin.it X-Trace: news1.tin.it 1045914665 62.211.248.235 (Sat, 22 Feb 2003 12:51:05 MET) NNTP-Posting-Date: Sat, 22 Feb 2003 12:51:05 MET Organization: TIN