|
i am working on a project in which i hav to copy a .exe file to all the pcs' on the domain and the execute it with in a single loop, i used File.copy to copy and invoke psexec to exe cute the file, the problem is that psexec give file error bcoz the file is in use by copy command, when i restart the application the psexec execute the file that was copied when i first run the application
|
|
|
|
|
|
Is there an interop or P/Invoke (or are those the same?) call to ascertain the Win32 file version of a file? I want to list the version of all files in a directory, but some may not be .NET assemblies. How can I read this info?
Thanks.
|
|
|
|
|
Hi,
have a look at FileVersionInfo.GetVersionInfo(), it works for all kinds of files.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Use FileVersionInfo.FileVersion. Try:
FileVersionInfo fv = FileVersionInfo.GetVersionInfo("Filename");
Console.WriteLine(fv.FileVersion);
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
As has already been said, using FileVersionInfo.GetVersionInfo() is the right way to go. If you are only looking for the version number data, there aren't any problems. However, if you want to start looking at any of the other properties, a lot of the .NET assemblies will report incorrect data, particularly the IsDebug property.
|
|
|
|
|
Thanks, guys! That is quick service.
|
|
|
|
|
I have two listBoxes on a Winforms project that populate indirectly from two different datatables. One is a complete list of available families in a families table and the other is a list of the families that are assigned to a particular contact from a join table. This worked fine. Now I want to change the list of available families to exclude those in the "assigned list" so that the available families list only shows those families that are not currently assigned to the current contact. My code for this works fine if there is only one assigned family but if there are more then I get duplicates in the available families list. I've thought of a couple of ways to accomplish this but none of them are elegant. See code below...
private void loadFamiliesList(string contactID)
{
int cID = Convert.ToInt32(contactID);
this.view_form_manageContactsTableAdapter.FillByContact(this.ds_formContactsFamilies4Contact.view_form_manageContacts, cID);
listBox_availableFamilies.Items.Clear();
foreach (DataRow datarow in ds_form_contacts.tbl_families.Rows)
{
string fam1 = datarow["familyName"].ToString();
string famID = datarow["familyID"].ToString();
string cID2 = contactID;
int i = ds_formContactsFamilies4Contact.view_form_manageContacts.Rows.Count;
// MessageBox.Show("ContactID is " + i);
if (i < 1)
{
listBox_availableFamilies.Items.Add(new ItemObject(fam1, famID, cID2));
}
else
{
foreach (DataRow datarow3 in ds_formContactsFamilies4Contact.view_form_manageContacts.Rows)
{
string fam3 = datarow3["familyName"].ToString();
string famID3 = datarow3["familyID"].ToString();
string cID3 = contactID;
if (famID != famID3)
{
// listBox_availableFamilies.Items.Add(fam1);
listBox_availableFamilies.Items.Add(new ItemObject(fam1, famID, cID2));
}
}
}
}
}
-Kevin
|
|
|
|
|
Hi Kevin,
I am not familiar with databases and databinding in general.
It seems like you want to remove those items from listBox_availableFamilies
that already are present in listbox2. Couldn't you achieve that by starting
with listBox_availableFamilies as is, then have a foreach loop over the
listbox2 items, and simply find (with FindStringExact) and remove them from
listBox_availableFamilies ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I thought about this too, but it seemed a bit awkward to populate the whole list then remove items. I may end up doing this if I can't figure something else out. Thanks for your help.
-Kevin
|
|
|
|
|
Oh, I understood you already had that; if not, and populating listbox1 by your
own code (as opposed to databinding), just do the listbox2 first, then populate
listbox1 as uou did before but add a test for presence in listbox2
(a few lines will be required to do that).
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Is there a specific command to do this test for presence?
-Kevin
|
|
|
|
|
No, and that's why I described it as "a few lines"
you probably want a foreach loop.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
That's what I ended up doing. thanks, -Kevin
|
|
|
|
|
Kevin
You should add a break statement to your inner foreach loop after adding the item to the list. This will ensure that the current family from the outer loop is not added multiple times to the available list if it is not already assigned to the contact.
Paul
|
|
|
|
|
Thanks Paul, This managed to remove all but one of my duplicates in my available list. I put the break; inside the if statement.
-Kevin
|
|
|
|
|
Kevin,
kboyette wrote: My code for this works fine if there is only one assigned family but if there are more then I get duplicates in the available families list. I've thought of a couple of ways to accomplish this but none of them are elegant.
i believe you are calling your families list from a DB using a T-SQL statement.
You can use the 'distinct' keyword in your sql statement to retrieve unique values.
For ex: select distinct [familynames] from familytable
does it work well?
-- modified at 8:08 Friday 17th August, 2007
He who goes for revenge must first dig two graves.
|
|
|
|
|
Hi there,
Well, my problem is pretty straightforward. I need to control access to a particular directory through a bit of C# code. I also need to toggle this security mode between 'access denied' and 'access granted' modes whenever I need.
How can I do this?
Regards,
A
|
|
|
|
|
You can't really. Well, not without writing, in C++, hooks into the Windows File I/O API's to capture the requests. You can NOT do this in C# because of the requirements of "DLL Injection" to get this to work.
This just handles the File I/O part. Then you've got to write another app, which CAN be written in C#, that manages the access and the user database, and maybe a utility to fix any problems with said database.
It's simply not worth it. You get nothing above and beyond what the standard NTFS security system gives you, other than an administrative nightmare.
|
|
|
|
|
You can use the DirectorySecurity and FileSystemAccessRule classes to do this. There aren't any DLL injection concerns here at all. These classes rely on the underlying Win32 APIs to manipulate the ACLs assigned to the filesystem.
|
|
|
|
|
Scott Dorman wrote: You can use the DirectorySecurity and FileSystemAccessRule classes to do this.
Which is all NTFS security... Not exactly the solution his description spelled out, but it would work. Personally, I think his requirements are a bit over the top. In 22 years, I've never heard of anyone needing a security solution like this for any reason what-so-ever.
|
|
|
|
|
Disclaimer... not sure if this will work for your case -- this is the first time I've used this and I havn't really looked into it much.
Doing this I was able to restrict access to a directory that I had just created.
DirectoryInfo dirinfo = new DirectoryInfo(@".\mydir");
DirectorySecurity dirsec = new DirectorySecurity();
WindowsIdentity.GetCurrent().Name.ToString();
FileSystemAccessRule fsar = new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name.ToString(), FileSystemRights.FullControl, AccessControlType.Deny);
dirsec.SetAccessRule(fsar);
dirinfo.SetAccessControl(dirsec);
Basically this restricts it for the current user, but you can change it to the user name you'd like by replacing the WindowsIdentity name to whatever user you want.
Include these namespaces:
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;
|
|
|
|
|
Hi,
I have been fighting this problem for a couple of days now, I have a application where the user uses userid and password to log-on. My app goes to the database verifies user info and if the user has not changed his/her pswd for 90 days need to pop up a msg to user asking her/him to do so
I use the following code in button click event (after going to the db and verifying), am not sure if this is correct, does not work
StringBuilder sbScript = new StringBuilder();
sbScript.Append("alert('");
sbScript.Append("Change password");
sbScript.Append("')");
ClientScript.RegisterClientScriptBlock(this.GetType(), "pswdrem", sbScript.ToString());
can anyo1 help?
|
|
|
|
|
vis, CodeProject has a ASP.NET forum. Look in the Forum list.
|
|
|
|
|
Try Response.Write("<script language= 'javascript'>alert('Change Password');</script>);
I agree with led. you should better ask in right forum....
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|