I have developed a program (1) coded in batch named info.bat:
Store information about a computer,
Manipulates information and outputs details to %ComputerName%.csv file.
Then a .vbs file (2) is called, and this outputs a list of installed programs to %ComputerName%-programs.txt file in the same directory as the .csv file.
The batch file ends when the .vbs has finished, and user is shown a Cmd window ready for next command.
Next another program StripSoftware.bat (3) is manually started:
It creates %ComputerName%-programs-to-check.txt,
Adds OS version and %ComputerName%,
Examines entries in %ComputerName%-programs.txt,
Takes out unwanted matches (using findstr and switches),
Removes empty lines,
Sorts results ascending,
Then puts them into %ComputerName%-programs-to-check.txt
Aim:
I need to use the software entries (1 line per software name) in %ComputerName%-programs-to-check.txt, concatenate them together, then put them into the software_needed column in the .csv file.
Output:
The output needed is a .csv file or preferably an .xlsx file with the following headers in the 1st row, and applicable information in the 2nd row.
.csv example:
v34,ID,Asset,Sys_Type,Model,NHC Asset,New Sys Type,New Model,New Sys Asset,Domain,DIR,Site,Team,Location,Post,Name,Postcode,Local Printers,Network Printers,Eth_MACs,Wifi_MACs,Phone_MAC,Software Needed,OTHER_ASSET,OS_VER,Hostname,Software_Notes,Other_Notes,IGEL_REC
,,ABCDEFG,PC,A123,,,,,XXXX,Unknown,,,,,,, , ,||"XX-XX-XX-XX-XX-XX"|"Disabled",,,Not Used,ABCDEFG,Win XP Pro,ABCDEFG,,,
Partial contents of info.bat:
#echo OFF
setlocal enableextensions enabledelayedexpansion
SET file="%~dp0%computername%.csv"
If Exist %file% Del %file%
echo %Version_tool%,ID,Asset,Sys_Type,Model,NHC Asset,New Sys Type,New Model,New Sys Asset,Domain,DIR,Site,Team,Location,Post,Name,Postcode,Local Printers,Network Printers,Eth_MACs,Wifi_MACs,Phone_MAC,Software Needed,OTHER_ASSET,OS_VER,Hostname,Software_Notes,Other_Notes,IGEL_REC>>%file%
rem ========= Other code =========
echo ,%ID%,%serialnumber%,PC,%model%,,,,,%userdomain%,Unknown,,,,,,,%Local_Printers%,!network_printers!,!Eth_MACs!,!Wifi_MACs!,!Phone_MACs!,Not Used,%system%,%osname%,%Hostname%,,,%IGEL REC%>> %file%
SET file2="%~dp0%computername%-programs.txt"
If Exist %file2% Del %file2%
start /b cmd /k "cscript //nologo programs_02.vbs >> %file2%"
echo Batch Tool should finish in a few seconds ...
Contents of .vbs file:
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry2 = "InstallDate"
strEntry3 = "VersionMajor"
strEntry4 = "VersionMinor"
strEntry5 = "EstimatedSize"
Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
WScript.Echo "Installed Applications" & VbCrLf
For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, strEntry1a, strValue1)
If intRet1 <> 0 Then
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry1b, strValue1
End If
If strValue1 <> "" Then
WScript.Echo VbCrLf & strValue1
End If
objReg.GetStringValue HKLM, strKey & strSubkey, strEntry2, strValue2
If strValue2 <> "" Then
'WScript.Echo "Install Date: " & strValue2
End If
objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry3, intValue3
objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry4, intValue4
If intValue3 <> "" Then
WScript.Echo "Version: " & intValue3 & "." & intValue4
End If
objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry5, intValue5
If intValue5 <> "" Then
'WScript.Echo "Estimated Size: " & Round(intValue5/1024, 3) & " megabytes"
End If
Next
Problem:
With current way the code is structured info.bat creates .csv file before the .txt files are created and values for Software_Needed (eg Adobe Flash | Hotfix for Windows) is available in %ComputerName%-programs-to-check.txt. Hence difficult to then update the .csv with the value for Software_Needed on the second row.
Proposed solution: (*)
I'm beginning to think the .vbs file should be called first to create %ComputerName%-programs.txt in the first .bat file, then in a second .bat file have the functionality in StripSoftware.bat to create %ComputerName%-programs-to-check.txt, and then use that and other information to create %ComputerName%.csv
Questions:
1) Would appreciate peoples thoughts, comments and views on the Proposed Solution
2) Suggestions as to better solutions than the proposed Solution.
It's unclear what you want. This is a standard post of mine. Then I'll show you something.
Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste). Type for table format
wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:htable
or in a form format
wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:hform
It will create a html file on the desktop.
Note
This is not a full list. This is only products installed with Windows Installer. There is no feature for everything.
However as I said in my previous post nearly everything is listed in the registry.
So to see it in a command prompt
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s
or in a file
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s>"%userprofile%\desktop\WindowsUninstall.txt"
To see it in notepad in a different format
Click Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type Regedit and navigate to
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Right click the Uninstall key and choose Export. If you save as a reg file (there is also text file, they are slightly different text formats) you need to right click the file and choose Edit to view it.
To view Windows Updates
wmic /output:"%userprofile%\desktop\WindowsUpdate.html" qfe get /format:htable
Here is a VBS script that get installed programs, sorts, and filters.
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set rs = CreateObject("ADODB.Recordset")
Set wshshell = CreateObject("wscript.shell")
Set Outp = Wscript.Stdout
ComputerName=WshShell.ExpandEnvironmentStrings("%Computername%")
'Build database with Computername and Softwarename
With rs
.Fields.Append "ComputerName", 201, 5000
.Fields.Append "Txt", 201, 5000
.Open
'Get list installed programs
Set colItems = objWMIService.ExecQuery("Select * From Win32_Product")
'Add to database
For Each objItem in colItems
.AddNew
.Fields("ComputerName").value = ComputerName
.Fields("Txt").value = objItem.Name
.UpDate
Next
'Sort Database on software name
'Sort and filter it - Softwarename acending (Txt) and filter only those starting M
.Sort = "Txt ASC"
.Filter = "Txt like 'm*'"
'write out to a CSV
Do While not .EOF
Outp.writeline .Fields("ComputerName").Value & "," & .Fields("Txt").Value
.MoveNext
Loop
End With
To use
cscript //nologo <path to vbs file> > OUTPUTFILE
This is the output
SERENITY,Microsoft .NET Framework 1.1
SERENITY,Microsoft .NET Framework 3.5 SP1
SERENITY,Microsoft .NET Framework 4 Client Profile
SERENITY,Microsoft .NET Framework 4 Extended
SERENITY,Microsoft Application Compatibility Toolkit 5.0
SERENITY,Microsoft Application Error Reporting
SERENITY,Microsoft Calculator Plus
SERENITY,Microsoft Device Emulator version 3.0 - ENU
SERENITY,Microsoft Document Explorer 2005
SERENITY,Microsoft Filter Pack 1.0
SERENITY,Microsoft LifeCam
SERENITY,Microsoft Mathematics
SERENITY,Microsoft Network Monitor 3.0
SERENITY,Microsoft Office XP Professional
SERENITY,Microsoft OpenType Font File Properties Extension
SERENITY,Microsoft Search Enhancement Pack
So there are three places where you can discard items. In the WMI select.
Set colItems = objWMIService.ExecQuery("Select * from Win32_Product where Name='Microsoft LifeCam'")
And also in the filter as shown above using similar syntax.
Also while writing it back you can compare it then and not write the ones you don't want.
I'm exporting from an Access DB via VBscript and want to try using a Schema.ini file. I have a batch program that fires off a vbscript file that opens the Access DB and does the export. My vbscript filename is export.vbs.
If I have:
DoCmd.TransferText acExportDelim, "", "table", "C:\output\table.csv"
I notice while the export is happening a file gets automatically created "export.ini".
If I have
DoCmd.TransferText acExportDelim, "Schema.ini", "table", "C:\output\table.csv"
I get an error talking about "The text file spec 'Schema.ini" does not exist." even though in the same directory this is all happening in I have a Schema.ini file there. What am I missing?
Thanks!
You need to go about it a different way ( Create comma separated file (csv) from access - scheduled daily from windows )
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=z:\Docs\test.accdb"
sSQL = "select * into "
sSQL= sSQL & "[text;database=z:\docs\;FMT=Delimited;HDR=Yes].[csvfile.csv]"
sSQL= sSQL & " from table1"
cn.Execute sSQL
I have a personal DB app that was initially designed using the mdb format in Access 2007. For security reasons I've converted it to .accdb. All functions converted fine except the change DB password function. This function is done in VBA because the Db has all the tool bars turned off. In mdb format... this works fine
DBPath = [CurrentProject].[FullName]
' Create connection string by using current password.
strOpenPwd = ";pwd=" & OldPswd
' Open database for exclusive access by using current password. To get
' exclusive access, you must set the Options argument to True.
Set dbsDB = OpenDatabase(Name:=DBPath, _
Options:=True, _
ReadOnly:=False, _
Connect:=strOpenPwd)
' Set or change password.
With dbsDB
.NewPassword OldPswd, Pswd2
.Close
End With
Me.DB_Pswd = Pswd2
Set dbsDB = Nothing
I found something from this very forum that comes close for the .accdb but it only works for another .accdb file not the current project....
strAlterPassword = "ALTER DATABASE PASSWORD [" & NwPswd& "] [" & OldPswd & "];"
Set ADO_Cnnct = New adodb.Connection
With ADO_Cnnct
.Mode = adModeShareExclusive
.Provider = "Microsoft.ACE.OLEDB.12.0"
' Use old password to establish connection
.Properties("Jet OLEDB:Database Password") = OldPswd
'name current DB
DBPath = [CurrentProject].[FullName] <- this does not work: get a file already in use error
.Open "Data Source= " & DBPath & ";"
' Execute the SQL statement to change the password.
.Execute (strAlterPassword)
End With
'Clean up objects.
ADO_Cnnct.Close
Set ADO_Cnnct = Nothing
So is there a way to do this in VBA for .accdb files? Basically it would be automating the tool bar function of first Decrypt and the encrypt with a new password. I know the tool bar can do so I know there must be a VBA way to do it.
I found the fix for this or maybe just a work around. By removing the ADO library the first method will work for .Accde format files. It will not work for the .accdb format file, but you don't want to distribute those anyway.
I have read every question on this site having to do with SaveAsText (and other version-control-with-Access related questions).
The most helpful one so far was this one. I am using a slightly modified version of the VBScript code posted in Oliver's answer to save my objects as text files. My application is an .adp, and the database (which obviously includes the Stored Procedures) is SQL Server 2005.
I have attempted to add this code to my VBScript, but I consistently get an error that says "You have cancelled the previous operation" when the SaveAsText line is hit.
For Each myObj In oApplication.CurrentData.AllStoredProcedures
WScript.Echo " " & myObj.fullname
oApplication.SaveAsText acQuery, _
myObj.fullname, _
sExportpath & "\" & myObj.fullname & ".sql"
dctDelete.Add "RE" & myObj.fullname, acQuery
Next
Based on the response in this question, I made sure to add
Const acQuery = 1
to the top of the file.
Also, this code
For i = 0 To oApplication.CurrentDatabase.QueryDefs.Count - 1
oApplication.SaveAsText acQuery, _
oApplication.CurrentDatabase.QueryDefs(i).Name, _
sExportpath & "\" & db.QueryDefs(i).Name & ".sql"
Next i
did not work, but I believe that was intended for a .mdb anyway, not an .adp. Is there any solution for exporting StoredProcedures (and Views or Table definitions, while we're at it) to text files?
It probably doesn't have anything to do with mdb vs adp. When I try the following in an mdb, I get the same error message.
MsgBox Application.CurrentData.AllStoredProcedures.Count
I suspect that it is doing that because MS Access doesn't know the underlying structure of the SQL database is. And really, why should it care, and why would the DB tell your app what it looks like under the covers? The stored procedures run entirely on the DB side and knows nothing about the MS Access app, and the views are just that a view (or presentation of) the data. As far as I know, you can't manipulate either from within MS Access.
What I think you are trying to do is automate an export of the sql scripts necessary to recreate your database, and store them in some sort of version control system. The folks on Serverfault might have a convenient solution for that.
As for SaveAsText, unfortunately it is an undocumented method. I've used the following for exporting Queries
''...
Dim db As Database
Set db = CurrentDb()
Dim Qry As QueryDef
For Each Qry In db.QueryDefs
strObjectName = Qry.Name
If Not (strObjectName Like "~sq_*") Then
Debug.Print " - " & strObjectName
Application.SaveAsText acQuery, strObjectName, _
MY_PATH & "queries_" & strObjectName & ".txt"
End If
Next
''...
TableDef's were a little different (couldn't get SaveAsText/LoadAsText to work properly)
For Each Tbl In db.TableDefs
If Tbl.Attributes = 0 Then 'Ignores System Tables
strObjectName = Tbl.Name
Debug.Print " - " & strObjectName
Application.ExportXML acExportTable, strObjectName, , _
MY_PATH & "tables_" & strObjectName & ".xsd"
End If
Next
I have a few data sources in access that I need to connect to programatically to do things with behind the scenes and keep visibility away from users.
Said datasource has a password 'pass' as I'm going to call it here. Using this connection method I get an error attempting to use the open method
Dim conn as ADODB.Connection
Set ROBBERS.conn = New ADODB.Connection
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=\\pep-home\projects\billing\autobilling\DPBilling2.mdb;" _
& "Jet OLEDB:Database Password=pass;", "admin", "pass"
"Cannot start your application. The workgroup information file is missing or opened exclusively by another user."
Due to planning to move into 2007, we are not using nor have ever used a workgroup identification file through access. The database password on the data source was set through the Set Databa Password which had to be done on an exclusive open.
Ive spent a good while changing around my connection options, where to put the passwords etc and either cannot find the right format, or (why I'm asking here) I think there may be some other unknown that I must setup to do this. Anyone out there got some useful information?
Your connection string seems to be incorrect. Try:
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=\\pep-home\projects\billing\autobilling\DPBilling2.mdb;" _
& "Jet OLEDB:Database Password=MyDbPassword;"
-- http://www.connectionstrings.com/access