I am trying to write a computer startup script that will be pushed out
through group policy. I want to check if a key exist in the registry. If
it does then exit if not add the key.

I can run this from my desktop and it works but it doesnt have the if
statement.

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WSHShell.RegWrite
"HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Outlook\ForceFormReload",
1 ,"REG_DWORD"

I tried adding this for the if statement but its not working

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
IF
RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Outlook\ForceForm
Reload") <> "" Then
END IF
ELSE
WSHShell.RegWrite
"HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Outlook\ForceFormReload",
1 ,"REG_DWORD"

I am new to vbscript so this is a beginner question

Any help would be great thanks..

Re: computer startup script by Torgeir

Torgeir
Thu Apr 29 16:39:33 CDT 2004

Josh wrote:

> I am trying to write a computer startup script that will be pushed out
> through group policy. I want to check if a key exist in the registry. If
> it does then exit if not add the key.
Hi

Note that your script is working against a registry value
and not a key.

I use a function RegValueExists to test if a value exists
or not, here is a rewritten version of your script that
uses this function:



Dim WshShell, sRegValue
Set WshShell = CreateObject("WScript.Shell")

sRegValue = "HKLM\Software\Microsoft\Office\11.0\Outlook\ForceForm"

If Not RegValueExists(sRegValue) Then
WSHShell.RegWrite sRegValue, 1 ,"REG_DWORD"
End If


Function RegValueExists(sRegValue)
' Returns True or False based of the existence of a registry value.
Dim oShell, RegReadReturn
Set oShell = CreateObject("WScript.Shell")
RegValueExists = True ' init value
On Error Resume Next
RegReadReturn = oShell.RegRead(sRegValue)
If Err.Number <> 0 Then
RegValueExists = False
End if
On Error Goto 0
End Function



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/community/scriptcenter/default.mspx

Re: computer startup script by Josh

Josh
Thu Apr 29 17:47:09 CDT 2004

thank you so much.. That works great. I am new to vbscripting. I have been
using kixtart so I am now learning a new syntax. I just bought the windows
2000 scripting bible. Thanks again.

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:ewzePKjLEHA.1644@TK2MSFTNGP09.phx.gbl...
> Josh wrote:
>
> > I am trying to write a computer startup script that will be pushed out
> > through group policy. I want to check if a key exist in the registry.
If
> > it does then exit if not add the key.
> Hi
>
> Note that your script is working against a registry value
> and not a key.
>
> I use a function RegValueExists to test if a value exists
> or not, here is a rewritten version of your script that
> uses this function:
>
>
>
> Dim WshShell, sRegValue
> Set WshShell = CreateObject("WScript.Shell")
>
> sRegValue = "HKLM\Software\Microsoft\Office\11.0\Outlook\ForceForm"
>
> If Not RegValueExists(sRegValue) Then
> WSHShell.RegWrite sRegValue, 1 ,"REG_DWORD"
> End If
>
>
> Function RegValueExists(sRegValue)
> ' Returns True or False based of the existence of a registry value.
> Dim oShell, RegReadReturn
> Set oShell = CreateObject("WScript.Shell")
> RegValueExists = True ' init value
> On Error Resume Next
> RegReadReturn = oShell.RegRead(sRegValue)
> If Err.Number <> 0 Then
> RegValueExists = False
> End if
> On Error Goto 0
> End Function
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/community/scriptcenter/default.mspx



Re: computer startup script by Josh

Josh
Thu Apr 29 18:13:43 CDT 2004

I thought it might also be good to add something else in. The script should
check to make sure that the 11.0 folder is there. Some users have office
2000 and outlook 2003. So if they were not upgrade to outlook 2003 yet the
11.0 folder might not be there. This is what I thought I should use but it
doesnt work. Did I mis type something?

Again thanks



Dim WshShell, sRegValue,sRegKey
Set WshShell = CreateObject("WScript.Shell")


sRegKey = "HKLM\Software\Microsoft\Office\11.0"
sRegValue = "HKLM\Software\Microsoft\Office\11.0\Outlook\ForceFormReload"


If Not RegKey And RegValueExists(sRegValue) Then
WSHShell.RegWrite sRegValue, 1 ,"REG_DWORD"
End If


