Results 1 to 4 of 4

Thread: Pin To Start Up

  1. #1

    Thread Starter
    Lively Member Jamiex's Avatar
    Join Date
    Sep 2007
    Location
    Scotland, UK
    Posts
    116

    Pin To Start Up

    Hi

    I have two checkboxes on my form. What i want to do is when one is clicked it pins the program to start up and if the other is clicked it unpins the program from startup. Is there anyway of doing this.

    Thanks

    Jamie

    <Removed So dclamp Wouldn't Cry>

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Pin To Start Up

    What do you mean by "pin" and "unpin"?

  3. #3

    Thread Starter
    Lively Member Jamiex's Avatar
    Join Date
    Sep 2007
    Location
    Scotland, UK
    Posts
    116

    Re: Pin To Start Up

    ok "pin to startup" means that the program starts on startup and "unpin from startup" means that if the program is already set to go on startup it doesnt

    <Removed So dclamp Wouldn't Cry>

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Pin To Start Up

    Oh....never heard that expression before. Here is an example
    vb Code:
    1. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    2. Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    3. Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
    4. Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
    5. Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    6. Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    7. Private 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
    8.  
    9.  
    10. Private Const REG_SZ = 1 ' Unicode nul terminated String
    11. Private Const REG_DWORD = 4 ' 32-bit number
    12. Private Const HKEY_CLASSES_ROOT = &H80000000
    13. Private Const HKEY_CURRENT_USER = &H80000001
    14. Private Const HKEY_LOCAL_MACHINE = &H80000002
    15. Private Const HKEY_USERS = &H80000003
    16. Private Const HKEY_PERFORMANCE_DATA = &H80000004
    17. Private Const ERROR_SUCCESS = 0&
    18.  
    19.  
    20. Private Const UNIT_NAME = "UTILITY"
    21. 'To use the procedures;
    22. '---------
    23. 'If StartUp Then
    24. '    Call MakeStartUp(AddFile(App.Path, (App.EXEName & ".exe")))
    25. 'Else
    26. '    Call DeleteFromStartup(AddFile(App.Path, (App.EXEName & ".exe")))
    27. 'End If
    28. '==================================
    29.  
    30. Private Sub MakeStartUp(FileName As String)
    31. Dim Counter As Integer
    32. Dim MarkPos As Integer
    33. Dim Application As String
    34.    
    35. Application = GetFileName(FileName)
    36. Application = Left(Application, (Len(Application) - 4)) 'Replace(Application, ".exe", "", , , vbTextCompare) & "~@#"
    37. Call SaveString(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", Application, FileName)
    38. End Sub
    39.  
    40. Private Sub SaveKey(hKey As Long, strPath As String)
    41.     Dim KeyHand&
    42.     Dim r As Long
    43.    
    44.     r = RegCreateKey(hKey, strPath, KeyHand&)
    45.     r = RegCloseKey(KeyHand&)
    46. End Sub
    47.  
    48. Private Function GetString(hKey As Long, strPath As String, strValue As String)
    49.     'EXAMPLE:
    50.     '
    51.     'text1.text = getstring(HKEY_CURRENT_USE
    52.     '
    53.     ' R, "Software\VBW\Registry", "String")
    54.     '
    55.     Dim KeyHand As Long
    56.     Dim datatype As Long
    57.     Dim lResult As Long
    58.     Dim strBuf As String
    59.     Dim lDataBufSize As Long
    60.     Dim intZeroPos As Integer
    61.     Dim r As Long
    62.     Dim lValueType As Long
    63.    
    64.     r = RegOpenKey(hKey, strPath, KeyHand)
    65.     lResult = RegQueryValueEx(KeyHand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
    66.  
    67.  
    68.     If lValueType = REG_SZ Then
    69.         strBuf = String(lDataBufSize, " ")
    70.         lResult = RegQueryValueEx(KeyHand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
    71.  
    72.  
    73.         If lResult = ERROR_SUCCESS Then
    74.             intZeroPos = InStr(strBuf, Chr$(0))
    75.  
    76.  
    77.             If intZeroPos > 0 Then
    78.                 GetString = Left(strBuf, intZeroPos - 1)
    79.             Else
    80.                 GetString = strBuf
    81.             End If
    82.         End If
    83.     End If
    84. End Function
    85.  
    86. Private Sub SaveString(hKey As Long, strPath As String, strValue As String, strdata As String)
    87.     'EXAMPLE:
    88.     '
    89.     'Call savestring(HKEY_CURRENT_USER, "Sof
    90.     '
    91.     ' tware\VBW\Registry", "String", text1.t
    92.     '     ex
    93.     ' t)
    94.     '
    95.     Dim KeyHand As Long
    96.     Dim r As Long
    97.    
    98.     r = RegCreateKey(hKey, strPath, KeyHand)
    99.     r = RegSetValueEx(KeyHand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
    100.     r = RegCloseKey(KeyHand)
    101. End Sub
    102.  
    103.  
    104. Private Function GetDWord(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String) As Long
    105.     'EXAMPLE:
    106.     '
    107.     'text1.text = getdword(HKEY_CURRENT_USER
    108.     '
    109.     ' , "Software\VBW\Registry", "Dword")
    110.     '
    111.     Dim lResult As Long
    112.     Dim lValueType As Long
    113.     Dim lBuf As Long
    114.     Dim lDataBufSize As Long
    115.     Dim r As Long
    116.     Dim KeyHand As Long
    117.    
    118.     r = RegOpenKey(hKey, strPath, KeyHand)
    119.     ' Get length/data type
    120.     lDataBufSize = 4
    121.     lResult = RegQueryValueEx(KeyHand, strValueName, 0&, lValueType, lBuf, lDataBufSize)
    122.  
    123.  
    124.     If lResult = ERROR_SUCCESS Then
    125.  
    126.  
    127.         If lValueType = REG_DWORD Then
    128.             GetDWord = lBuf
    129.         End If
    130.         'Else
    131.         'Call errlog("GetDWORD-" & strPath, Fals
    132.         '
    133.         ' e)
    134.     End If
    135.     r = RegCloseKey(KeyHand)
    136. End Function
    137.  
    138.  
    139. Private Function SaveDword(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
    140.     'EXAMPLE"
    141.     '
    142.     'Call SaveDword(HKEY_CURRENT_USER, "Soft
    143.     '
    144.     ' ware\VBW\Registry", "Dword", text1.tex
    145.     '     t)
    146.     '
    147.     '
    148.     Dim lResult As Long
    149.     Dim KeyHand As Long
    150.     Dim r As Long
    151.    
    152.     r = RegCreateKey(hKey, strPath, KeyHand)
    153.     lResult = RegSetValueEx(KeyHand, strValueName, 0&, REG_DWORD, lData, 4)
    154.     'If lResult <> error_success Then
    155.     ' Call errlog("SetDWORD", False)
    156.     r = RegCloseKey(KeyHand)
    157. End Function
    158.  
    159.  
    160. Private Function DeleteKey(ByVal hKey As Long, ByVal strKey As String)
    161.     'EXAMPLE:
    162.     '
    163.     'Call DeleteKey(HKEY_CURRENT_USER, "Soft
    164.     '
    165.     ' ware\VBW")
    166.     '
    167.     Dim r As Long
    168.    
    169.     r = RegDeleteKey(hKey, strKey)
    170. End Function
    171.  
    172.  
    173. Private Function DeleteValue(ByVal hKey As Long, ByVal strPath As String, ByVal strValue As String)
    174.     'EXAMPLE:
    175.     '
    176.     'Call DeleteValue(HKEY_CURRENT_USER, "So
    177.     '
    178.     ' ftware\VBW\Registry", "Dword")
    179.     '
    180.     Dim KeyHand As Long
    181.     Dim r As Long
    182.    
    183.     r = RegOpenKey(hKey, strPath, KeyHand)
    184.     r = RegDeleteValue(KeyHand, strValue)
    185.     r = RegCloseKey(KeyHand)
    186. End Function
    187.  
    188. Private Sub DeleteFromStartup(FileName As String)
    189. Dim Counter As Integer
    190. Dim MarkPos As Integer
    191. Dim Application As String
    192.    
    193. Application = GetFileName(FileName)
    194. Application = Left(Application, (Len(Application) - 4)) 'Replace(Application, ".exe", "", , , vbTextCompare) & "~@#"
    195. Call DeleteValue(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", Application)
    196. End Sub
    197.  
    198. Private Function GetFileName(Path As String) As String
    199. 'returnes the filename from a path.
    200.  
    201. Dim Counter As Integer
    202. Dim LastPos As Integer
    203.  
    204. LastPos = 1
    205. For Counter = 1 To Len(Path)
    206.     If Mid(Path, Counter, 1) = "\" Then
    207.         LastPos = Counter
    208.     End If
    209. Next Counter
    210.  
    211. GetFileName = Mid(Path, (LastPos + 1), Len(Path))
    212.  
    213. End Function
    214.  
    215. Private Function AddFile(Path As String, File As String) As String
    216. 'This procedure adds a file name to a path.
    217. If Right(Path, 2) = ":\" Then
    218.     Path = Path & File
    219. Else
    220.     Path = Path & "\" & File
    221. End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width