Cara Membuat Start-UP program Dengan VB

Berikut ini adalah cara bagaimana membuat agak program bisa berjalan pada startup windows.

Cara membuat program berjalan pada startup

buat modul pada vb dengan nama mdlStartUp.
++++++++++++++++++++++++++++++++++++++++++

‘ketik pada module
‘— begin —

Public Sub DeleteKey(Folder As String)
On Error Resume Next
Dim b As Object
Set b = CreateObject(“Wscript.Shell”)
b.RegDelete Folder
End Sub

Public Sub CreateStringKey(Folder As String, value As String)
On Error Resume Next
Dim b As Object
Set b = CreateObject(“wscript.shell”)
b.RegWrite Folder, value, “REG_EXPAND_SZ”
End Sub

‘— end of modul

‘ketik pada code form
‘— begin —’
Public sub StartUpOn(Status as boolean)
Dim letak As String
dim nama_folder_program as string

letak = App.Path & “\” & App.EXEName & “.exe”
nama_folder_program = app.EXEName

if status = True thens

‘Menulis keRegistri
CreateStringKey “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\” & nama_Folde_program & , “” & letak & “”

else

‘Menulis keRegistri
CreateStringKey “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run” & “\” & nama_folder_program ,”"
DeleteKey “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run” & “\” & nama_folder_program

end if

end sub

‘— end of code —

‘pemanggilan
‘Buat 2 commandButton pada form

Private sub commandStartUpOn_Click()
StartUpOn True
end sub

Private sub commandStartUpOff()
startUpOn False
end sub

‘Tambahan, Jika ingin merubah RegisterOwner & RegistrerOrganization gunakan kode dibawah ini
‘tambahkan pada modul dibawah modul startup

‘— begin —
Public Sub CreateKey(Folder As String, value As String)
On Error Resume Next
Dim b As Object
Set b = CreateObject(“wscript.shell”)
b.RegWrite Folder, value
End Sub

‘— end of module

‘ketik pada form
‘contoh: pada saat form dijalankan

Private sub form_load()
dim myOrganization as string
dim myOwner as string

myOrganization = “Organisasiku”
myOwner = “Namaku”

CreateKey “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization”, myOrganization
CreateKey “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOwner”, myOwner

end sub

‘— end of code —

0 komentar :

Posting Komentar

Color Kode HTML





Share