|
You must not be using .net 2.0. There is a UserName and Password property in the StartInfo object of the Process in .net 2.0. Otherwise you are kind of stuck since what ever the service launches will be run under the user that the windows service is installed as.
The only other thing I can think of is not very clean. You could have the windows service send a windows message to your app. When that app receives that windows message, it could launch a small exe who's only purpose is to poll a directory or register setting that will get set when the update is done. One this little app see the update is done it launches the app again. Since it was started by the orignal application it should work fine.
Or you could just upgrade your service to .net 2.0.
Hope that helps.
Ben
|
|
|
|
|
I am using .net 2.0
I do see the startinfo.Username
and startinfo.Password
I suppose Knowing how to get the password for the default active user would do the trick as well.
|
|
|
|
|
I haven't tried it, but it might just work to set the UserName and the domain properties if the user is logged in.
This would get you the logged in user:
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
String username = wp.Identity.Name;
I believe this will include the domain.
Hope that helps.
Ben
|
|
|
|
|
Dear All,
i have problem in producing the auto generated number. my requirements are to produce series of numbers like that
AAA-0000
AAA-0001
up
.
.
.
AAA-9999
after that the number changes to
AAB-0000
AAB-0001
.
.
.
.
AAB-9999
the last number should be
ZZZ-9999
If there is any person who help me in producing that module / algorithm or piece of code in C# / T-SQL, i will be thankful for that.
NOTE:- the number should me auto generated i.e., after one transaction the new number would be generated.
or. in case of T-SQL, when inserting new record, the eky would be that number like the example that i stated above.
Hope that there is someone which will help me.
Best regards.
|
|
|
|
|
I don't know if I can offer help here as I'm not familiar with "T-SQL." Do you just need an algorithm for generating the numbers?
Off the top of my head, one way to do it would be to have an integer representing the first part of the number, the 0000 part. Also have three characters, each representing one of the letters in the letter part of the number. Initialize the number to 0 and each character to 'A', and do something like this:
using System;
using System.Collections.Generic;
using System.Text;
namespace AutoNumber
{
class Program
{
static int number = 0;
static char[] characters = { 'A', 'A', 'A' };
static void Main(string[] args)
{
for(int i = 0; i < 10000; i++)
{
Console.WriteLine(GenerateNumber());
}
Console.Read();
}
static string GenerateNumber()
{
number++;
if(number > 9999)
{
number = 0;
for(int i = characters.Length - 1; i >= 0; i--)
{
if(characters[i] == 'Z')
{
characters[i] = 'A';
}
else
{
characters[i]++;
break;
}
}
}
return new string(characters) + "-" + number.ToString();
}
}
}
The algorithm rolls over after you reach ZZZ-9999.
|
|
|
|
|
You need to use a format string so that he gets 0000 and not 0. Otherwise, this looks pretty good to me. I was just too lazy to do it for him
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Generating it in C# should be easy enough. Remember that a char implictly converts to int. So, you can store three chars, and a number, and increment from there.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Something like this do the trick?
<code>
public static string nextNumber(string num)
{
if (num == "")
num = "AAA-0000";
string[] parts = num.Split(new char[] { '-' }, System.StringSplitOptions.RemoveEmptyEntries);
if(parts.Length == 2) // else incorect format
{
string charPart = parts[0];
string intPart = parts[1];
int part = 0;
int.TryParse(intPart, out part);
if (part < 9999)
{
part++;
}
else
{
part = 0;
// we must now increment the char part.
bool incrementedChar = false;
int position = charPart.Length - 1;
while (!incrementedChar)
{
if (charPart[position] >= 'Z')
{
// set last char to A,
char[] chars = charPart.ToCharArray();// = charPart[position]+1;
chars[position] = 'A';
charPart = chars.ToString();
if (position > 0)
{--position;}
else
{
// we are at 'ZZZZ'
}
// and the next position to char++ (do this in the next iteration).
}
else
{
// we increment the char at this position
char[] chars = charPart.ToCharArray();// = charPart[position]+1;
++chars[position];
charPart = chars.ToString();
incrementedChar = true;
}
}
num = charPart + part.ToString("-0000");
}
}
return num;
}
</code>
|
|
|
|
|
This seems to work. Just pass in the current max key.
private string NextKey(string currentKey)
{
string ret = string.Empty;
string[] parts = currentKey.Split('-');
if (parts.Length == 2)
{
string alpha = parts[0];
Int32 numeric = Convert.ToInt32(parts[1]);
numeric++;
if (numeric > 999)
{
numeric = 0;
alpha = UpdateAlpha(alpha);
}
ret = alpha + "-" + Convert.ToString(numeric).PadLeft(3, '0');
}
return ret;
}
private string UpdateAlpha(string alpha)
{
string ret = string.Empty;
Char c = ' ';
for (Int32 i = alpha.Length-1; i >= 0;i-- )
{
c = alpha[i];
if (c == 'Z' && i != 0)
{
ret += 'A';
}
else if ((Int32)c < (Int32)'Z')
{
if (i == alpha.Length - 1)
{
ret += Convert.ToChar((Int32)c + 1);
}
else
{
ret = Convert.ToChar((Int32)c + 1) + ret;
}
for (Int32 j = i - 1; j >= 0; j--)
{
ret = alpha[j] + ret;
}
break;
}
else
{
ret += c;
}
} //foreach
return ret;
}
I tested it with this:
string key = "AAA-999";
richTextBox1.AppendText(key + Environment.NewLine);
// Int32 cnt = 0;
while (key != "ZZZ-999")// && cnt < 30001)
{
key = NextKey(key);
richTextBox1.AppendText(key+Environment.NewLine);
// cnt++;
} //while
Hope that helps.
Ben
|
|
|
|
|
Its amazing to see how there are so many ways to achive the same result.
Is there an optimal way?
ie: your else if ((Int32)c < (Int32)'Z')
could be written as
else if (c < 'Z')
and be cleaner, and skip the cast correct?
What do you see in my code that is 'sloppy' for lack of a better term. :P
|
|
|
|
|
Yes for sure it could be written as c < 'Z' I guess my coding background doesn't include C++. So I start with Cobol then SAS then Delphi (Pascal) then vb.net finally settled on C#. So with the baggage I bring to programming I always tend to cast things. In this case I am not sure if it is faster with the cast or not. I think C# actually see the Char as the ordinal value so there is probably no speed different. I am pretty sure in VB.net there would be a speed difference. Anyway, it was kind of a fun problem to work on since I had a little time.
Ben
|
|
|
|
|
So thanks for all beloved persons, who are trying to help me, i will check all solutions and notify , if i get the proper result.
Bye,
|
|
|
|
|
i have an windows application in .net 2005
i want get the logged in user name (the current user one who is logged in )
any idea?
thank u
|
|
|
|
|
WindowsIdentity.GetCurrent().Name
only two letters away from being an asset
|
|
|
|
|
I am trying to display columns as rows. The dataset has int and Double types.
I am not sure if this can be best accomplished within SQL Server / C# / .Net
This is what I want to accomplish:
Input:
val1A val2A val3A val4A
val1B val2B val3B val4B
val1C Val2C val3C val4C
Output:
val1A val1B val1C
val2A val2B val2C
val3A val3B val3C
val4A val4B val4C
Thanks for your help!
|
|
|
|
|
Hi,
I'm converting all of the database code in my app, and want to go through every class and every method to ensure that I haven't missed anything. What's a quick way to get a listing of all of my classes/methods?
(I code in VS2003/.net1.1)
Thanks,
cdj
|
|
|
|
|
Miss anything, in what way ? I often would comment out a member variable and compile, if I want to see all the places it is used.
If you want to generate a list, you'd need to write some reflection code, or look for a tool that uses reflection and generates such a list.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Have you tried viewing your class in the Object Browser? It won't give details but will list methods. What are you looking for?
only two letters away from being an asset
|
|
|
|
|
If I can print out the listing, that'll work fine - thanks!
|
|
|
|
|
I see only the option to build in C# . Is there a compile option like C++(ctrl F7) or is that not a concept in C#?
|
|
|
|
|
Save yourself (and us) some fustration and read some books or documentation before using the tool.
Build -> Build Solution or F6 if using the default VS2005 key mappings
only two letters away from being an asset
|
|
|
|
|
What is the difference between compile, and build ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello everyone,
I have a ListView that I wish to run a data search quary on it. I am able to get the raw's information once they are clicked but I was wondering if I can run a query to get the last registered item in the list without clicking on it?
as always, thank you very much for your help and have a great day.
Khoramdin
|
|
|
|
|
Can you tell more exactly what do you need? And make a sample where it will be used. Because it is not clearly understood what do you want.
What is the last registered item ?
One nation - underground
|
|
|
|
|
Hello Saikek,
Thank you for the reply. Your message came few seconds before I lose hope!
I have a ListView which I am registering and displaying some data once a particular button is clicked. Unfortunatly, the data that is going to be displayed in the ListView can be repeative and I am not intrested to register and display the same data once it has been displayed.
That is why I thought if I can run a query to see what has been registed then I can exclude the data that has already been registered and is displayed in the ListView.
Thank you very much for your help and have a great day.
Khoramdin
|
|
|
|