<?xml version="1.0"?><!-- generator="b2evolution/0.9.0.12" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Blog - Technical Articles</title>
		<link>http://charora.com/blog/index.php/technicalarticles</link>
		<description>Articles on Microsoft Technologies</description>
		<language>en-US</language>
		<docs>http://backend.userland.com/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=0.9.0.12"/>
		<ttl>60</ttl>
				<item>
			<title>How do I get the Username in Windows Services?</title>
			<link>http://charora.com/blog/index.php/technicalarticles/2006/08/11/how_do_i_get_the_username_in_windows_ser_1</link>
			<pubDate>Sat, 12 Aug 2006 00:18:49 +0000</pubDate>
						<category domain="alt">Microsoft.NET</category>
<category domain="main">Windows Services</category>			<guid isPermaLink="false">30@http://charora.com/blog</guid>
			<description>SYMPTOMS
If a Windows Service running under Local System Account, System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() returns NT AUTHOURITY\SYSTEM

You want to get who logged on to the machine?

CAUSE
Windows Service is running under Local System Account. Current user credentials will be NT AUTHOURITY\SYSTEM. You have to query WMI to get current users logged on to the machine.

WORKAROUND
To work around this problem, use following code.


ManagementObjectSearcher searcher = new 
ManagementObjectSearcher("SELECT UserName, Name FROMWin32_ComputerSystem");

foreach (ManagementObject mo in searcher.Get()) {
if (mo["UserName"] != null) {
   vUserName = mo["UserName"].ToString();
}
if (mo["Name"] != null) {
   strComputer = mo["Name"].ToString();
}
}
searcher.Dispose();
searcher = null;


Email me if you want VB.NET or C++.NET Code
</description>
			<content:encoded><![CDATA[	<p>SYMPTOMS<br />
If a Windows Service running under Local System Account, System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() returns NT AUTHOURITY\SYSTEM</p>
	<p>You want to get who logged on to the machine?</p>
	<p>CAUSE<br />
Windows Service is running under Local System Account. Current user credentials will be NT AUTHOURITY\SYSTEM. You have to query WMI to get current users logged on to the machine.</p>
	<p>WORKAROUND<br />
To work around this problem, use following code.</p>
	<blockquote><p>
ManagementObjectSearcher searcher = new<br />
ManagementObjectSearcher("SELECT UserName, Name FROMWin32_ComputerSystem");</p>
	<p>foreach (ManagementObject mo in searcher.Get()) {<br />
if (mo["UserName"] != null) {<br />
   vUserName = mo["UserName"].ToString();<br />
}<br />
if (mo["Name"] != null) {<br />
   strComputer = mo["Name"].ToString();<br />
}<br />
}<br />
searcher.Dispose();<br />
searcher = null;
</p></blockquote>
	<p>Email me if you want VB.NET or C++.NET Code</p>
]]></content:encoded>
			<comments>http://charora.com/blog/index.php/technicalarticles?p=30&amp;c=1&amp;tb=1&amp;pb=1#comments</comments>
		</item>
				<item>
			<title>How to call a web service using Javascript?</title>
			<link>http://charora.com/blog/index.php/technicalarticles/2006/08/11/how_to_call_a_web_service_using_javascri_1</link>
			<pubDate>Sat, 12 Aug 2006 00:16:32 +0000</pubDate>
						<category domain="alt">Microsoft.NET</category>
<category domain="main">Web Services</category>			<guid isPermaLink="false">29@http://charora.com/blog</guid>
			<description>For example:
You want to get a client name from the client list. "GetClientName" function exposed through web service name called "Service1.asmx" and the function takes "Client Code" as a passing variable.

Copy the WebService behavior (webservice.htc file) into the Web project folder.
You can download webservice.htc file at this link: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/behaviors/library/webservice/default.asp

Copy this javscript code and name it webservice.js and copy into the Web project folder.


var iCallID1;

function onBlur()
{			
  Get_ClientName();
}

function onEnter()
{			
 var kCode=event.keyCode;
 if(kCode==13)
   {
     Get_ClientName();
   }
}

