cmd or powershell command from html with no window - windows

is there a way to active a powershell or a cmd command from html file without opening a console window ?
for example the following code runs the l.bat file i have without showing the output but still there is a powershell window which is open while the file runs
code:
<OBJECT id=z classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" width=5 height=5>
<PARAM name="Command" value="ShortCut">
<PARAM name="Button" value="Bitmap::shortcut">
<PARAM name="Item1" value=",powershell.exe ,Start-Process &#45WindowStyle hidden 'l'">
</OBJECT>
any idea?

if you want run script or bat file in html file or in ur site want run script
you can use visual studio and add Web Application called PowerShellExecution
default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PowerShellExecution.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr><td> </td><td><h1 align="left">PowerShell Command Harness</h1></td></tr>
<tr><td> </td><td> </td></tr>
<tr><td> </td><td>PowerShell Command</td></tr>
<tr><td>
<br />
</td><td>
<asp:TextBox ID="Input" runat="server" TextMode="MultiLine" Width="433px" Height="73px" ></asp:TextBox>
</td></tr>
<tr><td>
</td><td>
<asp:Button ID="ExecuteCode" runat="server" Text="Execute" Width="200" onclick="ExecuteCode_Click" />
</td></tr>
<tr><td> </td><td><h3>Result</h3></td></tr>
<tr><td>
</td><td>
<asp:TextBox ID="ResultBox" TextMode="MultiLine" Width="700" Height="200" runat="server"></asp:TextBox>
</td></tr>
</table>
</div>
</form>
</body>
</html>
Tools menu select Library Package Manager >> Package Manager Console
Package Manager Console execute “Install-Package System.Management.Automation”
After a successful execution of that package install, you’ll want to add the reference to your Default.aspx.cs file:
using System.Management.Automation;
in ur Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Management.Automation;
using System.Text;
namespace PowerShellExecution
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ExecuteCode_Click(object sender, EventArgs e)
{
// Clean the Result TextBox
ResultBox.Text = string.Empty;
// Initialize PowerShell engine
var shell = PowerShell.Create();
// Add the script to the PowerShell object
shell.Commands.AddScript(Input.Text);
// Execute the script
var results = shell.Invoke();
// display results, with BaseObject converted to string
// Note : use |out-string for console-like output
if (results.Count > 0)
{
// We use a string builder ton create our result text
var builder = new StringBuilder();
foreach (var psObject in results)
{
// Convert the Base Object to a string and append it to the string builder.
// Add \r\n for line breaks
builder.Append(psObject.BaseObject.ToString() + "\r\n");
}
// Encode the string in HTML (prevent security issue with 'dangerous' caracters like < >
ResultBox.Text = Server.HtmlEncode(builder.ToString());
}
}
}
}
“PowerShell Command” window Get-EventLog Security -Newest 10 (or your favorite cmdlet for a test).
or put script on that just change
//shell.Commands.AddScript(Input.Text);
shell.Commands.AddScript("C:\\Scripts\\PowerShell\\PowerShellScript.ps1")
but for run script you should run
Set-ExecutionPolicy bypass
in your powershell 32 bit and 64 bit
64 bit
C:\Windows\System32\WindowsPowerShell\v1.0
32 bit
C:\Windows\SysWOW64\WindowsPowerShell\v1.0
you should run visual studio and publish in your iis very simple to add feature iis
for dns you can use
C:\Windows\System32\drivers\etc
in host file like
127.0.0.1 soheil.com
I hope i understand ur needs
Regards

Related

I'm using Microsoft Visual Studio 2013 c# Web App. Project with crystal Reports for Microsoft Visual Studio with service pack 13

I'm using Microsoft Visual Studio 2013 c# Web App. Project with crystal Reports for Microsoft Visual Studio with service pack 13
When I run the application and click show report not response just page refresh
<%# Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
</tr>
<tr>
<td>repsrc
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
</CR:CrystalReportSource>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnViewReport" runat="server" CssClass="myButton" OnClick="btnViewReport_Click" Text="عرض التقرير" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
enter code here
protected void btnViewReport_Click(object sender, EventArgs e)
{
ReportDocument reportdocument = new ReportDocument();
reportdocument.Load(Server.MapPath("~/MyReport.rpt"));
ConnectionInfo connectInfo = new ConnectionInfo()
{
ServerName = ".",
DatabaseName = "MyDataBase",
UserID = "sa",
Password = ""
};
reportdocument.SetDatabaseLogon("sa", "123");
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in reportdocument.Database.Tables)
{
tbl.LogOnInfo.ConnectionInfo = connectInfo;
tbl.ApplyLogOnInfo(tbl.LogOnInfo);
}
CrystalReportViewer1.ReportSource = reportdocument;
Problem Solved after download and setup version 12
http://downloads.businessobjects.com/akdlm/cr4vs2010/CRforVS_13_0_12.exe
and create a new project using the new version

Mono on Apache2 System.Web.Compilation.CompilationException: VBNC30451: Could not resolve the name 'Type'

I installed mono and mod_mono for apache2 running on Debian 7.
Though its giving me this error:
System.Web.Compilation.CompilationException
VBNC30451: Could not resolve the name 'Type'
Description: Error compiling a resource required to service this request. Review your source file and modify it to fix this error.
Details: VBNC30451: Could not resolve the name 'Type'
Error origin: Compiler
Error source file: /tempconvert.asmx
Exception stack trace:
at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath, System.CodeDom.Compiler.CompilerParameters options) [0x0035f] in /home/joaogl/mono-3.4.0/mcs/class/System.Web/System.Web.Compilation/AssemblyBuilder.cs:853
at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath) [0x00000] in /home/joaogl/mono-3.4.0/mcs/class/System.Web/System.Web.Compilation/AssemblyBuilder.cs:731
at System.Web.Compilation.BuildManager.GenerateAssembly (System.Web.Compilation.AssemblyBuilder abuilder, System.Web.Compilation.BuildProviderGroup group, System.Web.VirtualPath vp, Boolean debug) [0x00258] in /home/joaogl/mono-3.4.0/mcs/class/System.Web/System.Web.Compilation/BuildManager.cs:846
at System.Web.Compilation.BuildManager.BuildInner (System.Web.VirtualPath vp, Boolean debug) [0x0011c] in /home/joaogl/mono-3.4.0/mcs/class/System.Web/System.Web.Compilation/BuildManager.cs:469
How can I solve this?
If I understand the nature of your problem (I have had the same problem), then:
Follow this (https://library.linode.com/frameworks/mod-mono/debian-5-lenny) "mod_mono and Apache on Debian" installation instruction
Use this (http://go-mono.com/config-mod-mono/Default.aspx) to generate an Apache mod_mono configuration file.
If you have set up MonoServerPath whatever "/usr/bin/mod-mono-server2" in your apache2.conf - remove it
Then, you may test how if it works.
Create index.aspx and put it into your htdocs directory or how you call it
<%# Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//initialize a datetime variable with current datetime
DateTime now = DateTime.Now;
Label1.Text = "now : " + now.ToString();
//add 2 minutes to current time
DateTime dateAfter2Minutes = now.AddMinutes(2);
TimeSpan ts = dateAfter2Minutes - now;
//total milliseconds difference between two datetime object
int milliseconds = (int)ts.TotalMilliseconds;
Label1.Text += "<br ><br />after two minutes: ";
Label1.Text += dateAfter2Minutes.ToString();
Label1.Text += "<br ><br />smillieconds difference between to datetime object : ";
Label1.Text += milliseconds;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - datetime difference in milliseconds</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - datetime difference in milliseconds
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
Font-Names="Comic Sans MS"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="get milliseconds difference between two datetime"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>
It helped me.
Good luck!
apache2monomod-monodebianasp.netcompilation

How to Preview uploaded image using telerik RadAsyncUpload and RadBinaryImage in ASP Update Panel?

I have a web form in asp.net contains a RadAsyncfileupload and a RadBinaryImage inside an Asp Update Panel like following
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server">
</telerik:RadAsyncUpload>
<telerik:RadBinaryImage ID ="RadBinaryImage1" runat ="server" Width= "100px" Height="100px"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
in code behind
protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
{
if (RadAsyncUpload1.UploadedFiles.Count == 1)
{
byte[] image;
long fileLength = RadAsyncUpload1.UploadedFiles[0].InputStream.Length;
image = new byte[fileLength];
RadAsyncUpload1.UploadedFiles[0].InputStream.Read(image, 0, image.Length);
RadBinaryImage1.DataValue = image;
}
}
but in runtime program controller does not fire RadAsyncUpload1_FileUploaded event
I have searched the Telerik forum and found that I should do something to script manager but I need some help on how to do it the reason is that in order to fire this event whole page should post back anyway some scripts can help me or any other ways!
mention that I need byte array of the image to save it in DB.
Thanks in advance
Saeed Soleimanifar
http://demos.telerik.com/aspnet-ajax/asyncupload/examples/persistuploadedfiles/defaultvb.aspx?#qsf-demo-source
I just added the same functionality by using this , if you find any problem let me know...
OR
Here is the part that does the magic
Page Source :
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function updatePictureAndInfo() {
__doPostBack('btnImgUpload', 'RadButton1Args');
}
</script>
</telerik:RadScriptBlock>
<telerik:RadBinaryImage runat="server" ID="imgBinaryPhoto" ImageUrl="~/Images/default-profile-pic.png"
Width="100px" Height="100px" ResizeMode="Fit" AlternateText="No picture available"
CssClass="preview"></telerik:RadBinaryImage>
<br />
<telerik:RadAsyncUpload ID="upldPhoto" runat="server" AllowedFileExtensions=".jpg,.png,.gif,jpeg,.tiff"
MaxFileInputsCount="1" MultipleFileSelection="Disabled">
</telerik:RadAsyncUpload>
<asp:Button ID="btnImgUpload" runat="server" Text="Upload" CssClass="button" OnClientClick="updatePictureAndInfo(); return false;" />
Code Behind:
Protected Sub FileUploaded() Handles upldPhoto.FileUploaded
Dim bitmapImage As Bitmap = ResizeImage(upldPhoto.UploadedFiles(0).InputStream)
Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream()
bitmapImage.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)
imgBinaryPhoto.DataValue = stream.ToArray()
End Sub

Only one instance of a ScriptManager can be added

Why do I get this error message: Only one instance of a ScriptManager can be added to the page?
I haven't been using HTML comment to hide an ASP.NET server tag and there is no other ScriptManager in the entire project.
Markup:
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblCount" CssClass="LikeCount" Text='<%#Eval("LikeCount") %>' runat="server"></asp:Label>
<asp:LinkButton ID="lbAddOne" CssClass="LikeAddOne" Text="+1" runat="server" OnClick="lbAddOne_Click" CommandArgument='<%#Eval("ReviewID") %>'></asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
Code-behind:
protected void lbAddOne_Click(object sender, EventArgs e)
{
LinkButton _sender = (LinkButton)sender;
string ReviewID = _sender.CommandArgument;
int UserID = ((User)Session["LoggedInUser"]).UserID;
lblCount.Text = (int.Parse(lblCount.Text) + 1).ToString();
CategoryAccess.AddLikeReview(ReviewID, UserID);
}
just add a reference to scriptmanager in the masterpage, then it will be available to any page referencing the master. this will be easier to maintain in the long run rather than adding references to individual pages.

Add javascript to generated html test page for Silverlight project

VS2010, Silverlight 4.0.
Does anyone know if there is a way to have Visual Studio add javascript (or anything for that matter) to the html test page it generates when compiling a silverlight project for debug? Does it use a template, and if so, where is it?
Really interesting question!
I've tried to do something like that and finally found raw but pretty working solution:
First of all you should set specific page by using Properties -> Debug -> Specific Page.
My page example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>SilverlightApplication1</title>
<script type="text/javascript">
</script>
</head>
<body>
<div id="fillWithData">
</div>
<form id="form1" runat="server" style="height:100%">
<div id="silverlightControlHost" style="height: 100%; text-align:center">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="30%" height="30%">
<param name="source" value="file:///C:/Users/Igor/Documents/Visual Studio 2010/Projects/MobileTest/SilverlightApplication1/Bin/Debug/SilverlightApplication1.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50826.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>
</body>
</html>
NOTE: blank script and div elements is important! we'll load dynamic js/html into them.
My silverlight xaml.cs:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
HtmlDocument hostPage = HtmlPage.Document;
ScriptObject obj = hostPage.GetElementsByTagName("script")[0];
obj.SetProperty("innerHTML", "function alertonclick() { alert('Amazing! I am dynamic javascript!'); }");
HtmlElement ipAddressHtml = hostPage.GetElementById("fillWithData");
ipAddressHtml.SetProperty("innerHTML", #"<input id=""Button1"" type=""button"" value=""button"" onclick=""alertonclick();"" />");
}
}
VERY IMPORTANT NOTE: I've tested this code and it works only under Opera.
If you need to test something using some other browser then you sould inline javascript directly into element.
Example:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
HtmlDocument hostPage = HtmlPage.Document;
HtmlElement ipAddressHtml = hostPage.GetElementById("fillWithData");
ipAddressHtml.SetProperty("innerHTML", #"<input id=""Button1"" type=""button"" value=""button"" onclick=""alert('Amazing! I am dynamic javascript!');"" />");
}
}
This code works well under IE/FF/Chrome/Opera (of course :) ).
As for me I like first example with both dynamic js and html. And I'm pretty sure that it's possible to fix it and make acceptable by other browser not just Opera.
I hope that my examples will help you =)

Resources