RE: unknown error when trying to write to text file
- From: Salvador Manaois III <SalvadorManaoisIII@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 14 Oct 2008 06:40:03 -0700
Hi,
You can try to modify the script at the part where the error is occurring
with these lines:
Set objOut =
objFSO.CreateTextFile("c:\Windows\temp\RegChanges\regValues.txt",2)
Else
Set objTextFile =
objFSO.OpenTextFile("c:\Windows\temp\RegChanges\regValues.txt", 8)
--
Salvador Manaois III
MCSE MCSA CEH MCITP | Enterprise/Server Admin
Bytes & Badz : http://badzmanaois.blogspot.com
"Tony Logan" wrote:
I'm stumped. I wrote a script that runs locally on a single PC to examine.
some registry values. If it finds a value that isn't set to "C:\", it writes
out the reg key, value, and data string to a text file, then changes the
registry value to "C:\".
If all the reg values are set to "C:\", nothing happens. Otherwise, the code
creates a folder and a text file and records any of the above-noted changes.
The code works fine if none of the reg values are C, and it also works for
the first non-C reg value it finds, writing the correct info to the text file.
My problem happens when more than one of the reg values are set to non-C.
When the code gets to the line instructing it to open the text file for
writing, I get the error "Permission denied: the remote server has been
paused or is in the process of being started." Which is a new one to me. The
PC I'm testing on isn't a server, just a normal desktop.
Here's the code. The line that throws the error is in the WriteToReg
subroutine; I'll note it with a comment.
Option Explicit
Dim objShell, objFSO, objTextFile, objComputer, objRegistry, objFolder
Dim strComputer, strComputerName, strKeyPath, strValueName, strValue
Dim bInfoToLog
' set constant for registry hive we want to examine
Const HKEY_LOCAL_MACHINE = &H80000002
' set constant for writing to text file we create
Const ForWriting = 8
' set variable for local PC
strComputer = "."
' connect to the WMI service and the StdRegProv class
Set objRegistry = GetObject("winmgmts:\\" & strComputer &
"\root\default:StdRegProv")
' define the reg keys and check values for anything not "C:\"
strKeyPath =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0FA989645BF32964F92B4D36DCF0D4E6"
strValueName = "40314C93E12538E4FA096CA6C4515B0F"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If Not IsNull(strKeyPath) Then ' if strKeyPath is not IsNull, then the reg
key exists
' Check value of strValue. If it's not "C:\", write some info to text file
we created above.
If strValue <> "C:\" Then
WriteToReg(True)
' now set the value to "C:\"
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0FA989645BF32964F92B4D36DCF0D4E6\40314C93E12538E4FA096CA6C4515B0F",
"C:\", "REG_SZ"
End If
End If
strKeyPath =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\4A4860479B387C34E8F64F4AFA7F4119"
strValueName = "40314C93E12538E4FA096CA6C4515B0F"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If Not IsNull(strKeyPath) Then ' if strKeyPath is not IsNull, then the reg
key exists
' Check value of strValue. If it's not "C:\", write some info to text file
we created above.
If strValue <> "C:\" Then
WriteToReg(True)
' now set the value to "C:\"
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\4A4860479B387C34E8F64F4AFA7F4119\40314C93E12538E4FA096CA6C4515B0F",
"C:\", "REG_SZ"
End If
End If
strKeyPath =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\1A7686356A1ADD44ABD5A2E599CDADD7"
strValueName = "40314C93E12538E4FA096CA6C4515B0F"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If Not IsNull(strKeyPath) Then ' if strKeyPath is not IsNull, then the reg
key exists
' Check value of strValue. If it's not "C:\", write some info to text file
we created above.
If strValue <> "C:\" Then
WriteToReg(True)
' now set the value to "C:\"
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\1A7686356A1ADD44ABD5A2E599CDADD7\40314C93E12538E4FA096CA6C4515B0F",
"C:\", "REG_SZ"
End If
End If
strKeyPath =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\28C3E705BBDE11D498D34073621939FA"
strValueName = "40314C93E12538E4FA096CA6C4515B0F"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If Not IsNull(strKeyPath) Then ' if strKeyPath is not IsNull, then the reg
key exists
' Check value of strValue. If it's not "C:\", write some info to text file
we created above.
If strValue <> "C:\" Then
WriteToReg(True)
' now set the value to "C:\"
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\28C3E705BBDE11D498D34073621939FA\40314C93E12538E4FA096CA6C4515B0F",
"C:\", "REG_SZ"
End If
End If
strKeyPath =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0890D7F67CBC50041961B45BDD582B46"
strValueName = "40314C93E12538E4FA096CA6C4515B0F"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If Not IsNull(strKeyPath) Then ' if strKeyPath is not IsNull, then the reg
key exists
' Check value of strValue. If it's not "C:\", write some info to text file
we created above.
If strValue <> "C:\" Then
WriteToReg(True)
' now set the value to "C:\"
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\0890D7F67CBC50041961B45BDD582B46\40314C93E12538E4FA096CA6C4515B0F",
"C:\", "REG_SZ"
End If
End If
Public Sub WriteToReg (bInfoToLog)
If bInfoToLog = True Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
' check if folder exists. If not, create it.
If Not objFSO.FolderExists("c:\Windows\temp\RegChanges") Then
Set objFolder = objFSO.CreateFolder("c:\Windows\temp\RegChanges")
End If
' check if we've already created the text file. If not,
' create it so we can write the reg values to it
If Not objFSO.FileExists("c:\Windows\temp\RegChanges\regValues.txt") Then
Set objTextFile =
objFSO.CreateTextFile("c:\Windows\temp\RegChanges\regValues.txt")
Else 'otherwise the file exists, so just open it for writing
'NEXT LINE BELOW THROWS THE ERROR
Set objTextFile = objFSO.OpenTextFile
("c:\Windows\temp\RegChanges\regValues.txt", ForWriting)
End If
' write info to the file
objTextFile.WriteLine Now
objTextFile.WriteLine "Key: " & strKeypath
objTextFile.WriteLine "Value: " & strValueName
objTextFile.WriteLine "Data: " & strValue
objTextFile.WriteLine "= = = = = = = = = = = = = = = = = ="
objTextFile.WriteBlankLines(1)
End If
End Sub
WScript.Quit
- Follow-Ups:
- RE: unknown error when trying to write to text file
- From: Tony Logan
- RE: unknown error when trying to write to text file
- References:
- unknown error when trying to write to text file
- From: Tony Logan
- unknown error when trying to write to text file
- Prev by Date: unknown error when trying to write to text file
- Next by Date: Re: VBScript not working as it should
- Previous by thread: unknown error when trying to write to text file
- Next by thread: RE: unknown error when trying to write to text file
- Index(es):
Relevant Pages
|