• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

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

0
sstretchh
Asked:
sstretchh
  • 7
  • 5
  • 3
  • +1
1 Solution
 
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
 
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

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 7
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now