Note that there are some explanatory texts on larger screens.

plurals
  1. POError 70: Permission denied running my app at startup
    primarykey
    data
    text
    <p>I've made an example using this function:</p> <pre><code>Option Explicit Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private 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 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 Private Const HKEY_CURRENT_USER     As Long = &amp;H80000001 Private Const KEY_WRITE             As Long = &amp;H20006 Private Const REG_SZ                As Long = &amp;H1 Public Function PutOnStartUp(ByVal sPath As String) As Boolean Dim hRegkey                         As Long    If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE, hRegkey) = 0 Then        sPath = sPath &amp; vbNullChar        PutOnStartUp = RegSetValueEx(hRegkey, "My App", 0, REG_SZ, ByVal sPath, Len(sPath)) = 0        RegCloseKey hRegkey    End If End Function </code></pre> <hr> <p><strong>TEST ONE:</strong></p> <pre><code>Private Sub Form_Load() Dim sPath      As String    sPath = App.Path &amp; "\" &amp; App.EXEName &amp; ".exe"        If PutOnStartUp(sPath) Then        Me.BackColor = vbGreen    Else        Me.BackColor = vbRed    End If        Me.AutoRedraw = True    Me.Print sPath End Sub </code></pre> <ul> <li>I compile it on the desktop.</li> <li>I execute it.</li> <li>I restart the PC and effectively executed successfully from my desktop.</li> </ul> <hr> <p><strong>TEST TWO:</strong></p> <pre><code>Private Sub Form_Load() Dim sPath      As String Dim sDest      As String    sPath = App.Path &amp; "\" &amp; App.EXEName &amp; ".exe"    sDest = Environ("tmp") &amp; "\Test.exe"    If sDest &lt;&gt; sPath Then     FileCopy sPath, sDest         If PutOnStartUp(sDest) Then         Me.BackColor = vbGreen     Else         Me.BackColor = vbRed     End If    End If    Me.AutoRedraw = True    Me.Print sPath End Sub </code></pre> <ul> <li>I compile it on my desktop.</li> <li>I execute it.</li> <li>I check that it was copied to the temporary folder.</li> <li>I delete the exe of my desktop.</li> <li>I reboot and... <strong>¡CRASH!</strong></li> </ul> <blockquote> <p>Error 70: Permission denied</p> </blockquote> <p>What happens here? </p> <p>Thanks in advance...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload