diff --git a/contrib/pg_autovacuum/README.pg_autovacuum b/contrib/pg_autovacuum/README.pg_autovacuum
index 88a8997b164cb06f975c038d370d8757813c647b..00da36db733147385aab5f20328d98e8ba96a762 100644
--- a/contrib/pg_autovacuum/README.pg_autovacuum
+++ b/contrib/pg_autovacuum/README.pg_autovacuum
@@ -163,12 +163,17 @@ The following arguments are used on Windows only:
    be stored in plain text.
 	     
 -N service user: Name of the Windows user account under which the service
-   will run.
+   will run. Only used when installing as a Windows service.
    
--W service password: The password for the service account.
+-W service password: The password for the service account.Only used when 
+   installing as a Windows service.
 
 -R Uninstall pg_autovacuum as a service.
 
+-E Dependent service that must start before this service. Normally this will be
+   a PostgreSQL instance, e.g. "-E pgsql-8.0.0". Only used when installing as 
+   a Windows service.
+
 Vacuum and Analyze:
 -------------------
 
diff --git a/contrib/pg_autovacuum/pg_autovacuum.c b/contrib/pg_autovacuum/pg_autovacuum.c
index c08911d6a6d83b324098ee074cdec0d74974630a..8053b647ce617b27395b3258e6bdb0dbe8d0daba 100644
--- a/contrib/pg_autovacuum/pg_autovacuum.c
+++ b/contrib/pg_autovacuum/pg_autovacuum.c
@@ -4,7 +4,7 @@
  * Revisions by Christopher B. Browne, Liberty RMS
  * Win32 Service code added by Dave Page
  *
- * $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v 1.26 2004/12/02 20:31:17 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.c,v 1.27 2004/12/02 22:48:10 momjian Exp $
  */
 
 #include "postgres_fe.h"
@@ -1100,7 +1100,7 @@ get_cmd_args(int argc, char *argv[])
 #ifndef WIN32
 	while ((c = getopt(argc, argv, "s:S:v:V:a:A:d:U:P:H:L:p:hDc:C:m:n:l:")) != -1)
 #else
-	while ((c = getopt(argc, argv, "s:S:v:V:a:A:d:U:P:H:L:p:hIRN:W:c:C:m:n:l:")) != -1)
+	while ((c = getopt(argc, argv, "s:S:v:V:a:A:d:U:P:H:L:p:hIRN:W:E:c:C:m:n:l:")) != -1)
 #endif
 	{
 		switch (c)
@@ -1165,6 +1165,9 @@ get_cmd_args(int argc, char *argv[])
 				usage();
 				exit(0);
 #ifdef WIN32
+			case 'E':
+				args->service_dependencies = optarg;
+				break;
 			case 'I':
 				args->install_as_service++;
 				break;
@@ -1216,6 +1219,7 @@ usage(void)
 	fprintf(stderr, "   [-R] Remove as a Windows service (all other options will be ignored)\n");
 	fprintf(stderr, "   [-N] Username to run service as (only useful when installing as a Windows service)\n");
 	fprintf(stderr, "   [-W] Password to run service with (only useful when installing as a Windows service)\n");
+	fprintf(stderr, "   [-E] Dependent service that must start before this service (only useful when installing as a Windows service)\n");
 #endif
 	i = AUTOVACUUM_DEBUG;
 	fprintf(stderr, "   [-d] debug (debug level=0,1,2,3; default=%d)\n", i);
@@ -1273,6 +1277,8 @@ print_cmd_args(void)
 	log_entry(logbuffer, LVL_INFO);
 	sprintf(logbuffer, "  args->remove_as_service=%d", args->remove_as_service);
 	log_entry(logbuffer, LVL_INFO);
+	sprintf(logbuffer, "  args->service_dependencies=%s", (args->service_dependencies) ? args->service_dependencies : "(null)");
+	log_entry(logbuffer, LVL_INFO);
 	sprintf(logbuffer, "  args->service_user=%s", (args->service_user) ? args->service_user : "(null)");
 	log_entry(logbuffer, LVL_INFO);
 	sprintf(logbuffer, "  args->service_password=%s", (args->service_password) ? args->service_password : "(null)");
@@ -1385,7 +1391,7 @@ InstallService()
 							   szFilename,		/* Service binary */
 							   NULL,	/* No load ordering group */
 							   NULL,	/* No tag identifier */
-							   NULL,	/* Dependencies */
+							   args->service_dependencies,	/* Dependencies */
 							   args->service_user,		/* Service account */
 							   args->service_password); /* Account password */
 
@@ -1406,11 +1412,11 @@ InstallService()
 	if (args->port)
 		sprintf(szCommand, "%s -p %s", szCommand, args->port);
 	if (args->user)
-		sprintf(szCommand, "%s -U %s", szCommand, args->user);
+		sprintf(szCommand, "%s -U \"%s\"", szCommand, args->user);
 	if (args->password)
-		sprintf(szCommand, "%s -P %s", szCommand, args->password);
+		sprintf(szCommand, "%s -P \"%s\"", szCommand, args->password);
 	if (args->logfile)
-		sprintf(szCommand, "%s -L %s", szCommand, args->logfile);
+		sprintf(szCommand, "%s -L \"%s\"", szCommand, args->logfile);
 	if (args->sleep_base_value != (int) SLEEPBASEVALUE)
 		sprintf(szCommand, "%s -s %d", szCommand, args->sleep_base_value);
 	if (args->sleep_scaling_factor != (float) SLEEPSCALINGFACTOR)
diff --git a/contrib/pg_autovacuum/pg_autovacuum.h b/contrib/pg_autovacuum/pg_autovacuum.h
index 02933fbc82dcdcc7dbf9c3ef621ceffcba0e5cbc..d9e476ed6a9ce9bfb18c000b896a63eb86ca0f09 100644
--- a/contrib/pg_autovacuum/pg_autovacuum.h
+++ b/contrib/pg_autovacuum/pg_autovacuum.h
@@ -2,7 +2,7 @@
  * Header file for pg_autovacuum.c
  * (c) 2003 Matthew T. O'Connor
  *
- * $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.h,v 1.13 2004/11/17 16:54:15 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pg_autovacuum/pg_autovacuum.h,v 1.14 2004/12/02 22:48:10 momjian Exp $
  */
 
 #ifndef _PG_AUTOVACUUM_H
@@ -68,6 +68,7 @@ typedef struct cmdargs
 	char	   *user,
 			   *password,
 #ifdef WIN32
+			   *service_dependencies,
 			   *service_user,
 			   *service_password,
 #endif