Function RegValueExists(sRegValue)
' Returns True or False based of the existence of a registry value.
Dim oShell, RegReadReturn
Set oShell = CreateObject("WScript.Shell")
RegValueExists = True ' init value
On Error Resume Next
RegReadReturn = oShell.RegRead(sRegValue)
If Err.Number <> 0 Then
RegValueExists = False
End if
On Error Goto 0
End Function


---------------------------------------------


"Josh" <josh.stinson@ipsos-na.com> wrote in message
news:%23U2mqvjLEHA.892@TK2MSFTNGP09.phx.gbl...
> thank you so much.. That works great. I am new to vbscripting. I have
been
> using kixtart so I am now learning a new syntax. I just bought the
windows
> 2000 scripting bible. Thanks again.
>
> "Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
> news:ewzePKjLEHA.1644@TK2MSFTNGP09.phx.gbl...
> > Josh wrote:
> >
> > > I am trying to write a computer startup script that will be pushed out
> > > through group policy. I want to check if a key exist in the registry.
> If
> > > it does then exit if not add the key.
> > Hi
> >
> > Note that your script is working against a registry value
> > and not a key.
> >
> > I use a function RegValueExists to test if a value exists
> > or not, here is a rewritten version of your script that
> > uses this function:
> >
> >
> >
> > Dim WshShell, sRegValue
> > Set WshShell = CreateObject("WScript.Shell")
> >
> > sRegValue = "HKLM\Software\Microsoft\Office\11.0\Outlook\ForceForm"
> >
> > If Not RegValueExists(sRegValue) Then
> > WSHShell.RegWrite sRegValue, 1 ,"REG_DWORD"
> > End If
> >
> >
> > Function RegValueExists(sRegValue)
> > ' Returns True or False based of the existence of a registry value.
> > Dim oShell, RegReadReturn
> > Set oShell = CreateObject("WScript.Shell")
> > RegValueExists = True ' init value
> > On Error Resume Next
> > RegReadReturn = oShell.RegRead(sRegValue)
> > If Err.Number <> 0 Then
> > RegValueExists = False
> > End if
> > On Error Goto 0
> > End Function
> >
> >
> >
> > --
> > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> > Administration scripting examples and an ONLINE version of
> > the 1328 page Scripting Guide:
> > http://www.microsoft.com/technet/community/scriptcenter/default.mspx
>
>



Re: computer startup script by Torgeir

Torgeir
Fri Apr 30 11:49:49 CDT 2004

Josh wrote:

> I thought it might also be good to add something else in. The script should
> check to make sure that the 11.0 folder is there. Some users have office
> 2000 and outlook 2003. So if they were not upgrade to outlook 2003 yet the
> 11.0 folder might not be there. This is what I thought I should use but it
> doesnt work. Did I mis type something?
>
> Again thanks
Hi

Here is a version that uses a function RegKeyExists to
see if the registry key HKLM\Software\Microsoft\Office\11.0
exists before doing anything:



Dim WshShell, sRegValue, sRegKey
Set WshShell = CreateObject("WScript.Shell")

sRegKey = "HKLM\Software\Microsoft\Office\11.0"
sRegValue = "HKLM\Software\Microsoft\Office\11.0\Outlook\ForceFormReload"

If RegKeyExists(sRegKey) And Not RegValueExists(sRegValue) Then
WSHShell.RegWrite sRegValue, 1 ,"REG_DWORD"
End If


Function RegValueExists(sRegValue)
' Returns True or False based of the existence of a registry value.
Dim oShell, RegReadReturn
Set oShell = CreateObject("WScript.Shell")
RegValueExists = True ' init value
On Error Resume Next
RegReadReturn = oShell.RegRead(sRegValue)
If Err.Number <> 0 Then
RegValueExists = False
End if
On Error Goto 0
End Function


Function RegKeyExists(ByVal sRegKey)
' Returns True or False based on the existence of a registry key.

Dim sDescription, oShell
Set oShell = CreateObject("WScript.Shell")

RegKeyExists = True
sRegKey = Trim (sRegKey)
If Not Right(sRegKey, 1) = "\" Then
sRegKey = sRegKey & "\"
End If

On Error Resume Next
oShell.RegRead "HKEYNotAKey\"
sDescription = Replace(Err.Description, "HKEYNotAKey\", "")

Err.Clear
oShell.RegRead sRegKey
RegKeyExists = sDescription <> Replace(Err.Description, sRegKey, "")
On Error Goto 0
End Function



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/community/scriptcenter/default.mspx