|
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.
|
|
|
|
|
Not all of it - just relevant fragments.
Without any code at all, it's like you telling a garage "my car broke" and putting the phone down - they don't know where you are, much less what parts they need to bring out to help you!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
all this code posted works wonderfully, except that I want it to be printed without a print preview
|
|
|
|
|
Member 14192216 wrote:
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); Don't do it like that!
Your code is almost certainly vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
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 @transno", con);
da.SelectCommand.Parameters.AddWithValue("@transno", f.lblTrans.Text);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I'm going to have a Windows Service running on a server. It will have a FileSystemWatcher running in it. When a file is dropped in, the service will process the file. Sometimes, when a user drops a file onto the server, I will need to prompt the user, from the server, with some options.
The question is, how can the server prompt the user?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It can't. The service is going to have to send a message to an app running on the client machines and that app is going to have to prompt the user. Of course, is has to be an app that is run from the registry Run key so it starts when the user is logged on. That app cannot also be a service.
|
|
|
|
|
I'v used SignalR alot. The client could register itself with the server, then the server could as the local user for any info it needs. This would work, but I'm concerned about the client side app either not starting or being turned off somehow.
Your thoughts?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Since everything launched from the Run key launches as the user that logged in, they are free to terminate the app any time they want from either the command line tools or from Task Manager.
They are also free to disconnect the network and rip out the LAN cable.
There's nothing you can do that's going to be 100% effective against losing communication or presentation.
|
|
|
|
|