Solved

I need to know how to turn on and configure Automatic Windwos Update for Windows

Posted on 2004-09-27
5
156 Views
Last Modified: 2011-09-20
My vb6 code needs to do the following:
1. determine if Auto update is turned on or not
2. be able to turn it on programmatically.

Looking for information regarding, but would prefer some sample code.

I am already familiar with the following links:
--http://www.sanx.org/tipShow.asp?articleRef=115
--http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wua_sdk/wua/portal_client.asp

...If you want to look at those articles and give me code that does the 2 things listed above, that would suffice.

thanks!

0
Comment
Question by:apm825
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 12165539
This should do it.

Dim wshShell As New wshShell
wshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\NoAutoUpdate", 0, "REG_DWORD"
wshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\AUOptions", 3, "REG_DWORD"
wshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\ScheduledInstallDay", 0, "REG_DWORD"
wshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\ScheduledInstallTime", 3, "REG_DWORD"
set wshShell = Nothing

This link takes you to a page that spells out what the individual values do.
http://www.winguides.com/registry/display.php/1176/
0
 

Author Comment

by:apm825
ID: 12165788
I'm not sure if I'll be able to do early binding, do you know the full prog id?

If I can, what is the reference library name?
0
 
LVL 76

Accepted Solution

by:
David Lee earned 300 total points
ID: 12165852
If you want to use late binding then use this instead:

    Dim wshShell As Object
    Set wshShell = CreateObject("Wscript.Shell")

Set a reference in your project to "Windows Script Host Object Model"
0
 
LVL 4

Assisted Solution

by:avi247
avi247 earned 200 total points
ID: 12165918
'Ref: http://www.sanx.org/tipShow.asp?articleRef=115
'HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU

'# Data Type: DWORD
'Value Name: NoAutoUpdate
'Value: 0 or 1
'
'    * 0: Automatic Updates are enabled (default)
'    * 1: Automatic Updates are disabled
'

'# Data Type: DWORD
'Value Name: AUOptions
'Value: 1 through 4
'
'    * 1: Automatic Updates are disabled
'    * 2: Notify of download and installation
'    * 3: Automatically download and notify of installation
'    * 4: Automatically download and scheduled installation
'
Option Explicit

  Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal lngRootKey As Long) As Long
 
  Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
            (ByVal lngRootKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
 
  Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
            (ByVal lngRootKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
 
  Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
            (ByVal lngRootKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
             lpType As Long, lpData As Any, lpcbData As Long) As Long
 
  Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" _
            (ByVal lngRootKey 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_LOCAL_MACHINE As Long = &H80000002
Private Const REG_DWORD As Long = 4

Private Sub Form_Load()
Dim lngKeyRoot As Long
Dim strKeyPath As String
Dim strSubKey As String
Dim lngKeyHandle As Long
Dim lngReturn As Long
Dim lngValue As Long
 
 lngKeyRoot = HKEY_LOCAL_MACHINE
 strKeyPath = "Software\Policies\Microsoft\Windows\WindowsUpdate\AU"
 strSubKey = "NoAutoUpdate"
 lngKeyHandle = 0
  If DoesKeyExist(lngKeyRoot, strKeyPath) Then
    lngReturn = RegOpenKey(lngKeyRoot, strKeyPath, lngKeyHandle)
    lngReturn = RegQueryValueEx(lngKeyHandle, strSubKey, 0&, REG_DWORD, lngValue, 4&)
    If lngValue = 0 Then ' its enabled
        ' do whatever you want
        GoTo CloseReg:
    Else
        ' turn it on
        lngReturn = RegSetValueEx(lngKeyHandle, strSubKey, 0&, REG_DWORD, 0, 4&)
    End If
 Else
    ' create a key and enable AU
    lngReturn = RegCreateKey(lngKeyRoot, strKeyPath, lngKeyHandle)
   
    'set a value
    lngReturn = RegSetValueEx(lngKeyHandle, strSubKey, 0&, REG_DWORD, 1, 4&)
 End If
 
 'set up Auto Update Configuration Keys e.g.AUOPTIONS
  strSubKey = "AUOptions"
  lngReturn = RegSetValueEx(lngKeyHandle, strSubKey, 0&, REG_DWORD, 2, 4&)
 
 
CloseReg:
 'close the registry
 lngReturn = RegCloseKey(lngKeyHandle)
End Sub


Private Function DoesKeyExist(ByVal KeyRoot As Long, ByVal KeyPath As String) As Boolean
  Dim lngKey As Long
  Dim blnKeyExists As Boolean
  Dim lngReturn As Long
 
  lngReturn = RegOpenKey(KeyRoot, KeyPath, lngKey)
  If lngKey = 0 Then 'key does not exist
      DoesKeyExist = False
  Else
      DoesKeyExist = True
  End If
 
   
End Function

0
 

Author Comment

by:apm825
ID: 12166083
I wanted to award avi247 some of the points since I may have to use straight win32 api instead of WSH in case the client does not have it installed or enabled.

Thank you very much. Both answers were great and will help me very much!!

Now my problem is the registry keys that article was talking about isn't exactly what I needed. If you're interested, I've created another question under Window OS: http://www.experts-exchange.com/Operating_Systems/WinXP/Q_21147297.html - worth 500pts
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question