VBScript Error : 0, 0000h
Posted: Wed May 30, 2012 8:54 pm
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
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