Author: tfaber
Date: Sun Jan 13 10:38:47 2013
New Revision: 58163

URL: http://svn.reactos.org/svn/reactos?rev=58163&view=rev
Log:
[EXPLORER_NEW]
- Process autostart registry entries. Patch by Edijs Kolesnikovičs.
CORE-6887

Added:
    trunk/reactos/base/shell/explorer-new/startup.c
      - copied, changed from r58156, 
trunk/reactos/base/shell/explorer/services/startup.c
Modified:
    trunk/reactos/base/shell/explorer-new/CMakeLists.txt
    trunk/reactos/base/shell/explorer-new/explorer.c
    trunk/reactos/base/shell/explorer-new/precomp.h

Modified: trunk/reactos/base/shell/explorer-new/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer-new/CMakeLists.txt?rev=58163&r1=58162&r2=58163&view=diff
==============================================================================
--- trunk/reactos/base/shell/explorer-new/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/base/shell/explorer-new/CMakeLists.txt [iso-8859-1] Sun Jan 
13 10:38:47 2013
@@ -7,6 +7,7 @@
     explorer.c
     settings.c
     startmnu.c
+    startup.c
     taskband.c
     taskswnd.c
     tbsite.c

Modified: trunk/reactos/base/shell/explorer-new/explorer.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer-new/explorer.c?rev=58163&r1=58162&r2=58163&view=diff
==============================================================================
--- trunk/reactos/base/shell/explorer-new/explorer.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/explorer-new/explorer.c [iso-8859-1] Sun Jan 13 
10:38:47 2013
@@ -400,6 +400,8 @@
         /* WinXP: Notify msgina to hide the welcome screen */
         if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent")))
             SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent"));
+
+        startup(0, NULL);
     }
     else
     {

Modified: trunk/reactos/base/shell/explorer-new/precomp.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer-new/precomp.h?rev=58163&r1=58162&r2=58163&view=diff
==============================================================================
--- trunk/reactos/base/shell/explorer-new/precomp.h [iso-8859-1] (original)
+++ trunk/reactos/base/shell/explorer-new/precomp.h [iso-8859-1] Sun Jan 13 
10:38:47 2013
@@ -257,6 +257,12 @@
                  IN DWORD dwValue);
 
 /*
+ * startup.c
+ */
+
+int startup(int argc, const char *argv[]);
+
+/*
  * trayprop.h
  */
 

Copied: trunk/reactos/base/shell/explorer-new/startup.c (from r58156, 
trunk/reactos/base/shell/explorer/services/startup.c)
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/explorer-new/startup.c?p2=trunk/reactos/base/shell/explorer-new/startup.c&p1=trunk/reactos/base/shell/explorer/services/startup.c&r1=58156&r2=58163&rev=58163&view=diff
==============================================================================
--- trunk/reactos/base/shell/explorer/services/startup.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/explorer-new/startup.c [iso-8859-1] Sun Jan 13 
10:38:47 2013
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2002 Andreas Mohr
  * Copyright (C) 2002 Shachar Shemesh
+ * Copyright (C) 2013 Edijs Kolesnikovics
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -24,10 +25,6 @@
  * Knowledge base articles that explain this are 137367, 179365, 232487 and 
232509.
  * Also, 119941 has some info on grpconv.exe
  * The operations performed are (by order of execution):
- *
- * Preboot (prior to fully loading the Windows kernel):
- * - wininit.exe (rename operations left in wininit.ini - Win 9x only)
- * - PendingRenameOperations (rename operations left in the registry - Win NT+ 
only)
  *
  * Startup (before the user logs in)
  * - Services (NT, ?semi-synchronous?, not implemented yet)
@@ -42,176 +39,11 @@
  * - HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce (all, 
asynch)
  *
  * Somewhere in there is processing the RunOnceEx entries (also no imp)
- *
- * Bugs:
- * - If a pending rename registry does not start with \??\ the entry is
- *   processed anyways. I'm not sure that is the Windows behaviour.
- * - Need to check what is the windows behaviour when trying to delete files
- *   and directories that are read-only
- * - In the pending rename registry processing - there are no traces of the 
files
- *   processed (requires translations from Unicode to Ansi).
  */
 
-#include <stdio.h>
-#include <windows.h>
-#include <ctype.h>
+#include "precomp.h"
 
 EXTERN_C HRESULT WINAPI SHCreateSessionKey(REGSAM samDesired, PHKEY phKey);
