Link to home
Start Free TrialLog in
Avatar of sstretchh
sstretchhFlag for United States of America

asked on

Help with VB Script to work in Vista

Hello Everyone,
I'm just starting out with scripting and was passed along a script to override using a Common Access Card to log into a network account.  

The registry information I am trying to change is:  HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\system\sforceoption

I'm trying to get a script to change the DWord Value from 1 to 0.

This the script I've been trying to modify in the original format sent to me:

' Region Description
' Name: CAC Enforcement Disable
' Author: Timothy B. Hayden
' Version: 2.0 GD
' Description: Disables machine base CAC enforcement ' EndRegion



Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = InputBox("Enter Computer Name.", "CAC Enforcement Disable") If strComputer = "" Then
    WScript.Quit
End If

Set oReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Policies\system\"
 
strValueName = "SCForceOption"
dwValue = 0
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

Open in new window

Avatar of exx1976
exx1976
Flag of United States of America image

In Vista you're likely having difficult with UAC...
Avatar of sstretchh

ASKER

well it executes and goes away, UAC never pops up.
Avatar of TakedaT
Do you get the InputBox popup?  Your line 3 is actually 2 statements.  It should be seperated by a : or put on seperate lines.
I don't get a input just the CMD window and it goes away really fast. where should i put the : ?

This script is designed and works in XP with no problem, trying to see if I can tweak it to work in Vista
I dont see how it would work the way you have it, XP or Vista.  It should error out on line 3.  Try this.
Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = InputBox("Enter Computer Name.", "CAC Enforcement Disable") 
If strComputer = "" Then
    WScript.Quit
End If

Set oReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Policies\system\"
 
strValueName = "SCForceOption"
dwValue = 0
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

Open in new window

Do you have any output error?
Try it directly from a vista computer, run a CMD then type cscript nameofthescript and then you will be able to see any error.
Let me know.
Rgds.
Also, is this script run locally, or from a remote machine?  If it is run locally, then you can just skip the whole inputbox part.  I just tested it on my vista pc and it worked fine, though I have UAC disabled completely.
The purpose of the script is to run remotely, I just tried the script u posted takeD on this computer, I get the POP box asking for the computer name but it doesn't change the value of
Software\Microsoft\Windows\CurrentVersion\Policies\system\

strValueName = "SCForceOption" from 1 to 0.


We have UAC turned on and by policy we can not turn it off.
Try this code
 

Const HKEY_LOCAL_MACHINE = &H80000002 
 
Set objNetwork = CreateObject("WScript.Network")

strComputer = objNetwork.ComputerName

Set objComputer = _
    GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
    strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" _
    & strComputer & "'")

 
Set oReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv") 
  
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Policies\system\" 
  
strValueName = "SCForceOption" 
dwValue = 0 
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

Open in new window

commond box popped up really fast then went away, but the value for SCForceOption is still 1
Indeed, what the script does is create the new key and set its initial value, it does not edit it. Let me write that option on it.
Use this one.
 

Const HKEY_LOCAL_MACHINE = &H80000002  
  
Set objNetwork = CreateObject("WScript.Network") 
 
strComputer = objNetwork.ComputerName 
 
Set objComputer = _ 
    GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _ 
    strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" _ 
    & strComputer & "'") 
 
  
Set oReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")  
   
strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system"  
   
strValueName = "SCForceOption"  
dwValue = 1  
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

Rem Change key if it exists
Dim objShell, RegLocate

Rem Libraries
Set objShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
Rem Change DWORD value (Registry key change value)

RegLocate = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system"
objShell.RegWrite RegLocate,"1","REG_DWORD"

Open in new window

yeap, that didn't change the value at all either.

UAC is on so I don't know if that is going to make a difference, we can't turn it off.
ASKER CERTIFIED SOLUTION
Avatar of pcfreaker
pcfreaker
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So it's going to be a pain to get that registry value to change with UAC on then ?
I gave this answer a C since I was given the links to read for myself, the scripts that where posted by the experts did not work for me.

I have UAC turned on and its something I can not turn off because of policy.