Compare commits

...

4 Commits

Author SHA1 Message Date
0a81086722
Update README.md 2025-03-07 21:55:42 +01:00
299e807e8a
Update README.md 2025-03-07 21:54:13 +01:00
bdb9f412a1 README updates 2025-03-07 21:40:22 +01:00
6599e17a18 neue version für .net framework 4.6.2
unterstützung für app.config
2025-03-07 21:05:03 +01:00
13 changed files with 223 additions and 72 deletions

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
VisualStudioVersion = 17.12.35527.113
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProgrammList", "ProgrammList\ProgrammList.csproj", "{06D431CD-A938-4DFD-8D77-4C612FDAD914}"
EndProject
@ -15,8 +15,8 @@ Global
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.Build.0 = Release|Any CPU
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|x64.ActiveCfg = Debug|x64
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|x64.Build.0 = Debug|x64
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.PrgmList|Any CPU.ActiveCfg = PrgmList|Any CPU

View File

@ -1,17 +0,0 @@
using System.Configuration;
namespace ProgrammList.ConfigManager {
public class ConfigManager {
public static string GetSetting(string key) {
return ConfigurationManager.AppSettings[key];
}
public static void SetSetting(string key, string value) {
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
configuration.AppSettings.Settings[key].Value = value;
configuration.Save(ConfigurationSaveMode.Full, true);
ConfigurationManager.RefreshSection("appSettings");
}
}
}

View File

