|
Not sure what you want us to do. We can't see anything that you have done.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
I am using the below code to obtain a list of all local user accounts on the machine. But in addition to the "human" accounts, it returns all the other accounts, such as the SQLSERVER accounts and something called the WDAGUtilityAccount .
What is the property I should be checking for to determine which listed accounts are the "human" accounts, and which are machine accounts?
public static List<string> GetComputerUsers()
{
List<string> users = new List<string>();
var path =
string.Format("WinNT://{0},computer", Environment.MachineName);
using (var computerEntry = new DirectoryEntry(path))
{
foreach (DirectoryEntry childEntry in computerEntry.Children)
{
if (childEntry.SchemaClassName == "User")
{
users.Add(childEntry.Name);
}
}
}
return users;
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard,
the first code block here[^] seems to give actual user names.
|
|
|
|
|
Hi Luc,
The first code block gives me the strings, "INTERACTIVE" and "Authenticated Users".
And the second code block fails because I do not have an LDAP server on my LAN.
Thank you
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Hi,
Richard Andrew x64 wrote: What is the property I should be checking for to determine which listed accounts are the "human" accounts, and which are machine accounts? I believe your childEntry variable will be a IADsUser COM object[^] for end-user accounts. You may be able to perform additional filtering by inspecting the IADsUser properties[^].
I am not a C# developer so I don't know off the top of my head how you would access this. Looking at the documentation it appears that you would need to iterate through DirectoryEntry.Properties[^] to access properties like 'LastLogin'.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you David.
I'm not averse to using native code to access what I need.
Which functions would I use to do this?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: Which functions would I use to do this?
You are the C# developer not me.
See if this works:
foreach (DirectoryEntry childEntry in computerEntry.Children)
{
if (childEntry.SchemaClassName == "User")
{
IADsUser coronavirus = childEntry.NativeObject as IADsUser;
}
}
|
|
|
|
|
Thank you for your response.
There seems to be a misunderstanding. I was asking which native functions I would use to do this. I only want the local machine accounts.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard,
I've already told you how you need to go about doing this. You will need to come up with some criteria for filtering out some accounts using the method I mentioned above.
First let's get on the same page. Could you tell me what accounts are listed if you use the method I mentioned above to filter out all accounts with the AccountDisabled IADsUser Property[^]?
|
|
|
|
|
Randor wrote: First let's get on the same page.
OK when I filter out accounts that have AccountDisabled == true, I get the following:
admin <<- This is my account
SQLEXPRESS00 through SQLEXPRESS20 <- I have Sql Server Express installed
INTERACTIVE <- I don't know which user this is
Authenticated Users <- I don't know which user this represents
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard,
Great, that looks good. I mentioned AccountDisabled because typically 'Built-In' accounts have the disabled flag set to disallow network login.
But you are not enumerating user account objects. You are enumerating everything.
Now enumerate with the scope of'WinNT://YOUR_MACHINE/Administrators,group' and then 'WinNT://YOUR_MACHINE/Users,group'
Best Wishes,
-David Delaune
|
|
|
|
|
Hmmmm,
You haven't answered yet and since I am under forced quarantine/lockdown orders I threw this together for you. You will have to figure out how to translate it to C#
I apologize in advance for the nested IF statements. It's a code sample and I don't really feel like taking the time to make it look pretty.
#pragma comment(lib, "adsiid.lib")
#pragma comment(lib, "Activeds.lib")
#include <iostream>
#include <windows.h>
#include <atlbase.h>
#include <activeds.h>
#include <iads.h>
#include <adshlp.h>
#include <strsafe.h>
INT main()
{
IADsClass* pClass = NULL;
IADs* pADs;
BSTR bstrSchema;
VARIANT var;
IEnumVARIANT* pEnumerator = NULL;
IADsContainer* pContainer = NULL;
ULONG count;
IADs* pChild = NULL;
WCHAR ad_path[MAX_PATH] = { 0 };
WCHAR computer_name[MAX_COMPUTERNAME_LENGTH] = { 0 };
count = MAX_COMPUTERNAME_LENGTH;
GetComputerName(computer_name, &count);
count = MAX_PATH;
if (SUCCEEDED(CoInitialize(NULL)))
{
if (SUCCEEDED(StringCchPrintfW(ad_path, count, L"WinNT://%s,computer", computer_name)))
{
if (SUCCEEDED(ADsGetObject(ad_path, IID_IADsContainer, (void**)&pContainer)))
{
if (SUCCEEDED(ADsBuildEnumerator(pContainer, &pEnumerator)))
{
VariantInit(&var);
while (SUCCEEDED(ADsEnumerateNext(pEnumerator, 1, &var, &count)) && count == 1)
{
if (SUCCEEDED(V_DISPATCH(&var)->QueryInterface(IID_IADs, (void**)&pChild)))
{
BSTR bstrClass;
pChild->get_Class(&bstrClass);
if (CComBSTR(bstrClass) == CComBSTR(L"User"))
{
IADsUser* user = nullptr;
if (SUCCEEDED(pChild->QueryInterface(&user)))
{
VARIANT_BOOL is_disabled;
user->get_AccountDisabled(&is_disabled);
if (VARIANT_FALSE == is_disabled)
{
BSTR bstrName;
pChild->get_Name(&bstrName);
std::wcout << bstrName << std::endl;
SysFreeString(bstrName);
pChild->Release();
}
}
}
pChild->Release();
}
VariantClear(&var);
}
ADsFreeEnumerator(pEnumerator);
}
pContainer->Release();
}
}
}
CoUninitialize();
return 0;
}
Best Wishes,
-David Delaune
|
|
|
|
|
I apologize for not answering sooner. I was called away.
I thank you very kindly for that code sample.
I will have no problem using it as is. I can make a mixed mode executable.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi David,
I ran this code and it still lists all of the SQL Express users along with my username, "admin".
Windows has to know the difference somewhere. After all, when you go into the Settings app, it lists only the "human" users on the Manage Users page.
Thanks for any pointers.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi I am trying to develop a multitasking application in C# based on some code I have available that is depicted below. I have tried to do some changes but I am not sure if I put the WaitOne() and Release() methods at the correct places.
I am trying to include semaphore for a secure usage of common resources.
A semaphore is defined in C# by making a "Semaphore" variable, and use the methods WaitOne() and Release() to access the semaphore services.
I want to include name, student number and the semester year in the display information.
Sleep(0) statements can be used to test the sharing of common resources. I will use a console application.
The print out in console should be something like:
[T1]: Student no.
[T1]: Student name
[T1]: Semester year
[T2]: Student no.
[T2]: Student name
[T2]: Semester year
[T1]: Student no.
[T3]: Student no.
[T1]: Student name
[T2]: Student name
using System;
using System.Threading;
namespace ThreadSys
{
class ThreadClass
{
int loopCnt, loopDelay;
Thread cThread;
public string studentname;
static Semaphore semaphore = new Semaphore(1,1);
public ThreadClass(string name, int delay)
{
loopCnt = 0;
loopDelay = delay;
cThread = new Thread(new ThreadStart(this.run));
cThread.Name = name;
cThread.Start();
}
void run()
{
Console.WriteLine(" Starting " + cThread.Name);
do
{
loopCnt++;
Thread.Sleep(loopDelay);
Console.Write(" ");
semaphore.WaitOne();
Console.Write(cThread.Name);
Console.Write(": ");
Console.WriteLine("Loop=" + loopCnt);
semaphore.Release();
} while (loopCnt < 5);
Console.WriteLine(" Ending " + cThread.Name);
}
}
class ThreadSys
{
static void Main(string[] args)
{
Console.WriteLine(" Start of main program ");
ThreadClass ct1 = new ThreadClass("[T1]:", 95);
ThreadClass ct2 = new ThreadClass("[T2]:", 279);
ThreadClass ct3 = new ThreadClass("[T3]:", 463);
for (int cnt = 0; cnt < 30; cnt++)
{
Console.Write(".");
Thread.Sleep(100);
}
}
}
}
|
|
|
|
|
It's not really a very good test as there is nothing that is shared between the threads. You could try using a common memory buffer, where one thread puts data into it, and the other takes data out.
|
|
|
|
|
This is more of a simulation of a multitask application. The only thing I was trying to do here is to make some slight changes to the code so that I get print outs where Tasks [T1], [T2] and [T3] are not only printing out sequnetally but kind of roandomly in sort of random order.
However my C# coding abilites are worse than I would imagine so getting this done anytime soon aitn gonna happen.
Furthermore, I couldnt find anything on this Threadclass in C#. I didnt see any examples online where this ThreadClass was used directly in the code.
|
|
|
|
|
auting82 wrote: I couldnt find anything on this Threadclass in C#.
Of course you didn't. It's not part of the .NET Framework. It's code YOU WROTE, so why would you expect there to be any documentation on it anywhere?
Threads do not run in sequential order, and cannot be predicted to execute in any determined order. It's not the code that is wrong, but your expectations of how the system will execute it.
|
|
|
|
|
Well you created the ThreadClass so why would you expect to find examples of it on the internet? However, there is some sample code at Thread Class (System.Threading) | Microsoft Docs[^]. Also, if your coding skills are as basic as you imply, then I suggest you stay well clear of threads, they rarely offer any benefit unless you are creating large multitasking applications.
|
|
|
|
|
Try an example that works; then get creative.
Thread Class (System.Threading) | Microsoft Docs
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Pardon me if I've misunderstood your question but it seems to me that you spawn your threads but expect them to execute synchronously which does not make any sense to me at all. So I agree with Richard that this is not the best example as it would just benefit from synchronous code as it is much simpler and as performant.
My main point is that the best parallelism is when you have no shared resources between your tasks and you should strive for it.
In case you wanted to simulate with your example the fact that it requires some effort to compute info about the student (i.e. you get it from DB) I would rather suggest you investigate async/await.
|
|
|
|
|
Hello everyone, I have a problem with my application which is designed to print purchase invoices in a shop on a thermal printer. I have a little problem when printing the invoice, I want the invoice to be printed directly without a preview.
I used ReportViewer and RDLC
If anyone has an idea please help me. thank you in advance
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. So we have no idea what your code might even look like!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
do I have to post my code that I used?
here is the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.Reporting.WinForms;
namespace POS_System_Inventory
{
public partial class frmReceipt : Form
{
String store = "LISINGI PC SOFTWARE Pvt Ltd";
String address = "13ième AV N°46 C/TSHOPO-KIS";
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
DBConnection dbcon = new DBConnection();
frmCashier f;
public frmReceipt(frmCashier frm)
{
InitializeComponent();
con = new SqlConnection(dbcon.MyConnection());
f = frm;
}
private void frmReceipt_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
public void LoadReport(string paracash, string parachange)
{
try
{
ReportDataSource rptDataSource;
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @"\Reports\Report1.rdlc";
this.reportViewer1.LocalReport.DataSources.Clear();
DataSet1 ds = new DataSet1();
SqlDataAdapter da = new SqlDataAdapter();
con.Open();
da.SelectCommand = new SqlCommand("select c.id,c.transno,c.pcode,c.price,c.qty,c.disc,c.total,c.sdate,c.status,p.pdesc from tblCart as c inner join tblProduct as p on p.pcode=c.pcode where transno like '" + f.lblTrans.Text + "' ", con);
da.Fill(ds.Tables["dtSold"]);
con.Close();
ReportParameter pVatable = new ReportParameter("pVatable", f.lblVatable.Text);
ReportParameter pVat = new ReportParameter("pVat", f.lblVat.Text);
ReportParameter pDiscount = new ReportParameter("pDiscount", f.lblDiscount.Text);
ReportParameter pTotal = new ReportParameter("pTotal", f.lblTotal.Text);
ReportParameter pCash = new ReportParameter("pCash", paracash);
ReportParameter pChange = new ReportParameter("pChange", parachange);
ReportParameter pStore = new ReportParameter("pStore", store);
ReportParameter pAddress = new ReportParameter("pAddress", address);
ReportParameter pTransaction = new ReportParameter("pTransaction", "Facture N°: " + f.lblTrans.Text);
ReportParameter pCashier = new ReportParameter("pCashier", frmLogin2.UserDisplayName2.name2);
reportViewer1.LocalReport.SetParameters(pVatable);
reportViewer1.LocalReport.SetParameters(pVat);
reportViewer1.LocalReport.SetParameters(pDiscount);
reportViewer1.LocalReport.SetParameters(pTotal);
reportViewer1.LocalReport.SetParameters(pCash);
reportViewer1.LocalReport.SetParameters(pChange);
reportViewer1.LocalReport.SetParameters(pStore);
reportViewer1.LocalReport.SetParameters(pAddress);
reportViewer1.LocalReport.SetParameters(pTransaction);
reportViewer1.LocalReport.SetParameters(pCashier);
rptDataSource = new ReportDataSource("DataSet1", ds.Tables["dtSold"]);
reportViewer1.LocalReport.DataSources.Add(rptDataSource);
reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
reportViewer1.ZoomMode = ZoomMode.Percent;
reportViewer1.ZoomPercent = 50;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
modified 23-Mar-20 4:14am.
|
|
|
|