How to make a dynamic file name?



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.


.



Relevant Pages

  • Re: How to make a dynamic file name?
    ... Boolean value that indicates whether you can overwrite an ... iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys) ... HKLM, sBaseKey & sKey, "DisplayName", sValue) ... HKLM, sBaseKey & sKey, "QuietDisplayName", sValue ...
    (microsoft.public.scripting.vbscript)
  • Re: Need to create and print a Software Inventory
    ... "Kernaa" wrote in message ... iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys) ... HKLM, sBaseKey & sKey, "DisplayName", sValue) ... HKLM, sBaseKey & sKey, "QuietDisplayName", sValue ...
    (microsoft.public.windows.mediacenter)
  • Re: Need to create and print a Software Inventory
    ... iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys) ... HKLM, sBaseKey & sKey, "DisplayName", sValue) ... HKLM, sBaseKey & sKey, "QuietDisplayName", sValue ...
    (microsoft.public.windows.mediacenter)
  • Re: Need to create and print a Software Inventory
    ... iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys) ... HKLM, sBaseKey & sKey, "DisplayName", sValue) ... HKLM, sBaseKey & sKey, "QuietDisplayName", sValue ...
    (microsoft.public.windows.mediacenter)
  • Re: Win32_Product doesnt list all installed Applications
    ... For Each sKey In arSubKeys ... iRC = oRegistry.GetStringValue(HKLM, sBaseKey & sKey, "DisplayName", sValue) ... oRegistry.GetStringValue HKLM, sBaseKey & sKey, "QuietDisplayName", sValue ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter/default.mspx. ...
    (microsoft.public.windows.server.scripting)