@ -0,0 +1,37 @@
using System;
using System.Configuration;
using System.IO;
namespace ProgrammList.ConfigManager {
public static class PrmListConfigManager {
public static string GetSetting(string key) {
try {
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
Console.WriteLine("Loading " + Directory.GetCurrentDirectory() + "\\app.conf");
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
return config.AppSettings.Settings[key].Value;
}
catch (Exception e) {
Console.WriteLine("Error on Key " + key + ": " + e.ToString());
Console.WriteLine(e.ToString());
}
return "13";
}
public static void SetSetting(string key, string value) {
try {
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
Console.WriteLine("Loading " + Directory.GetCurrentDirectory() + "\\app.conf");
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
config.AppSettings.Settings["key"].Value = value;
}
catch (Exception e) {
Console.WriteLine("Error on Key " + key + ": " + e.ToString());
Console.WriteLine(e.ToString());
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -1,12 +1,13 @@
using ProgrammList.ConfigManager;
using ProgrammList.ListPrograms;
using System;
class Program {
public static void Main(string[] args) {
string dbType = ConfigManager.GetSetting("DB_Type");
ListPrograms list = new ListPrograms(dbType);
string dbType = PrmListConfigManager.GetSetting("DB_Type");
ListPrograms list = new ListPrograms();
list.init();
Console.WriteLine("Deleting old data");
list.DeleteOldData();
string keyname1 = "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstal";

View File

@ -2,13 +2,16 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<Platforms>AnyCPU;x64</Platforms>
<Configurations>Debug;Release;PrgmList</Configurations>
</PropertyGroup>
<ItemGroup>
<Content Include="Icons\prm_icon\back-end.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.2" />
@ -16,5 +19,29 @@
<PackageReference Include="MySql.Data" Version="9.2.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net462</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<AssemblyName>ProgramList</AssemblyName>
<ApplicationIcon>Icons\prm_icon\back-end.ico</ApplicationIcon>
<StartupObject>Program</StartupObject>
</PropertyGroup>
</Project>

View File

@ -1,15 +1,20 @@
using Microsoft.Win32;
using ProgrammList.ConfigManager;
using ProgrammList.sql;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
namespace ProgrammList.ListPrograms {
internal class ListPrograms {
public class ListPrograms {
string prgm_path = Directory.GetCurrentDirectory() + "\\";
string[] keyvaluenames = { "DisplayName", "DisplayVersion", "InstallDate" };
private SqlBase sql = null;
internal ListPrograms(string sqlType) {
public void init() {
string sqlType = PrmListConfigManager.GetSetting("DB_Type");
if (sqlType == null) {
Console.WriteLine("SQL Database not defined in app.conf, allowed types:");
Console.WriteLine("MYSQL");
@ -30,12 +35,12 @@ namespace ProgrammList.ListPrograms {
}
}
internal void DeleteOldData() {
public void DeleteOldData() {
sql.CheckTableExists();
sql.DeleteOldData(Dns.GetHostName());
}
internal void createList(string hkey, string bit) {
public void createList(string hkey, string bit) {
RegistryKey key = Registry.LocalMachine.OpenSubKey(hkey);
try {
if (key == null) {
@ -56,11 +61,11 @@ namespace ProgrammList.ListPrograms {
count++;
}
result = String.Join("", value.ToArray());
if (result.EndsWith(",")) {
result = result.Remove(result.Length - 1);
}
// result = String.Join("", value.ToArray());
//
// if (result.EndsWith(",")) {
// result = result.Remove(result.Length - 1);
// }
value.Add("PCID", "'" + Dns.GetHostName() + "'");
value.Add("update_date", "'" + DateTime.Now + "'");

View File

@ -1,6 +1,8 @@

using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
namespace ProgrammList.sql {
public class Mssql : SqlBaseAbstract {
@ -46,6 +48,8 @@ namespace ProgrammList.sql {
Open(DB.MSSQL);
var command = sqlcon.CreateCommand();
command.CommandText = "select case when exists (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'prgmlist' AND TABLE_NAME = 'list') then 1 else 0 end";
Console.WriteLine("Executing: " + command.CommandText);
var returncode = command.ExecuteScalar();
if (returncode != null) {
int rc;
@ -76,7 +80,9 @@ namespace ProgrammList.sql {
string result = "";
for (int i = 0; i < valuenames.Length; i++) {
result += valuesqlCommand.GetValueOrDefault(valuenames[i]);
string val = "";
valuesqlCommand.TryGetValue(valuenames[i], out val);
result += val;
if (i < valuenames.Length - 1) {
result += ",";
@ -96,7 +102,13 @@ namespace ProgrammList.sql {
}
public void InsertOrUpdateData(Dictionary<string, string> value) {
if (GetSingleLine(value.GetValueOrDefault("PCID"), value.GetValueOrDefault("DisplayName"), value.GetValueOrDefault("DisplayVersion"))) {
string pcid = "";
value.TryGetValue("PCID", out pcid);
string displayName = "";
value.TryGetValue("DisplayName", out displayName);
string displayVersion = "";
value.TryGetValue("DisplayVersion", out displayVersion);
if (GetSingleLine(pcid, displayName, displayVersion)) {
UpdateData(value);
}
else {
@ -120,7 +132,9 @@ namespace ProgrammList.sql {
string result = "set ";
for (int i = 0; i < valuenames.Length; i++) {
result += valuenames[i] + " = " + value.GetValueOrDefault(valuenames[i]);
string val = "";
value.TryGetValue(valuenames[i], out val);
result += valuenames[i] + " = " + val;
if (i < valuenames.Length - 1) {
result += " ,";
@ -128,15 +142,23 @@ namespace ProgrammList.sql {
}
sqlCommand = sqlCommand + result;
sqlCommand = sqlCommand + " WHERE PCID = " + value.GetValueOrDefault("PCID") +
" and DisplayName like " + value.GetValueOrDefault("DisplayName") +
" and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
string pcid = "";
value.TryGetValue("PCID", out pcid);
string displayName = "";
value.TryGetValue("DisplayName", out displayName);
string displayVersion = "";
value.TryGetValue("DisplayVersion", out displayVersion);
sqlCommand = sqlCommand + " WHERE PCID = " + pcid +
" and DisplayName like " + displayName +
" and DisplayVersion like " + displayVersion;
var command = new SqlCommand(sqlCommand, sqlcon, transaction);
for (int i = 0; i < valuenames.Length; i++) {
if (valuenames[i] != "PCID") {
command.Parameters.AddWithValue("$" + valuenames[i], value.GetValueOrDefault(valuenames[i]));
string itemValue = "";
value.TryGetValue(valuenames[i], out itemValue);
command.Parameters.AddWithValue("$" + valuenames[i], itemValue);
}
}
Console.WriteLine(sqlCommand);

View File

@ -1,9 +1,11 @@
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
namespace ProgrammList.sql {
internal class Mysql : SqlBaseAbstract {
public class Mysql : SqlBaseAbstract {
public Boolean GetSingleLine(string pcid, string program, string version) {
@ -40,7 +42,9 @@ namespace ProgrammList.sql {
string result = "";
for (int i = 0; i < valuenames.Length; i++) {
result += valuesqlCommand.GetValueOrDefault(valuenames[i]);
string val = "";
valuesqlCommand.TryGetValue(valuenames[i], out val);
result += val;
if (i < valuenames.Length - 1) {
result += ",";
@ -48,7 +52,7 @@ namespace ProgrammList.sql {
}
var cols = String.Join(",", valuenames);
var cols = string.Join(",", valuenames);
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
@ -60,7 +64,13 @@ namespace ProgrammList.sql {
}
public void InsertOrUpdateData(Dictionary<string, string> value) {
if (GetSingleLine(value.GetValueOrDefault("PCID"), value.GetValueOrDefault("DisplayName"), value.GetValueOrDefault("DisplayVersion"))) {
string pcid = "";
value.TryGetValue("PCID", out pcid);
string displayName = "";
value.TryGetValue("DisplayName", out displayName);
string displayVersion = "";
value.TryGetValue("DisplayVersion", out displayVersion);
if (GetSingleLine(pcid, displayName, displayVersion)) {
UpdateData(value);
}
else {
@ -75,7 +85,9 @@ namespace ProgrammList.sql {
string result = "set ";
for (int i = 0; i < valuenames.Length; i++) {
result += valuenames[i] + " = " + value.GetValueOrDefault(valuenames[i]);
string val = "";
value.TryGetValue(valuenames[i], out val);
result += valuenames[i] + " = " + val;
if (i < valuenames.Length - 1) {
result += " ,";
@ -83,15 +95,23 @@ namespace ProgrammList.sql {
}
sqlCommand = sqlCommand + result;
sqlCommand = sqlCommand + " WHERE PCID = " + value.GetValueOrDefault("PCID") +
" and DisplayName like " + value.GetValueOrDefault("DisplayName") +
" and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
string pcid = "";
value.TryGetValue("PCID", out pcid);
string displayName = "";
value.TryGetValue("DisplayName", out displayName);
string displayVersion = "";
value.TryGetValue("DisplayVersion", out displayVersion);
sqlCommand = sqlCommand + " WHERE PCID = " + pcid +
" and DisplayName like " + displayName +
" and DisplayVersion like " + displayVersion;
var command = new MySqlCommand(sqlCommand, mysqlcon, transaction);
for (int i = 0; i < valuenames.Length; i++) {
if (valuenames[i] != "PCID") {
command.Parameters.AddWithValue("$" + valuenames[i], value.GetValueOrDefault(valuenames[i]));
string itemValue = "";
value.TryGetValue(valuenames[i], out itemValue);
command.Parameters.AddWithValue("$" + valuenames[i], itemValue);
}
}
Console.WriteLine(sqlCommand);

View File

@ -1,19 +1,23 @@
namespace ProgrammList.sql {
using System.Collections.Generic;
namespace ProgrammList.sql {
interface SqlBase {
internal bool GetSingleLine(string pcid, string program, string version);
bool GetSingleLine(string pcid, string program, string version);
internal void CheckTableExists();
void CheckTableExists();
internal void InsertData(Dictionary<string, string> valuesqlCommand);
internal void InsertOrUpdateData(Dictionary<string, string> value);
internal void DeleteOldData(string hostname);
void InsertData(Dictionary<string, string> valuesqlCommand);
internal void UpdateData(Dictionary<string, string> value);
void InsertOrUpdateData(Dictionary<string, string> value);
void DeleteOldData(string hostname);
void UpdateData(Dictionary<string, string> value);
}

View File

@ -1,6 +1,8 @@
using Microsoft.Data.SqlClient;
using Microsoft.Data.Sqlite;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
namespace ProgrammList.sql {
@ -59,11 +61,15 @@ namespace ProgrammList.sql {
}
}
bool SqlBase.GetSingleLine(string pcid, string program, string version) {
void SqlBase.CheckTableExists() {
throw new NotImplementedException();
}
void SqlBase.CheckTableExists() {
void SqlBase.DeleteOldData(string hostname) {
throw new NotImplementedException();
}
bool SqlBase.GetSingleLine(string pcid, string program, string version) {
throw new NotImplementedException();
}
@ -75,10 +81,6 @@ namespace ProgrammList.sql {
throw new NotImplementedException();
}
void SqlBase.DeleteOldData(string hostname) {
throw new NotImplementedException();
}
void SqlBase.UpdateData(Dictionary<string, string> value) {
throw new NotImplementedException();
}

View File

@ -1,4 +1,6 @@
using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.Configuration;
namespace ProgrammList.sql {
@ -42,7 +44,8 @@ namespace ProgrammList.sql {
string result = "";
for (int i = 0; i < valuenames.Length; i++) {
result += valuesqlCommand.GetValueOrDefault(valuenames[i]);
string value = "";
result += valuesqlCommand.TryGetValue(valuenames[i], out value);
if (i < valuenames.Length - 1) {
result += ",";
@ -61,7 +64,13 @@ namespace ProgrammList.sql {
}
public void InsertOrUpdateData(Dictionary<string, string> value) {
if (GetSingleLine(value.GetValueOrDefault("PCID"), value.GetValueOrDefault("DisplayName"), value.GetValueOrDefault("DisplayVersion"))) {
string pcid = "";
string displayName = "";
string displayVersion = "";
value.TryGetValue("PCID", out pcid);
value.TryGetValue("DisplayName", out displayName);
value.TryGetValue("DisplayVersion", out displayVersion);
if (GetSingleLine(pcid, displayName, displayVersion)) {
Console.WriteLine("Update");
UpdateData(value);
@ -86,7 +95,9 @@ namespace ProgrammList.sql {
string result = "set ";
for (int i = 0; i < valuenames.Length; i++) {
result += valuenames[i] + " = " + value.GetValueOrDefault(valuenames[i]);
string res = "";
value.TryGetValue(valuenames[i], out res);
result += valuenames[i] + " = " + res;
if (i < valuenames.Length - 1) {
result += " ,";
@ -94,15 +105,23 @@ namespace ProgrammList.sql {
}
sqlCommand = sqlCommand + result;
sqlCommand = sqlCommand + " WHERE PCID = " + value.GetValueOrDefault("PCID") +
" and DisplayName like " + value.GetValueOrDefault("DisplayName") +
" and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
string pcid = "";
value.TryGetValue("PCID", out pcid);
string displayName = "";
value.TryGetValue("DisplayName", out displayName);
string displayVersion = "";
value.TryGetValue("DisplayVersion", out displayVersion);
sqlCommand = sqlCommand + " WHERE PCID = " + pcid +
" and DisplayName like " + displayName +
" and DisplayVersion like " + displayVersion;
var command = new SqliteCommand(sqlCommand, sqlitecon, transaction);
for (int i = 0; i < valuenames.Length; i++) {
if (valuenames[i] != "PCID") {
command.Parameters.AddWithValue("$" + valuenames[i], value.GetValueOrDefault(valuenames[i]));
string itemValue = "";
value.TryGetValue(valuenames[i], out itemValue);
command.Parameters.AddWithValue("$" + valuenames[i], itemValue);
}
}

View File

@ -1 +1,32 @@
# ProgrammList
# ProgrammList (EN)
A Program to create a list of programs installled on a system. You may add this program on a networkfolder to get more information from single clients that execute a script to invoke it and save the data to a centralized database.
Supported databases are MSSQL, Sqlite and MySql.
For Sqlite a database file will be created as long as the parameter for it is in the coresponding app.conf file. The app.conf file has to be in the same folder as the .exe file.
For MSSQL and MySql standard parameters are used currently such as IP (localhost) and Port.
In later versions this should be made configurable through the app.conf file.
Plan for the future:
- UI To configure the program through parameter, default will be cli auto run. there may be branches for winform vs wpf
- Additional Database support and eventuall csv support. (
- Depending on .net version (see branches) a portable version or installer.
# ProgrammList (GER)
Ein Programm zum erstellen einer Liste installierter Programme auf einem Rechner. Man kann das Programmm in einen Netzwerkordner legen um von mehreren Systemen die Information zu bekommen und diese Zentral zu Speichern.
Untersützt werden bisher Speichermethoden in MSSQL, Sqlite und MySql.
Für Sqlite wird eine Dantenbankdatei über eine app.conf date erstellt. Die app.conf Datei muss sich dazu im gleichen Ordner wie die exe befinden.
Für MSSQL und MySql werden bisher Standard Parameter für IP (Localhost) und Port verwendet.
In Späteren Versionen sollte dies auch über das Config file editierbar sein.
Zukunftsplan:
- Oberfläche zur Einrichtung der Konfigurationsdatei. Eventuell in eigenen Branches (WinForm vs WPF)
- Zusätzliche Datenbanken und eventuell auch ein CSV report.
- Je nach .net version, Portable single exe oder ein installer