function onWSresult()
{
if (event.result.error)
{
var xfaultcode = event.result.errorDetail.code;
var xfaultstring = event.result.errorDetail.string;
var xfaultsoap = event.result.errorDetail.raw;

alert("Error: " + xfaultcode + "|" + xfaultstring + "|" + xfaultsoap + "|");
}
else
{

if (iCallID1==event.result.id) {
   document.all("ClientName").innerHTML = event.result.value;
}
}
}

function Get_ClientName() {
if (document.all("ClientCode").value != "") {
   service.useService("http://www.charora.com/WebServices/Service1.asmx?WSDL","MyWebService");
   iCallID1 = service.MyWebService.callService("GetClientName", document.all("ClientCode").value);
}
else {
   alert ("Please enter client code ... ");
}
}


Create test.htm and include webservice.js in the test.htm

add a DIV tag and with following attributes
id="service" 
style="behavior:url(webservice.htc)" 
onresult="onWSresult();" 

add input tag and with following attributes
type="text" 
name="ClientCode" 
Text="" 
onblur="onBlur();" 
onkeypress="onEnter();"

add another input tag and with following attributes
type="text" 
name="ClientName" 
Text="" 



Finally, browse the test.htm file and enter client code and hit enter.

You will get the client name.
</description>
			<content:encoded><![CDATA[	<p>For example:<br />
You want to get a client name from the client list. "GetClientName" function exposed through web service name called "Service1.asmx" and the function takes "Client Code" as a passing variable.</p>
	<p>Copy the WebService behavior (webservice.htc file) into the Web project folder.</p>
	<blockquote><p>You can download webservice.htc file at this link: <a href="http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/behaviors/library/webservice/default.asp">http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/behaviors/library/webservice/default.asp</a></p></blockquote>
	<p>Copy this javscript code and name it webservice.js and copy into the Web project folder.</p>
	<blockquote><p>
var iCallID1;</p>
	<p>function onBlur()<br />
{<br />
  Get_ClientName();<br />
}</p>
	<p>function onEnter()<br />
{<br />
 var kCode=event.keyCode;<br />
 if(kCode==13)<br />
   {<br />
     Get_ClientName();<br />
   }<br />
}</p>
	<p>function onWSresult()<br />
{<br />
if (event.result.error)<br />
{<br />
var xfaultcode = event.result.errorDetail.code;<br />
var xfaultstring = event.result.errorDetail.string;<br />
var xfaultsoap = event.result.errorDetail.raw;</p>
	<p>alert("Error: " + xfaultcode + "|" + xfaultstring + "|" + xfaultsoap + "|");<br />
}<br />
else<br />
{</p>
	<p>if (iCallID1==event.result.id) {<br />
   document.all("ClientName").innerHTML = event.result.value;<br />
}<br />
}<br />
}</p>
	<p>function Get_ClientName() {<br />
if (document.all("ClientCode").value != "") {<br />
   service.useService("http://www.charora.com/WebServices/Service1.asmx?WSDL","MyWebService");<br />
   iCallID1 = service.MyWebService.callService("GetClientName", document.all("ClientCode").value);<br />
}<br />
else {<br />
   alert ("Please enter client code ... ");<br />
}<br />
}
</p></blockquote>
	<p>Create test.htm and include webservice.js in the test.htm</p>
	<p>add a DIV tag and with following attributes</p>
	<blockquote><p>id="service"<br />
style="behavior:url(webservice.htc)"<br />
onresult="onWSresult();" </p></blockquote>
	<p>add input tag and with following attributes</p>
	<blockquote><p>type="text"<br />
name="ClientCode"<br />
Text=""<br />
onblur="onBlur();"<br />
onkeypress="onEnter();"</p></blockquote>
	<p>add another input tag and with following attributes</p>
	<blockquote><p>type="text"<br />
name="ClientName"<br />
Text=""
</p></blockquote>
	<p>Finally, browse the test.htm file and enter client code and hit enter.</p>
	<p>You will get the client name.</p>
]]></content:encoded>
			<comments>http://charora.com/blog/index.php/technicalarticles?p=29&amp;c=1&amp;tb=1&amp;pb=1#comments</comments>
		</item>
			</channel>
</rss>
