How to make an AJAX call from inside Silverlight

by Shawn November 17, 2009 04:05

Here is a little snippet that will let you make a remote AJAX call from inside Silverlight - the only catch is that you will get a "security warning" dialog for making a crossdomain call

ScriptObjectCollection scriptCollection = HtmlPage.Document.GetElementsByTagName("head");
HtmlElement head = (HtmlElement)scriptCollection[0];

HtmlElement script = HtmlPage.Document.GetElementById("dataAccess_js");
if (script == null)
{
	script = HtmlPage.Document.CreateElement("script");
	script.SetAttribute("type", "text/javascript");
	script.Id = "dataAccess_js";

	StringBuilder sbScript = new StringBuilder();

	sbScript.AppendLine("function createXMLHttpRequest() { var httprequest = false; if (window.XMLHttpRequest) { httprequest = new XMLHttpRequest(); if (httprequest.overrideMimeType) httprequest.overrideMimeType(\"text/xml\"); } else if (window.ActiveXObject) {  try { httprequest = new ActiveXObject(\"Msxml2.XMLHTTP\"); } catch (e) { try { httprequest = new ActiveXObject(\"Microsoft.XMLHTTP\"); } catch (e) { } } } return httprequest; }");
	sbScript.AppendLine("function retrieveContent(url) { var request = createXMLHttpRequest(); request.open(\"GET\", url, false); request.send(null); if (request.status == 200) { var text = request.responseText; return text; } else { alert(\"Error loading \" + url); } }");

	script.SetProperty("text", sbScript);

	head.AppendChild(script);
}

var result = HtmlPage.Window.Invoke("retrieveContent", sURL);

Tags:

Scripting

How to replace notepad.exe on Windows Server 2008

by Shawn February 08, 2009 12:41

Have you been looking for a way to replace all instances of notepad.exe on Windows Server 2008? If so, here is a quick and dirty batch file to help you out.

Note: I ran a "dir /s /b notepad.exe > replace_notepad.cmd" to get a list of copies of notepad.exe on the c drive, then edited the new file with what is below

@echo off 
echo Create Backup copies of the original notepad.exe 
copy C:\Windows\notepad.exe C:\Windows\notepad32.exe 
copy C:\Windows\System32\notepad.exe C:\Windows\System32\notepad32.exe
copy C:\Windows\SysWOW64\notepad.exe C:\Windows\SysWOW64\notepad32.exe

echo Take Ownership of the files rem This could be changed to use icacls now 
takeown /F C:\Windows\notepad.exe /A 
takeown /F C:\Windows\System32\notepad.exe /A 
takeown /F C:\Windows\SysWOW64\notepad.exe /A
takeown /F C:\Windows\winsxs\x86_microsoft-windows-notepadwin_31bf3856ad364e35_6.0.6001.18000_none_42c9ccdefb0d0dc9\notepad.exe /A 
takeown /F C:\Windows\winsxs\x86_microsoft-windows-notepad_31bf3856ad364e35_6.0.6001.18000_none_6f1a8d7b6fffbb73\notepad.exe /A 

takeown /F C:\Windows\winsxs\amd64_microsoft-windows-notepadwin_31bf3856ad364e35_6.1.7600.16385_none_9ebebe8614be1470\notepad.exe /A
takeown /F C:\Windows\winsxs\amd64_microsoft-windows-notepad_31bf3856ad364e35_6.1.7600.16385_none_cb0f7f2289b0c21a\notepad.exe /A
takeown /F C:\Windows\winsxs\wow64_microsoft-windows-notepad_31bf3856ad364e35_6.1.7600.16385_none_d5642974be118415\notepad.exe /A

echo Assign full rights to the administrators group 
icacls c:\windows\notepad.exe /grant Administrators:F 
icacls C:\Windows\System32\notepad.exe /grant Administrators:F
icacls C:\Windows\SysWOW64\notepad.exe /grant Administrators:F
icacls C:\Windows\winsxs\x86_microsoft-windows-notepadwin_31bf3856ad364e35_6.0.6001.18000_none_42c9ccdefb0d0dc9\notepad.exe /grant Administrators:F 
icacls C:\Windows\winsxs\x86_microsoft-windows-notepad_31bf3856ad364e35_6.0.6001.18000_none_6f1a8d7b6fffbb73\notepad.exe /grant Administrators:F 

icacls C:\Windows\winsxs\amd64_microsoft-windows-notepadwin_31bf3856ad364e35_6.1.7600.16385_none_9ebebe8614be1470\notepad.exe /grant Administrators:F 
icacls C:\Windows\winsxs\amd64_microsoft-windows-notepad_31bf3856ad364e35_6.1.7600.16385_none_cb0f7f2289b0c21a\notepad.exe /grant Administrators:F 
icacls C:\Windows\winsxs\wow64_microsoft-windows-notepad_31bf3856ad364e35_6.1.7600.16385_none_d5642974be118415\notepad.exe /grant Administrators:F 

echo Copy new notepad.exeover the original versions 
copy /y C:\notepad.exe C:\Windows\notepad.exe 
copy /y C:\notepad.exe C:\Windows\System32\notepad.exe 
copy /y C:\notepad.exe C:\Windows\SysWOW64\notepad.exe
copy /y C:\notepad.exe C:\Windows\winsxs\x86_microsoft-windows-notepadwin_31bf3856ad364e35_6.0.6001.18000_none_42c9ccdefb0d0dc9\notepad.exe
copy /y C:\notepad.exe C:\Windows\winsxs\x86_microsoft-windows-notepad_31bf3856ad364e35_6.0.6001.18000_none_6f1a8d7b6fffbb73\notepad.exe

copy /y C:\notepad.exe C:\Windows\winsxs\amd64_microsoft-windows-notepadwin_31bf3856ad364e35_6.1.7600.16385_none_9ebebe8614be1470\notepad.exe
copy /y C:\notepad.exe C:\Windows\winsxs\amd64_microsoft-windows-notepad_31bf3856ad364e35_6.1.7600.16385_none_cb0f7f2289b0c21a\notepad.exe
copy /y C:\notepad.exe C:\Windows\winsxs\wow64_microsoft-windows-notepad_31bf3856ad364e35_6.1.7600.16385_none_d5642974be118415\notepad.exe

Tags: ,

Scripting

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen | Modified by Mooglegiant