-
-/**
- * Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
- * Returns FALSE if there was an error, or otherwise if all is ok.
- */
-static BOOL wininit()
-{
-    return TRUE;
-}
-
-static BOOL pendingRename()
-{
-    static const WCHAR ValueName[] = {'P','e','n','d','i','n','g',
-                                      'F','i','l','e','R','e','n','a','m','e',
-                                      
'O','p','e','r','a','t','i','o','n','s',0};
-    static const WCHAR SessionW[] = { 'S','y','s','t','e','m','\\',
-                                     
'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
-                                     'C','o','n','t','r','o','l','\\',
-                                     'S','e','s','s','i','o','n',' 
','M','a','n','a','g','e','r',0};
-    WCHAR *buffer=NULL;
-    const WCHAR *src=NULL, *dst=NULL;
-    DWORD dataLength=0;
-    HKEY hSession=NULL;
-    DWORD res;
-
-    printf("Entered\n");
-
-    if ((res=RegOpenKeyExW(HKEY_LOCAL_MACHINE, SessionW, 0, KEY_ALL_ACCESS, 
&hSession))
-            !=ERROR_SUCCESS)
-    {
-        if (res==ERROR_FILE_NOT_FOUND)
-        {
-            printf("The key was not found - skipping\n");
-            res=TRUE;
-        }
-        else
-        {
-            printf("Couldn't open key, error %ld\n", res);
-            res=FALSE;
-        }
-
-        goto end;
-    }
-
-    res=RegQueryValueExW(hSession, ValueName, NULL, NULL /* The value type 
does not really interest us, as it is not
-                                                             truely a 
REG_MULTI_SZ anyways */,
-            NULL, &dataLength);
-    if (res==ERROR_FILE_NOT_FOUND)
-    {
-        /* No value - nothing to do. Great! */
-        printf("Value not present - nothing to rename\n");
-        res=TRUE;
-        goto end;
-    }
-
-    if (res!=ERROR_SUCCESS)
-    {
-        printf("Couldn't query value's length (%ld)\n", res);
-        res=FALSE;
-        goto end;
-    }
-
-    buffer=malloc(dataLength);
-    if (buffer==NULL)
-    {
-        printf("Couldn't allocate %lu bytes for the value\n", dataLength);
-        res=FALSE;
-        goto end;
-    }
-
-    res=RegQueryValueExW(hSession, ValueName, NULL, NULL, (LPBYTE)buffer, 
&dataLength);
-    if (res!=ERROR_SUCCESS)
-    {
-        printf("Couldn't query value after successfully querying before 
(%lu),\n"
-                "please report to [email protected]\n", res);
-        res=FALSE;
-        goto end;
-    }
-
-    /* Make sure that the data is long enough and ends with two NULLs. This
-     * simplifies the code later on.
-     */
-    if (dataLength<2*sizeof(buffer[0]) ||
-            buffer[dataLength/sizeof(buffer[0])-1]!='\0' ||
-            buffer[dataLength/sizeof(buffer[0])-2]!='\0')
-    {
-        printf("Improper value format - doesn't end with NULL\n");
-        res=FALSE;
-        goto end;
-    }
-
-    for(src=buffer; (src-buffer)*sizeof(src[0])<dataLength && *src!='\0';
-            src=dst+lstrlenW(dst)+1)
-    {
-        DWORD dwFlags=0;
-
-        printf("processing next command\n");
-
-        dst=src+lstrlenW(src)+1;
-
-        /* We need to skip the \??\ header */
-        if (src[0]=='\\' && src[1]=='?' && src[2]=='?' && src[3]=='\\')
-            src+=4;
-
-        if (dst[0]=='!')
-        {
-            dwFlags|=MOVEFILE_REPLACE_EXISTING;
-            dst++;
-        }
-
-        if (dst[0]=='\\' && dst[1]=='?' && dst[2]=='?' && dst[3]=='\\')
-            dst+=4;
-
-        if (*dst!='\0')
-        {
-            /* Rename the file */
-            MoveFileExW(src, dst, dwFlags);
-        } else
-        {
-            /* Delete the file or directory */
-                       res = GetFileAttributesW (src);
-            if (res != (DWORD)-1)
-            {
-                if ((res&FILE_ATTRIBUTE_DIRECTORY)==0)
-                {
-                    /* It's a file */
-                    DeleteFileW(src);
-                } else
-                {
-                    /* It's a directory */
-                    RemoveDirectoryW(src);
-                }
-            } else
-            {
-                printf("couldn't get file attributes (%ld)\n", GetLastError());
-            }
-        }
-    }
-
-    if ((res=RegDeleteValueW(hSession, ValueName))!=ERROR_SUCCESS)
-    {
-        printf("Error deleting the value (%lu)\n", GetLastError());
-        res=FALSE;
-    } else
-        res=TRUE;
-
-end:
-    if (buffer!=NULL)
-        free(buffer);
-
-    if (hSession!=NULL)
-        RegCloseKey(hSession);
-
-    return res;
-}
 
 enum runkeys {
     RUNKEY_RUN, RUNKEY_RUNONCE, RUNKEY_RUNSERVICES, RUNKEY_RUNSERVICESONCE
@@ -242,17 +74,17 @@
 {
     STARTUPINFOW si;
     PROCESS_INFORMATION info;
-    DWORD exit_code=0;
-    WCHAR szCmdLineExp[MAX_PATH+1]= L"\0";
+    DWORD exit_code = 0;
+    WCHAR szCmdLineExp[MAX_PATH+1] = L"\0";
 
     ExpandEnvironmentStringsW(cmdline, szCmdLineExp, sizeof(szCmdLineExp) / 
sizeof(WCHAR));
 
     memset(&si, 0, sizeof(si));
-    si.cb=sizeof(si);
+    si.cb = sizeof(si);
     if (minimized)
     {
-        si.dwFlags=STARTF_USESHOWWINDOW;
-        si.wShowWindow=SW_MINIMIZE;
+        si.dwFlags = STARTF_USESHOWWINDOW;
+        si.wShowWindow = SW_MINIMIZE;
     }
     memset(&info, 0, sizeof(info));
 
@@ -263,8 +95,7 @@
         return INVALID_RUNCMD_RETURN;
     }
 
-    printf("Successfully ran command\n"); //%s - Created process handle %p\n",
-               //wine_dbgstr_w(szCmdLineExp), info.hProcess);
+    printf("Successfully ran command\n");
 
     if (wait)
     {   /* wait for the process to exit */
@@ -277,6 +108,7 @@
 
     return exit_code;
 }
+
 
 /**
  * Process a "Run" type registry key.
@@ -293,18 +125,18 @@
     static const WCHAR WINKEY_NAME[]={'S','o','f','t','w','a','r','e','\\',
         
'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
         'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
-    HKEY hkWin=NULL, hkRun=NULL;
-    LONG res=ERROR_SUCCESS;
-    DWORD i, nMaxCmdLine=0, nMaxValue=0;
-    WCHAR *szCmdLine=NULL;
-    WCHAR *szValue=NULL;
-
-    if (hkRoot==HKEY_LOCAL_MACHINE)
+    HKEY hkWin = NULL, hkRun=NULL;
+    LONG res = ERROR_SUCCESS;
+    DWORD i, nMaxCmdLine = 0, nMaxValue = 0;
+    WCHAR *szCmdLine = NULL;
+    WCHAR *szValue = NULL;
+
+    if (hkRoot == HKEY_LOCAL_MACHINE)
         wprintf(L"processing %s entries under HKLM\n", szKeyName);
     else
         wprintf(L"processing %s entries under HKCU\n", szKeyName);
 
-    if ((res=RegOpenKeyExW(hkRoot, WINKEY_NAME, 0, KEY_READ, 
&hkWin))!=ERROR_SUCCESS)
+    if ((res = RegOpenKeyExW(hkRoot, WINKEY_NAME, 0, KEY_READ, &hkWin)) != 
ERROR_SUCCESS)
     {
         printf("RegOpenKey failed on 
Software\\Microsoft\\Windows\\CurrentVersion (%ld)\n",
                 res);
@@ -312,14 +144,14 @@
         goto end;
     }
 
-    if ((res=RegOpenKeyExW(hkWin, szKeyName, 0, 
bDelete?KEY_ALL_ACCESS:KEY_READ, &hkRun))!=
+    if ((res = RegOpenKeyExW(hkWin, szKeyName, 0, 
bDelete?KEY_ALL_ACCESS:KEY_READ, &hkRun))!=
             ERROR_SUCCESS)
     {
-        if (res==ERROR_FILE_NOT_FOUND)
+        if (res == ERROR_FILE_NOT_FOUND)
         {
             printf("Key doesn't exist - nothing to be done\n");
 
-            res=ERROR_SUCCESS;
+            res = ERROR_SUCCESS;
         }
         else
             printf("RegOpenKey failed on run key (%ld)\n", res);
@@ -327,48 +159,48 @@
         goto end;
     }
 
-    if ((res=RegQueryInfoKeyW(hkRun, NULL, NULL, NULL, NULL, NULL, NULL, &i, 
&nMaxValue,
-                    &nMaxCmdLine, NULL, NULL))!=ERROR_SUCCESS)
+    if ((res = RegQueryInfoKeyW(hkRun, NULL, NULL, NULL, NULL, NULL, NULL, &i, 
&nMaxValue,
+                    &nMaxCmdLine, NULL, NULL)) != ERROR_SUCCESS)
     {
         printf("Couldn't query key info (%ld)\n", res);
 
         goto end;
     }
 
-    if (i==0)
+    if (i == 0)
     {
         printf("No commands to execute.\n");
 
-        res=ERROR_SUCCESS;
-        goto end;
-    }
-
-    if ((szCmdLine=malloc(nMaxCmdLine))==NULL)
+        res = ERROR_SUCCESS;
+        goto end;
+    }
+
+    if ((szCmdLine = malloc(nMaxCmdLine)) == NULL)
     {
         printf("Couldn't allocate memory for the commands to be executed\n");
 
-        res=ERROR_NOT_ENOUGH_MEMORY;
-        goto end;
-    }
-
-    if ((szValue=malloc((++nMaxValue)*sizeof(*szValue)))==NULL)
+        res = ERROR_NOT_ENOUGH_MEMORY;
+        goto end;
+    }
+
+    if ((szValue = malloc((++nMaxValue)*sizeof(*szValue))) == NULL)
     {
         printf("Couldn't allocate memory for the value names\n");
 
         free(szCmdLine);
-        res=ERROR_NOT_ENOUGH_MEMORY;
-        goto end;
-    }
-
-    while(i>0)
+        res = ERROR_NOT_ENOUGH_MEMORY;
+        goto end;
+    }
+
+    while(i > 0)
     {
         DWORD nValLength=nMaxValue, nDataLength=nMaxCmdLine;
         DWORD type;
 
         --i;
 
-        if ((res=RegEnumValueW(hkRun, i, szValue, &nValLength, 0, &type,
-                        (LPBYTE)szCmdLine, &nDataLength))!=ERROR_SUCCESS)
+        if ((res = RegEnumValueW(hkRun, i, szValue, &nValLength, 0, &type,
+                        (LPBYTE)szCmdLine, &nDataLength)) != ERROR_SUCCESS)
         {
             printf("Couldn't read in value %ld - %ld\n", i, res);
 
@@ -378,19 +210,19 @@
         /* safe mode - force to run if prefixed with asterisk */
         if (GetSystemMetrics(SM_CLEANBOOT) && (szValue[0] != L'*')) continue;
 
-        if (bDelete && (res=RegDeleteValueW(hkRun, szValue))!=ERROR_SUCCESS)
+        if (bDelete && (res = RegDeleteValueW(hkRun, szValue)) != 
ERROR_SUCCESS)
         {
             printf("Couldn't delete value - %ld, %ld. Running command 
anyways.\n", i, res);
         }
 
-        if (type!=REG_SZ)
+        if (type != REG_SZ)
         {
             printf("Incorrect type of value #%ld (%ld)\n", i, type);
 
             continue;
         }
 
-        if ((res=runCmd(szCmdLine, NULL, bSynchronous, 
FALSE))==INVALID_RUNCMD_RETURN)
+        if ((res = runCmd(szCmdLine, NULL, bSynchronous, FALSE)) == 
INVALID_RUNCMD_RETURN)
         {
             printf("Error running cmd #%ld (%ld)\n", i, GetLastError());
         }
@@ -400,17 +232,17 @@
 
     free(szValue);
     free(szCmdLine);
-    res=ERROR_SUCCESS;
+    res = ERROR_SUCCESS;
 
 end:
-    if (hkRun!=NULL)
+    if (hkRun != NULL)
         RegCloseKey(hkRun);
-    if (hkWin!=NULL)
+    if (hkWin != NULL)
         RegCloseKey(hkWin);
 
     printf("done\n");
 
-    return res==ERROR_SUCCESS?TRUE:FALSE;
+    return res == ERROR_SUCCESS ? TRUE : FALSE;
 }
 
  /// structure holding startup flags
@@ -424,8 +256,8 @@
 };
 
 static const struct op_mask
-       SESSION_START   = {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE},
-    SETUP                      = {FALSE, FALSE, FALSE, TRUE, TRUE, TRUE};
+    SESSION_START   = {FALSE, FALSE, TRUE, TRUE, TRUE, TRUE},
+    SETUP           = {FALSE, FALSE, FALSE, TRUE, TRUE, TRUE};
 #define DEFAULT SESSION_START
 
 int startup(int argc, const char *argv[])
@@ -439,12 +271,12 @@
 
     res = GetWindowsDirectory(gen_path, sizeof(gen_path));
 
-    if (res==0)
-    {
-               printf("Couldn't get the windows directory - error %ld\n",
-                       GetLastError());
-
-               return 100;
+    if (res == 0)
+    {
+        printf("Couldn't get the windows directory - error %ld\n",
+            GetLastError());
+
+        return 100;
     }
 
     if (!SetCurrentDirectory(gen_path))
@@ -487,31 +319,27 @@
             ops = DEFAULT;
             break;
         }
-    } else
+    }
+    else
         ops = DEFAULT;
 
     /* do not run certain items in Safe Mode */
