Is it possible to set regional settings for a process through VB script?
Dim oEnv: Set oEnv = WshShell.Environment("PROCESS")
oEnv.Item("NLS_LANG") = "AMERICAN_AMERICA.WE8MSWIN1252"
This is one bit of code I got. Not sure how it works though? I would like to set the standards and formats for my application specifically to United States from United Kingdom.
Thanks
Nishant
Your computer uses environment variables to remember certain internal settings for applications. You can view them by pressing Windows key (flag) + Pause/Break, selecting the Advanced tab, pressing the Environments Variables button and look into the System Variables section.
With the WshShell.Environment object, you can read and write these variables:
Option Explicit
dim wshshell, EnvVar
set WshShell = WScript.CreateObject("WScript.Shell")
Dim oEnv: Set oEnv = WshShell.Environment("PROCESS")
' This shows you all environment variables in your system:
For each EnvVar in oEnv
msgbox EnvVar
Next
' This shows you a particular environment variable:
msgbox oEnv.item("OS")
' And this sets a particular environment variable:
oEnv.Item("NLS_LANG") = "AMERICAN_AMERICA.WE8MSWIN1252"
NLS_LANG is a setting used by Oracle and sets the cultural settings. By setting it to AMERICAN_AMERICA.WE8MSWIN1252 you tell your Oracle implementation what kind of culture you want to use on your specific system (remember, environment variables are per PC). You can find more information about that on the net.
This needs to be set in the registry. The registry path you use differs depending upon the version you are using.
For Oracle version 7:
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE
Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\ORACLE"
strValueName = "NLS_LANG"
strValue = "AMERICAN_AMERICA.WE8MSWIN1252"
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
For Oracle Database versions 8, 8i and 9i:
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMEx\
where "x" is the unique number identifying the Oracle home.
HOME0 is the first installation
Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\ORACLE\HOMEx"
strValueName = "NLS_LANG"
strValue = "AMERICAN_AMERICA.WE8MSWIN1252"
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
For Oracle Database 10g:
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_
Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\ORACLE\KEY_<oracle_home_name>"
strValueName = "NLS_LANG"
strValue = "AMERICAN_AMERICA.WE8MSWIN1252"
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
Related
How to check the version of oracle provider for ole-db. OraOLEDB.Oracle provider on windows 10 and windows 7 ?
You can use for example tool RegDllView. Search for "OraOLEDB", result could be this:
A simpler approach would be this navigate to your ORACE_HOME\bin directory and locate file OraOLEDB??.dll. Check version with right-hand mouse click -> Properties -> Details.
However, you just get the version of the file, it does not necessarily mean that this DLL is also registered and ready for use.
Or use this VBScript:
Option Explicit
Const HKEY_CLASSES_ROOT = &H80000000
Dim Key, strComputer, objRegistry, strPath, arrKeys, fso
Dim strKeyPath, strValueName, strValue, uValue, ver
Set fso = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objRegistry.enumKey HKEY_CLASSES_ROOT, "CLSID", arrKeys
For Each key In arrKeys
strKeyPath = "CLSID\" & key
strValueName = "OLEDB_SERVICES"
If objRegistry.GetDWordValue (HKEY_CLASSES_ROOT, strKeyPath, strValueName, uValue) = 0 Then
'get the (Default) value which is the name of the provider
objRegistry.GetStringValue HKEY_CLASSES_ROOT, strKeyPath, "", strValue
If InStr(1, strValue, "OraOLEDB.Oracle", vbTextCompare) > 0 Then
' get expanded location
objRegistry.GetStringValue HKEY_CLASSES_ROOT, strKeyPath & "\InprocServer32", "", strPath
ver = fso.GetFileVersion(strPath)
Wscript.Echo strValue & " # " & strPath & " -> " & ver
End If
End If
Next
OLE DB provider may exist in 32-bit or/and in 64-bit, so you may execute the script twice:
C:\Windows\System32\cscript.exe Print_OLE.vbs
C:\Windows\SysWOW64\cscript.exe Print_OLE.vbs
This is my VBS code:
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strKeyPath
Dim objReg, strSubkey, arrSubkeys
Dim Name, Version
strComputer = "."
' Registry key path of Control panel items for installed programs
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
'Enumerate registry keys.
For Each strSubkey In arrSubkeys
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & strSubkey, "DisplayName" , Name
If Name <> "" Then
WScript.Echo Name&""&","
End If
Next
WScript.Echo "Installed Programs listed successfully through Registry using VBScript."
WScript.Quit
It will give all software name list. But I want only those software which are visible in Programs and Features in the Control Panel.
You can use shell with KNOWNFOLDERID of Programs and Features.
This gives you the exact list you see on the control panel.
Set Shell = CreateObject("Shell.Application")
Set Programs = Shell.NameSpace("shell:::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}")
For Each item In Programs.Items
WScript.Echo item
Next
I want to add trusted web sites to the windows registry for all users using a VBScript. I currently have a script with me and its given below. I'm neither a Windows guy nor a Visual Basic guy, so I have absolutely no idea whether the script would run or not and would it meet my needs or not. Could someone please explain the script and check whether would it run as expected.
On Error Resume Next
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & _
"\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\EscDomains\google.com"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\EscDomains\google.com\www"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strValueName = "https"
dwValue = 2
objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\Domains\google.com"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\Domains\google.com\www"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strValueName = "https"
dwValue = 2
objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\EscDomains\hotmail.com"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strValueName = "https"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" _
& "ZoneMap\Domains\hotmail.com"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
strValueName = "https"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
If you feel this is an inappropiate script, please share the VBScript which you feel that would work.
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Your script is adding to current user, not all users as you said you need. Will multiple real users be logging into that machine?
The keys you need are:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\<website>.com]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\<website>.com\www]
"http"=dword:00000002
You could create a .reg file with above information for the websites and run it (put "Windows Registry Editor Version 5.00" at the top of that .reg file)
As has already been indicated, some quality time on Google will definitely enhance your knowledge of what the script you posted is trying to do and how to modify it. Don't hesitate to ask any specific (as opposed very general) questions.
I can't use VB Script to create registry keys. I've hecked WMI using wbemtest and I am running the script using administrative privileges. I beleive the code is correct - I've seen several sample on the internet and it seems to be straight forward. Is there anything else within the OS that could prevent a VB Script from creating registry keys?
Sample code is below.
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "ostslhqe-48958"
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\TestKey"
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath
strKeyPath = "SOFTWARE\Script Center"
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath
An example of registry entry creation would be:
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strValueName = "My DWORD Value"
dwValue = 13
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
Source : http://blogs.technet.com/b/heyscriptingguy/archive/2006/11/16/how-can-i-create-a-new-registry-key.aspx
I have the following code. I am trying to get the information on whether or not the remote computer I am connecting to is 32-bit or 64 bit. I tried doing it at the last snippet of this code but it didn't work. Here is the error (I changed the remote system name):
WshShell.RegRead: Invalid root in registry key
"\*remotesystem*\HKEY_LOCAL_MACHINE\SYSTEM\CurrentCon
trolSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE".
Option Explicit
Dim objWMISrvc,strRemoteComputer,colOSItems,objItem,args,OsType
'String variables
Dim strName,strCaption,strVersion,strCSDVer,strSerial,WshShell
'Adding this in to transfer FQDN variable to this script from ASP.net
Set args = WScript.Arguments
strRemoteComputer = args.Item(0)
Set objWMISrvc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strRemoteComputer & "\root\cimv2")
CheckOSType objWMISrvc
Sub CheckOSType( objWMISrvc )
Set colOSItems = objWMISrvc.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colOSItems
strName = objItem.CSName
'strDesc = objItem.Description
'strManufac = objItem.Manufacturer
strCaption = objItem.Caption
strVersion = objItem.Version
strCSDVer = objItem.CSDVersion
strSerial = objItem.SerialNumber
Next
Set WshShell = CreateObject("WScript.Shell")
OsType = WshShell.RegRead("\\" & strRemoteComputer & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
If OsType = "x86" then
WScript.Echo "Windows 32bit system detected"
elseif OsType = "AMD64" then
WScript.Echo "Windows 64bit system detected"
end if
End Sub
You can do this directly from WMI without reading the registry. Just loop through your computer names with this script. It returns either "32" or "64".
strComputer = "."
Set objWMIService = GetObject("winmgmt:\\" & strComputer & "\root\cimv2")
Set colProcessors = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objProcessor in colProcessors
WScript.Echo objProcessor.AddressWidth 'or objProcessor.DataWidth
Exit For
Next
To read the registry of as remote machine you must use the the StdRegProv WMI class
Check this sample
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
strValueName = "PROCESSOR_ARCHITECTURE"
oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,OsType
WScript.Echo OsType