使用vbs更改系统的区域/位置设置 [英] Change the system Region/Location setting using vbs

查看:248
本文介绍了使用vbs更改系统的区域/位置设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以协助我进行查询.

I was wondering if perhaps somebody could assist with a query I have.

每周一次,我需要从美国对方处获取文件,我需要将其本地保存到我的机器上,并更改文件格式.此后,我创建了一个可以执行SaveAs例程并将其保存的VBScript,但是,为了将日期格式保留为美国,我必须在该过程之前和之后将控制面板中的地区"设置更改为美国",然后再更改为默认本地.设置.

Once a week i get file from my US counterpart that i need to save locally to my machine, and change the format of the file. I have since created a VBScript that can perform a SaveAs routine and save it, however in order to retain the date formats in US, I am having to change my Region setting to US in control panel before the procedure and after to change to default local setting.

我一直在对此进行研究,并且从Microsoft网站获得了一些想法,这些想法显示了如何使用Set Locale和Get locale,但是我的代码似乎并没有实际更改任何内容,即使它执行没有错误.

I have been researching this and got some ideas from the Microsoft site that shows how to use the Set Locale and Get locale, but my code doesnt seem to actually change anything, even though it executes without error.

有人可以给我一些指示吗...

Can somebody please give me some pointers...

option explicit
dim currentLocale
currentLocale = GetLocale()

SetLocale 1033       ' 1033 is the EN-US locale

' Revert back to the default system locale
SetLocale currentLocale

推荐答案

Option Explicit

'Define a key registry path
Dim strComputer
Dim objRegistry
Dim strKeyPath
Dim strValueName
Dim getValue
Dim regKeyPath
Dim strLocaleName, strCountry, strshortDateValue, strlongDateValue, strshortTimeValue, strlongTimeValue, strfirstDayOfWeekValue

Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
regKeyPath = "Control Panel\International"

strLocaleName = "en-US" 
strCountry = "United States" 
strshortDateValue = "M/d/yyyy"
strlongDateValue = "dddd, MMMM d, yyyy"
strshortTimeValue = "h:mm tt"
strlongTimeValue = "h:mm:ss tt"
strfirstDayOfWeekValue = "6"

objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "LocaleName", strLocaleName
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sCountry", strCountry
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sShortDate", strshortDateValue
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sLongDate", strlongDateValue
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sShortTime", strshortTimeValue
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sTimeFormat", strlongTimeValue
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "iFirstDayOfWeek", strfirstDayOfWeekValue


WScript.Echo "Successfully changed system regional settings."

此脚本将更改注册表中的区域设置.请谨慎使用.它将更改为US,因此,如果您打算使用此脚本,请确保在更改默认设置之前知道默认设置是什么.仅还原控制面板"中的设置将不起作用.

This script will change your regional settings in registry. Use with caution. This will change to US, so if you intend on using this script, make sure you know what the default settings are before you change them. Merely reverting the settings in Control Panel will not work.

以下脚本将再次将所有内容更改回英国.

The script below will change everything back to UK again.

Option Explicit

'Define a key registry path
Dim strComputer
Dim objRegistry
Dim strKeyPath
Dim strValueName
Dim getValue
Dim regKeyPath
Dim strLocaleName, strCountry, strshortDateValue, strlongDateValue, strshortTimeValue, strlongTimeValue, strfirstDayOfWeekValue

Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
regKeyPath = "Control Panel\International"

strLocaleName = "en-GB" 
strCountry = "United Kingdom" 
strshortDateValue = "dd/MM/yyyy"
strlongDateValue = "dd MMMM yyyy"
strshortTimeValue = "HH:mm"
strlongTimeValue = "HH:mm:ss"
strfirstDayOfWeekValue = "0"

objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "LocaleName", strLocaleName
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sCountry", strCountry
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sShortDate", strshortDateValue
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sLongDate", strlongDateValue
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sShortTime", strshortTimeValue
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "sTimeFormat", strlongTimeValue
objRegistry.SetStringValue HKEY_CURRENT_USER, regKeyPath, "iFirstDayOfWeek", strfirstDayOfWeekValue


WScript.Echo "Successfully changed system regional settings."

这篇关于使用vbs更改系统的区域/位置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