How to get current user logon in windows service
Hello i want to run windows service on client machine that makes an entry of Current user logon in server database
well i tried three ways to do it
1) Enviroment.username
2) System.security.Principals.windowsidentity.getCurrent();
3) through windows registry
All three methods work well when i use them in console application but when i make a windows service the first two returns me name of user who started the service and third method returns me nothing
Here's my code that is written in my start method
///////////////////////////////////////////////////////////*******************************//////////////////////////////////////////
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
String str1,str2;
DateTime dt=DateTime.Now;
RegistryKey hkcu=Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Microsoft");
RegistryKey hkt=hkcu.OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Explorer");
str2= (string)hkt.GetValue("Logon User Name");
FileStream fs = new FileStream(@"c:\jk.txt",FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter SR = new StreamWriter(fs);
SR.WriteLine(str2);
SR.Flush();
str1="insert into Attendence Values('"+ str2 +"','Time In','Time Out','"+dt.ToString()+"','Present','null')";
con= new SqlConnection("Data Source=INSSS9;Initial Catalog=Attentence System;User Id=sa;Password=sa123;" );
cmd = new SqlCommand(str1,con);
con.Open();
dr=cmd.ExecuteReader();
dr.Close();
con.Close();
///////////////////////////////////////////////****************************************//////////////////////////////////////////////
PLz help meee

