Solved

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

Posted on 2004-09-27
5
155 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 63
Copy a row 12 75
Visual Studio 2005 text editor 10 54
Prevent user closing word document opened with VB6 6 88
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

737 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