How to make a dynamic file name?
- From: "John Smith" <jon@xxxxxxxxxxx>
- Date: Mon, 13 Mar 2006 19:03:57 -0800
I have a simple script that does what I want except that it saves the file
as a predetermined static name each time it's run.
I need to change it so it gets the computer name, adds it to the output and
also saves the file as the "computername."txt so each time it runs on a
different machine it would be easy to identify which machine it came from
without having to manually rename the file.
Here is the code:
Const OpenAsASCII = 0 ' Opens the file as ASCII (TristateFalse)
Const OverwriteIfExist = -1
' file where result is to be saved
sFile = "c:\apps.txt"
sComputer = "." ' use . for local computer
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set fFile = oFSO.CreateTextFile(sFile, _
OverwriteIfExist, OpenAsASCII)
fFile.Write InstalledApplications(sComputer)
fFile.Close
Function InstalledApplications(node)
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Set oRegistry = _
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& node & "/root/default:StdRegProv")
sBaseKey = _
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys)
For Each sKey In arSubKeys
iRC = oRegistry.GetStringValue( _
HKLM, sBaseKey & sKey, "DisplayName", sValue)
If iRC <> 0 Then
oRegistry.GetStringValue _
HKLM, sBaseKey & sKey, "QuietDisplayName", sValue
End If
If sValue <> "" Then
InstalledApplications = _
InstalledApplications & sValue & vbCrLf
End If
Next
End Function
What would need to change so the results are saved as the name of the
computer it ran on instead of apps.txt or any other static name?I searched
around the Microsoft scripting site and could not find an understandable
answer. I found another script there that did a similar software inventory,
except it had even worse output. It outputted to pop-up dialog boxes
instead a written file.
.
- Follow-Ups:
- Re: How to make a dynamic file name?
- From: Fosco
- Re: How to make a dynamic file name?
- Prev by Date: Re: Enumerate ODBC Data Sources on all computers and write to file
- Next by Date: Re: Help with script
- Previous by thread: Connect to db via VBScript?
- Next by thread: Re: How to make a dynamic file name?
- Index(es):
Relevant Pages
|