VBScript Error : 0, 0000h

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 11 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
bigsheddy5
Posts: 2
Last visit: Wed May 30, 2012 9:46 pm

VBScript Error : 0, 0000h

Post by bigsheddy5 »

Hi, I have a script I am trying to use in querying the registry of remote computers to copy the LocaleName to a network share. I am testing the script but gets an error: 0, 0000h. Been trying to no avail to debug the error. please someone help; plus I am newbie to vbscripting. the script is shown below:


Option Explicit
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText, WshShell, objNetwork
strDirectory = "Win2008r2NetworkshareQuery"
strFile = "Locale.txt"
strText = " "

On Error Resume Next

'The Bit that Queries the Registry for User Locale Settings
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objNetwork = wscript.CreateObject("wscript.network")
WshShell.Run "cmd /c reg query " & Chr(34) & "hkcucontrol panelinternational" & Chr(34) & " /v "_
& Chr(34) & "LocaleName" & Chr(34) & " > " & "Win2008r2NetworkshareLocaleQuery" & objNetwork.Username & ".txt"


' Catch Error here...
if err.number = 0 Then
set strText = strText & "Script completed successfully"
WScript.Echo "Script completed successfully"
else if Err.Number <> 0 then
' An exception occurred
Set strText = strText & "Exception:" & " Error number: " & Err.Number & " Error description: " & Err.Description
Err.Clear
WScript.echo strText
End If

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " & strDirectory
End If

If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
Wscript.Echo "Just created " & strDirectory & strFile
End If

set objFile = nothing
set objFolder = Nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8

Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, ForAppending, True)

' Appends strText which holds the error values every time you run this VBScript

objTextFile.WriteLine(strText)
objTextFile.Close

' Bonus or cosmetic section to launch explorer to check file
If err.number = vbEmpty then
Set objShell = CreateObject("WScript.Shell")
objShell.run ("Explorer" &" " & strDirectory & "" )
objShell.run ("Explorer.exe" &" " & "Win2008r2Networkshare" & objNetwork.Username & ".txt" )
Else WScript.echo " Textfile Append Unsuccessful.."
WScript.Quit
End If



End If
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

VBScript Error : 0, 0000h

Post by jvierra »

Your code does not make a lot of sense. Start by describing what it is you are trying to do.

It is impossibel to get an error 0 in vbscript. The error is coming from something else like the reg command because you are giving it a bad commandline.

Code: Select all

cmd = "cmd /c reg query ""hkcucontrol panelinternational"" /v LocaleName > Win2008r2NetworkshareLocaleQuery" & objNetwork.Username & ".txt"
WshShell.Run cmd
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

VBScript Error : 0, 0000h

Post by jvierra »

Try it like this:

Code: Select all

Const strRootFolder = "Win2008r2NetworkshareLocaleQuery"
Set oNet = wscript.CreateObject("WScript.Network") 
sFileName= strRootFolder & oNet.Username & ".txt"
' get local from registry - no error because this would mean Windows is corrupt and it would not be running
Set shell = CreateObject("WScript.Shell")
locale = shell.RegRead("HKCUcontrol panelinternationallocale")
WScript.Echo  "[ & Now & ] User:" & oNet.Username & " Locale:" & locale
'write to file
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next  ' possibel error on open or create
Set file = fso.OpenTextFile(sFileName,8,True)
If Err Then
    WScript.Echo Err.Description
    WScript.Quit -1
Else
    On Error GoTo 0  ' always turn errors back on
    file.Write locale
    file.Close
End If

# - fixed typosjvierra2012-05-31 04:39:44
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

VBScript Error : 0, 0000h

Post by jvierra »

I just fixed the code I posted above. I had some typos that needed help.
User avatar
bigsheddy5
Posts: 2
Last visit: Wed May 30, 2012 9:46 pm

VBScript Error : 0, 0000h

Post by bigsheddy5 »

ok, i got you.

I need to know the various locale settings for various users in different locations to enable us understand the different OS locale settings acrossdifferent branch office location for subsequent OS upgrade configuration.

So i intend to run the script remotely but first need to make sure it works correctly.

Thanks.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

VBScript Error : 0, 0000h

Post by jvierra »

Here is another morsel that may be easier to understand.

Code: Select all

	
gwmi win32_operatingsystem -computer pc002 ,pc003, pc004 |
     select csname, registereduser,locale, oslanguage|ft -auto
	
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

VBScript Error : 0, 0000h

Post by jvierra »

Why would you use teh registry from a batch file when WMI is all set uyp to do this remotely and is much easier to script.

PowerSHell also has all of the primitives for converting and reporting on locale.

You answer also has nothing to do with teh question. It is a batch file to get values of McAfee ePO. The question isj about determining the locale of a machine.

The whole point of the discussion is to note that using REF is an unreliable methood.. Theregie=try locations for these thngs can change from OS to OS. Using WMI is far more reliable.

ALso the issue of reading the specific users locale is not addressed.

An example of using a remote registry script from VBScritp and using REG to the requested key were also given so it is not clear why you would post a reference to the McAfee key.
This topic is 11 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked