{"id":317,"date":"2009-05-04T22:49:22","date_gmt":"2009-05-05T01:49:22","guid":{"rendered":"http:\/\/leandroascierto.com\/blog\/?p=317"},"modified":"2011-08-27T08:30:12","modified_gmt":"2011-08-27T11:30:12","slug":"inicio-de-aplicacion-con-windows","status":"publish","type":"post","link":"https:\/\/leandroascierto.com\/blog\/inicio-de-aplicacion-con-windows\/","title":{"rendered":"Inicio de Aplicaci\u00f3n con Windows"},"content":{"rendered":"<p style=\"text-align: justify;\">Este es un m\u00f3dulo bas que sirve para que nuestra aplicaci\u00f3n se inicie junto con Windows, no es nada novedoso, modifica las claves del registro mediante Apis.<br \/>\nCuenta con dos funciones:<br \/>\n&#8211; <em>SetAutoRun<\/em>: Con un par\u00e1metro Boolean, si \u00e9ste es verdadero ancla nuestra aplicaci\u00f3n al inicio, de lo contrario la quita, la funci\u00f3n deber\u00eda retornarnos un valor verdadero si es que todo sali\u00f3 bien.<br \/>\n&#8211; <em>IsAutoRun<\/em>: Devuelve \u00abtrue\u00bb si nuestra aplicaci\u00f3n ya est\u00e1 en el inicio<\/p>\n<p style=\"text-align: justify;\">\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOption Explicit\r\n\r\nPrivate Declare Function RegOpenKeyEx Lib &quot;advapi32.dll&quot; Alias &quot;RegOpenKeyExA&quot; (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long\r\nPrivate Declare Function RegCloseKey Lib &quot;advapi32.dll&quot; (ByVal hKey As Long) As Long\r\nPrivate Declare Function RegSetValueExString Lib &quot;advapi32.dll&quot; Alias &quot;RegSetValueExA&quot; (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long\r\nPrivate Declare Function RegDeleteKey&amp; Lib &quot;advapi32.dll&quot; Alias &quot;RegDeleteKeyA&quot; (ByVal hKey As Long, ByVal lpSubKey As String)\r\nPrivate Declare Function RegQueryValueExNULL Lib &quot;advapi32.dll&quot; Alias &quot;RegQueryValueExA&quot; (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long\r\nPrivate Declare Function RegQueryValueExString Lib &quot;advapi32.dll&quot; Alias &quot;RegQueryValueExA&quot; (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long\r\nPrivate Declare Function RegDeleteValue&amp; Lib &quot;advapi32.dll&quot; Alias &quot;RegDeleteValueA&quot; (ByVal hKey As Long, ByVal lpValueName As String)\r\n\r\nPrivate Const RAMA_RUN_WINDOWS As String = &quot;SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run&quot;\r\nPrivate Const HKEY_CLASSES_ROOT = &amp;H80000000\r\nPrivate Const HKEY_CURRENT_USER = &amp;H80000001\r\nPrivate Const HKEY_LOCAL_MACHINE = &amp;H80000002\r\nPrivate Const HKEY_USERS = &amp;H80000003\r\nPrivate Const REG_SZ As Long = 1\r\nPrivate Const KEY_ALL_ACCESS = &amp;H3F\r\n\r\nPublic Function SetAutoRun(Value As Boolean) As Boolean\u00a0\r\n    Dim Path          As String\r\n    Dim Handle        As Long\u00a0\r\n    Path = Chr(34) &amp; App.Path &amp; &quot;\\&quot; &amp; App.EXEName &amp; &quot;.exe&quot; &amp; Chr(34)\u00a0\r\n    RegOpenKeyEx HKEY_CURRENT_USER, RAMA_RUN_WINDOWS, 0, KEY_ALL_ACCESS, Handle\r\n    If Value Then\r\n        SetAutoRun = RegSetValueExString(Handle, App.Title, 0&amp;, REG_SZ, Path, Len(Path)) = 0\r\n    Else\r\n        SetAutoRun = RegDeleteValue(Handle, App.Title) = 0\r\n    End If\r\n    RegCloseKey Handle\u00a0\r\nEnd Function\r\n\r\nPublic Function IsAutoRun() As Boolean\u00a0\r\n    Dim Path          As String\r\n    Dim Handle        As Long\r\n    Dim Data          As String\r\n    Dim cch           As Long\u00a0\r\n    Path = Chr(34) &amp; App.Path &amp; &quot;\\&quot; &amp; App.EXEName &amp; &quot;.exe&quot; &amp; Chr(34)\u00a0\r\n    RegOpenKeyEx HKEY_CURRENT_USER, RAMA_RUN_WINDOWS, 0, KEY_ALL_ACCESS, Handle\r\n    RegQueryValueExNULL Handle, App.Title, 0&amp;, 0&amp;, 0&amp;, cch\r\n\r\n    If cch &gt; 0 Then\r\n        Data = String(cch - 1, 0)\r\n        RegQueryValueExString Handle, App.Title, 0&amp;, 0&amp;, Data, cch\r\n        IsAutoRun = Path = Data\r\n    End If\u00a0\r\n    RegCloseKey Handle\u00a0\r\n\r\nEnd Function\r\n<\/pre>\n<p style=\"text-align: justify;\">\n<p style=\"text-align: justify;\">\n","protected":false},"excerpt":{"rendered":"<p>Este es un m\u00f3dulo bas que sirve para que nuestra aplicaci\u00f3n se inicie junto con Windows, no es nada novedoso, modifica las claves del registro mediante Apis. Cuenta con dos funciones: &#8211; SetAutoRun: Con un par\u00e1metro Boolean, si \u00e9ste es verdadero ancla nuestra aplicaci\u00f3n al inicio, de lo contrario la quita, la funci\u00f3n deber\u00eda retornarnos <a href='https:\/\/leandroascierto.com\/blog\/inicio-de-aplicacion-con-windows\/' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[83,82],"class_list":["post-317","post","type-post","status-publish","format-standard","hentry","category-modulos","tag-registro","tag-registry","category-29-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/comments?post=317"}],"version-history":[{"count":2,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/317\/revisions"}],"predecessor-version":[{"id":531,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/317\/revisions\/531"}],"wp:attachment":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/media?parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/categories?post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/tags?post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}