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

sstretchhAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

exx1976Commented:
In Vista you're likely having difficult with UAC...
0
sstretchhAuthor Commented:
well it executes and goes away, UAC never pops up.
0
TakedaTCommented:
Do you get the InputBox popup?  Your line 3 is actually 2 statements.  It should be seperated by a : or put on seperate lines.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

sstretchhAuthor Commented:
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
0
TakedaTCommented:
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

0
pcfreakerCommented:
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.
0
TakedaTCommented:
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.
0
sstretchhAuthor Commented:
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.
0
pcfreakerCommented:
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

0
sstretchhAuthor Commented:
commond box popped up really fast then went away, but the value for SCForceOption is still 1
0
pcfreakerCommented:
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.
0
pcfreakerCommented:
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

0
sstretchhAuthor Commented:
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.
0
pcfreakerCommented:
Here is a MSDN guide to ussing UAC with programs and scripts
 http://msdn.microsoft.com/en-us/library/aa826699(VS.85).aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sstretchhAuthor Commented:
So it's going to be a pain to get that registry value to change with UAC on then ?
0
sstretchhAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.