I would be very gratefull if someone could assistme with a script I'm trying to create. First let me give you a little back ground, we have an app that is used through out the company, this app's settings etc is controlled via settings in HKLM > Software > Policies >AppName, the company has decided it wants to update these settings by pushing out some new reg settings. After some testing it was found this was best done by deleting the old settings 1st of all and then apllying the new, to make matters more complicated we have a mix of Win XP and Win 7.
The script that I have hobbled together tries to do the following:
Check for the presence of a certain regkey to see if the script should be run (Regkey found at HKCU > Software >AppName. If the Reg key does not exists it should carry on, if it does the entire script should stop.
If the script is to continue check to see if client is XP or Win 7 by checking for the folder C:\Users and then run the appropriate commands.
Add the Regkey mentioned above so that the script does not run again.
on error resume next
Dim WSHShell, RNetKey, SetRNetRanValue, wshEnvironment, Folder, AppName1, AppName2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = CreateObject("WScript.Shell")
Set wshEnvironment = wshShell.Environment("System")
Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOSInfo = oWMIService.ExecQuery("Select * from Win32_OperatingSystem")
set shell = WScript.CreateObject("WScript.Shell")
RNetKey = "HKCU\Software\AppName\"
SetRNetRanValue = WSHShell.RegRead(RNetKey & "SetRNetRan")
AppName1 = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\AppName\"
AppName2 = "HKEY_CURRENT_USER\SOFTWARE\Policies\AppName\"
Set oshell = CreateObject("WScript.Shell")
strRegKey = oshell.RegRead ("HKCU\Software\AppName\")
If Err.Number <> 0 Then
If objFSO.FolderExists("C:\Users") Then
Set objShell = CreateObject("Shell.Application")
'Pass a bogus argument with leading blank space, say [ uac]
objShell.ShellExecute "wscript.exe", Chr(34) & _
WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
on error resume next
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.Run "regedit /s \\servername\install\AppName.reg"
WshShell.Run "regedit /s \\servername\install\AppName.reg"
if not SetRNetRanValue = "1" Then
'WScript.echo "SetRnetRan set"
Function RunSetRNetLocation( RNetKey)
'wscript.echo "SetRNetRan not set"
WshShell.RegWrite RNetKey, 0 ,"REG_SZ"
WSHShell.RegWrite RNetKey & "\" & "SetRNetRan", "1"