|
I've got a string
@"\fs17 someTextHere\"
where 17 could be any number
I'd like to extrract the "someTextHere" part from the string using a regular expression.
The regular expression
@"\\fs(\d{1})+ (\w|\W)+\\"
will match the entire string; but I only want to find out the "someTextHere" part of the string. Could any of the regular expression experts here help me out?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: The Secular Left, the Religious Right, and Prejudice
Judah Himango
|
|
|
|
|
@"\\fs\d+ (\w|\W)+\\"
Now you have only one grouping, which is the word. You can get this group out of your regex match, it has a property or something to access it. Any bracket will generate a group. From memory, the array is 1 indexed, with the 0 index containing the whole match.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks Christian; I was totally oblivious to the groups property, much appreciated. For the record, I ended up modifying the pattern a bit:
<br />
@"\\fs\d+ (\w+|\W+)\\"
As the previous one grouped only a single character (the plus sign was outside the parentheses).
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: The Secular Left, the Religious Right, and Prejudice
Judah Himango
|
|
|
|
|
Judah Himango wrote:
As the previous one grouped only a single character (the plus sign was outside the parentheses).
Sorry, I just copied that bit from yours, I didn't really check it
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
|
how can i have the computername in a simple windows application with c#
thanks
prog
|
|
|
|
|
I am assuming you are asking how you could get the computer name in a simple windows app? You could query the WMI for the computername.
Eric
|
|
|
|
|
For a much easier method, you'll find the computer name in the MachineName property of the Environment class.
String computerName = Environment.MachineName;
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
is it possible for this to be done for application running in a terminal services environment..can the name of the computer that is connecting to the app via terminal services be captured??
Afzal Hassen
|
|
|
|
|
Not that I know of. Since the application is always running on the server, it'll always return the name of the server. It has no way of knowing that it is running under a TS session since the .NET Framework doesn't expose any of the TS functionality. You'll have to look into calling the TS API directly to see if you can get the name of the computer that started the session.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i have dabbled with the WTSQueryUserConfig API call,and it does return the name of the computer, thanks for that input...
would you by any chance know how i can access the client computer hardware information via TS?? or of any articles that can help me accomplish this??
Thanks
Afzal Hassen
|
|
|
|
|
TS doesn't care about the client hardware at all, so it's not going to give you access to it. But, there's always one of these, once you get the client computer name from WTSQueryUserConfig, you can use it to connect back to the client machine and query WMI (if available!) to get its hardware details.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thanks
|
|
|
|
|
I am new to C#..about 6 months in. I am working on a program that will Inventory computers, and then either write out to a text file or dump the data into an SQL server. Would this be best suited to run as a Service or make it a scheduled task?
Eric
|
|
|
|
|
Scheduled Task. I did something like this a few years ago. But, I did it as a three part application.
First, the Client side. A small application, written in C++, that gathered everything I needed to know about each workstation at Login time. This app was launched out of a Novell login script and dumped all of its information into a common text file on the server. Each of the workstations generated a GUID for itself (only once!) and tagged it's data with the GUID. All the workstations at a site dumped its data into the same text file. Since each workstation was tagging its data with its own GUID, every workstation could repeatedly dump its data into the text file without worrying about getting counted multiple times. 40,000 workstations did not allow for me to write something to go out and "touch" each of the workstations from a central point.
Second, the Server side. Two parts. One was an SQL database that ultimately stored all the information on each machine. The Primary Key to this little table was, you guessed it, that little GUID that each machine generated for itself. Now, the second part of this was Collection application that went out to each server (200+) every night (scheduled task!), renamed the log file to a temporary name, then read the file line-by-line. If the GUID in the line was not already in the database, a new record was created using the new GUID. If the GUID was already in the database, it simply updated the record that was there. Now, you're probably thinking if I change out a machine and it gets a new GUID, what happens to the old record? Each record is stamped with the last date/time that that particular record was touched, either created or updated. The SQL Server ran a little statement that selected the records that have not been touched in the last, say 7 days. Old records are now either refreshed from the log file download, or are dropped. After the entire log file was read, it was deleted.
Third, the Reporting side. A simple data driven website using the SQL database as a backend.
Easy!
Now, why didn't I just have the Client app go directly to the SQL Server? Two reasons... Minimize the traffic going acrossed the WAN during the two busiest shifts of the day. And, the client machines were running various versions of Windows. Most of which either had screwed up SQL Server drivers or were behind firewalls that wouldn't allow that kind of traffic to get out.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for this Reply! I like the idea of writing everything to a text file first and then running an app from the server to enter the data into the DB. How could I go about getting the GUID with C#, and I am not familiar with adding records to a DB by reading from a file.....
Eric
|
|
|
|
|
New GUID? Easy...
Guid myNewGuid = Guid.NewGuid();
Do you know how to read a text file? Do you know how to run a query against a database? If you answered "Yes" to both of these questions, you already know how to do this. There is no special function that will just copy a file into a database for you. You have to write the code to read the text file, read a line, parse it up into useful data, and use that data to work with the database.
If you've got a more specific question, that would help.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I would say go write it as a Service. While David suggested to run it as a Scheduled Task it has its disadvantages. Namely what happens if the user that is supposed to run the Scheduled Task is not logged in ? Your scheduled task will not run.
|
|
|
|
|
Scheduled Tasks don't need anyone to be logged on for them to run. The scheduled tasks run under their own session and can be run under any account, especially one specifically created for the purpose. The machine can be sitting at the login screen and the Task will stil run just as if someone was logged in.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I do know how to read from a file, but I am not sure how you would go about making all of the correct associations so the data can be entered into the database at the correct location....if that makes sense. For instance, you have a text file with information from many different computers...How would I make sure that data from the text file is entered into the correct column in my DB table?
|
|
|
|
|
Well, you're specifying what data your collecting, the file format your going to use, the database tables, ... Since your specifying the file format, you get to map what columns of the text file get mapped to which columns in the database. For example...
Your collecting the machine name, the O/S version, and how much memory is installed in the machine. The client app would probably write something like this to the text file:
820db904-3dd1-4035-ba68-776debc7b796;AGC2010A;5.1.2600.0;1024
Since your defining the file format, the same data will go into the same columns for each line. When you read the line, you use the .Split() method on the string you read to break the line up into an array of strings. You can now go through that array and map each of those strings to the appropriate columns. It's a one-for-one relationship that doesn't change throughout the entire file.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The knowledge is much appreciated. I am 6 months into this, and programming is like a freakin disease. I CAN'T help myself. I think I am going to alter my app to work more like the Frame of yours. I really like the idea of dumping everything into the text file, and I think you have given me enough ideas to start working at it!
I did have another question for you. What is the easiest way to get the GUID of a computer?
Eric
|
|
|
|
|
The computer really doesn't have a GUID. In my method, I checked a file on the hard drive (C:\InvGuid.txt), if it wasn't there, I generated a new GUID and used that as the GUID to ID that machine. The new GUID was written to the file for use the next time the app was run. If the file is there already, read the GUID out of the file. Simple.
How do you generate a GUID?
Guid myGUID = Guid.NewGuid();
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have gotten this far...
I can write to a text file, and then use the Split() method like you said to put everything into an array.
What would be the best way for me to add this array of strings to my DB?
|
|
|
|
|