-    if(GetSystemMetrics(SM_CLEANBOOT)) ops.startup = FALSE;
+    if (GetSystemMetrics(SM_CLEANBOOT)) ops.startup = FALSE;
 
     /* Perform the ops by order, stopping if one fails, skipping if necessary 
*/
-    /* Shachar: Sorry for the perl syntax */
     res = TRUE;
-    if (res && !ops.ntonly && ops.preboot)
-         res = wininit();
-    if (res && !ops.w9xonly && ops.preboot)
-         res = pendingRename();
     if (res && !ops.ntonly && ops.prelogin)
-         res = ProcessRunKeys(HKEY_LOCAL_MACHINE, 
runkeys_names[RUNKEY_RUNSERVICESONCE], TRUE, FALSE);
+        res = ProcessRunKeys(HKEY_LOCAL_MACHINE, 
runkeys_names[RUNKEY_RUNSERVICESONCE], TRUE, FALSE);
     if (res && !ops.ntonly && ops.prelogin && ops.startup)
-         res = ProcessRunKeys(HKEY_LOCAL_MACHINE, 
runkeys_names[RUNKEY_RUNSERVICES], FALSE, FALSE);
+        res = ProcessRunKeys(HKEY_LOCAL_MACHINE, 
runkeys_names[RUNKEY_RUNSERVICES], FALSE, FALSE);
     if (res && ops.postlogin)
-         res = ProcessRunKeys(HKEY_LOCAL_MACHINE, 
runkeys_names[RUNKEY_RUNONCE], TRUE, TRUE);
+        res = ProcessRunKeys(HKEY_LOCAL_MACHINE, 
runkeys_names[RUNKEY_RUNONCE], TRUE, TRUE);
     if (res && ops.postlogin && ops.startup)
-         res = ProcessRunKeys(HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUN], 
FALSE, FALSE);
+        res = ProcessRunKeys(HKEY_LOCAL_MACHINE, runkeys_names[RUNKEY_RUN], 
FALSE, FALSE);
     if (res && ops.postlogin && ops.startup)
-         res = ProcessRunKeys(HKEY_CURRENT_USER, runkeys_names[RUNKEY_RUN], 
FALSE, FALSE);
+        res = ProcessRunKeys(HKEY_CURRENT_USER, runkeys_names[RUNKEY_RUN], 
FALSE, FALSE);
     if (res && ops.postlogin && ops.startup)
-         res = ProcessRunKeys(HKEY_CURRENT_USER, 
runkeys_names[RUNKEY_RUNONCE], TRUE, FALSE);
+        res = ProcessRunKeys(HKEY_CURRENT_USER, runkeys_names[RUNKEY_RUNONCE], 
TRUE, FALSE);
 
     printf("Operation done\n");
 


Reply via email to