This question already has answers here:
Executing exe from asp page
(2 answers)
Closed 20 days ago.
I'd like to know what's the proper way of running a node script from within a ASP Classic / VBScript page.
I've tried to open a notepad file didn't work:
<%
CreateObject("Wscript.Shell").Run "C:\Windows\System32\notepad.exe"
%>
What I really want to do:
<%
Response.Expires=-1
session.LCID=1046
Dim user, numNF, programArgs, programPath
numNF = Request.Form("numNF")
user = Request.Form("user")
programPath = "C:\aloha\nodeProgram.js"
programArgs = numNF & " " & user
Dim oShell
Set oShell = Wscript.CreateObject("WScript.Shell")
oShell.Run("""C:\Program Files\nodejs\node.exe"" ""C:\aloha\nodeProgram.js"" ""numNF"" ""user""", 0, True)
Set oShell = Nothing
%>
Nothing Works!
As I was not managing to execute the node script with an ASP page, I changed the POST request url to an ASP.NET page with the following code:
<%# Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1;
Session["LCID"] = 1046;
string user, numNF, programArgs, programPath;
numNF = Request.Form["numNF"];
user = Request.Form["user"];
programPath = #"C:\inetpub\wwwroot\aloha.js";
programArgs = numNF + " " + user;
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = #"C:\Program Files\nodejs\node.exe";
startInfo.Arguments = programPath + " " + programArgs;
process.StartInfo = startInfo;
process.Start();
}
</script>
Now it works. Hope it helps!
Related
I designed a Form and it use to the sub Form
The Mainform is correctly display, but I use some action to show the sub Form and set Visible property of Mainform to false
The sub Form is displayed incorrectly
^^ Sub Form
^^ displayed
MainForm code:
Imports SearcherScreen = Osu_Offline_Searcher.My.SearcherScreen
Public Class SearcherOfOsu
Private ReadOnly SS As New SearcherScreen()
Private ReadOnly DOF As New DownloadOsuForm()
Private Sub Downloader_OnDownloadData(sender As OsuDownload.OsuDownloader, e As OsuDownload.OsuDownloader.DownloadDataEventArgs) Handles Downloader.DownloadData
If DOF.Created Then
DOF.ChangeProgressBar(e.Present)
Else
DOF.Icon = New Icon("osu!.ico")
DOF.Show()
Visible = False
End If
End Sub
Private Sub DetectButton_Click(sender As Object, e As EventArgs) Handles DetectButton.Click
Dim Detecter As New OsuDetect.DetectClass()
Dim UserDirectoryName = Detecter.DetectUserDirectory()
If UserDirectoryName = "No User" Then
MsgBox("I can't find any User.")
Else
Dim OsuDirectoryName = Detecter.DetectOsuDirectory(UserDirectoryName)
If OsuDirectoryName = "No Osu" Then
MsgBox("You don't download the Osu in defalut directory.")
Dim Result = MsgBox("Download Osu now?", MsgBoxStyle.YesNo, "Download Osu")
If Result = MsgBoxResult.Yes Then
OsuDirectoryPath.Text = Downloader.DownloadOsu(UserDirectoryName)
Visible = True
DOF.Close()
End If
Else
OsuDirectoryPath.Text = OsuDirectoryName
End If
End If
End Sub
Friend WithEvents Downloader As New OsuDownload.OsuDownloader()
End Class
Sub Form:
Public Class DownloadOsuForm
Sub ChangeProgressBar(Value As Integer)
OsuDownloadProgressBar.Value = Value
OsuDownloadLabel.Text = "Osu Downloading..."
End Sub
End Class
This the code of forms
and after here is the designer code
Sub Designer Code:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class DownloadOsuForm
Inherits System.Windows.Forms.Form
'Form 覆寫 Dispose 以清除元件清單。
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'為 Windows Form 設計工具的必要項
Private components As System.ComponentModel.IContainer
'注意: 以下為 Windows Form 設計工具所需的程序
'可以使用 Windows Form 設計工具進行修改。
'請勿使用程式碼編輯器進行修改。
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.OsuDownloadProgressBar = New System.Windows.Forms.ProgressBar()
Me.OsuDownloadLabel = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'OsuDownloadProgressBar
'
Me.OsuDownloadProgressBar.Location = New System.Drawing.Point(60, 205)
Me.OsuDownloadProgressBar.Minimum = 0
Me.OsuDownloadProgressBar.Maximum = 100
Me.OsuDownloadProgressBar.Value = 0
Me.OsuDownloadProgressBar.Name = "OsuDownloadProgressBar"
Me.OsuDownloadProgressBar.Size = New System.Drawing.Size(280, 30)
Me.OsuDownloadProgressBar.TabIndex = 0
'
'OsuDownloadLabel
'
Me.OsuDownloadLabel.AutoSize = True
Me.OsuDownloadLabel.Font = New System.Drawing.Font("新細明體", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(136, Byte))
Me.OsuDownloadLabel.Location = New System.Drawing.Point(105, 155)
Me.OsuDownloadLabel.Name = "OsuDownloadLabel"
Me.OsuDownloadLabel.Size = New System.Drawing.Size(190, 24)
Me.OsuDownloadLabel.TabIndex = 1
Me.OsuDownloadLabel.Text = "Osu Downloading..."
'
'DownloadOsuForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(9.0!, 18.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(400, 400)
Me.Controls.Add(Me.OsuDownloadLabel)
Me.Controls.Add(Me.OsuDownloadProgressBar)
Me.Margin = New System.Windows.Forms.Padding(1, 3, 1, 3)
Me.Name = "DownloadOsuForm"
Me.Text = "Downloading Osu"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents OsuDownloadProgressBar As ProgressBar
Friend WithEvents OsuDownloadLabel As Label
End Class
HTMLHeadElement vb6 add meta
I have vb6(the old version) and this code
Dim helement As HTMLHeadElement
I would like to add this meta tag(<meta http-equiv="X-UA-Compatible" content="IE=edge" />) to the document - WebBrowser1.document
based on this code -http://vbcity.com/forums/t/49404.aspx
in a DocumentComplete sub - prints out the document to text2
Dim htDoc As HTMLDocument
Dim htHead As HTMLHeadElement
Dim htMeta As HTMLMetaElement
'<meta http-equiv="X-UA-Compatible" content="IE=edge" />
Set htDoc = WebBrowser1.document
Set htHead = htDoc.getElementsByTagName("HEAD").Item(0)
htDoc.designMode = "on"
'Set htMeta = htDoc.createElement("META")
Set htMeta = htDoc.createElement("META")
'htMeta.httpEquiv = "MSThemeCompatible"
htMeta.httpEquiv = "X-UA-Compatible"
'htMeta.content = "Yes"
htMeta.content = "IE=edge"
Set htMeta = htHead.insertAdjacentElement("afterBegin", htMeta)
htDoc.designMode = "off"
Set htMeta = Nothing
Set htHead = Nothing
Set htDoc = Nothing
'getElementsByTagName("HEAD").Item(0)
'Me.Text2.Text = WebBrowser1.document.body.innerHTML
Me.Text2.Text = WebBrowser1.document.getElementsByTagName("HTML").Item(0).innerHTML
I want to call java servlet from from my vb 6.0 code. I have tu use the URL of the servelet on remote machine and display the message after execution of the program.
Private Sub Command3_Click()
Dim req As WinHttp.WinHttpRequest
Dim buffer As Variant
Set req = New WinHttp.WinHttpRequest
req.SetTimeouts 1800000, 1800000, 1800000, 1800000
req.Open "POST", "http://www.google.co.in", False
buffer = "tusharp 0"
req.Send cmbuffer
Debug.Print req.ResponseText
End Sub
Try this.....
Using following bunch of code you can simply call servlet by using URL. You can pass parameters via appropriate method.
**Private Function ExecuteSQL(ByVal sSQL As String, ByVal bResultSet As Boolean) As String
Dim http As Object
Dim strURL As String
Dim strPostData As String
Dim strHeader As String
Dim strResponse As String
On Error GoTo Err
Screen.MousePointer = vbHourglass
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
strPostData = "?Command=" & IIf(bResultSet, "SELECT", "UPDATE") & "&SQL=" & sSQL
strURL = "http://localhost:8080/FirstProject/DBConnector" & strPostData
http.setTimeouts 10000, 10000, 10000, 10000 'For some reason times out sooner than this sometimes
http.Open "POST", strURL, False
http.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.Send strPostData
strResponse = http.ResponseText
Screen.MousePointer = vbDefault
ExecuteSQL = strResponse
Exit Function
I have a page for deleting ORDER record. This page was called from AJAX, which work perfectly. However once I added some code that I made for updating inventory table at the same time. It seemed that AJAX function became malfunction and I can't figure out what is wrong with them. Please suggest me. Thanks in advance.
My AJAX function (order_edit.asp)
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(ID) { // delete order
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = '../engine/delorder_edit.asp';
var pmeters = "tID="+ID;
var bill_id = document.getElementById('bill_id').value; // additional for delorder_edit.asp
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 4) // Return Request
{
if(HttPRequest.responseText == 'Y')
{
document.getElementById("tr"+ID).style.display = 'none';
}
}
}
}
</script>
My delorder_edit.asp Page
<%
Option Explicit
Dim strID
strID = Request.Form("tID")
Dim Conn,strSQL,objExec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("../database/TKP.mdb"),"" , ""
'********** *****************************
'Open recorset in order to add od_qty back to tbl_inventory before this record was removed
'****** Once I added these code, my ajax became malfunction ******
Set rsOrder = conn.Execute("SELECT * FROM tbl_order WHERE od_id = "&strID&"" )
pd_id = rsOrder.fields.item("pd_id")
od_qty = rsOrder.fields.item("od_qty")
od_qty = DzToPcs(od_qty)
strSQL1 = "UPDATE tbl_inventory SET inv_qty_act = inv_qty_act + " & od_qty & ", inv_date = date() WHERE pd_id = '" & pd_id & "'"
Set objExec = Conn.Execute(sql1)
'*******************************************
strSQL = ""
strSQL = strSQL&"DELETE * FROM tbl_order "
strSQL = strSQL&"WHERE od_id = "&strID&" "
Set objExec = Conn.Execute(strSQL)
If Err.Number = 0 Then
Response.write("Y")
Else
Response.write("N")
End IF
Conn.Close()
Set Conn = Nothing
%>
First of all i will suggest to use the jQuery.ajax method to call the server method, so your code will be less and also more convenience to understand. And second thing, debug :
"HttPRequest.onreadystatechange = function()",
and check what value is being returned. Until unless we didn't get a exact error we can not suggest you a solution.
How can I get the description from an WMI class using vbscript?
I found this example but it's in C#:
// Gets the class description.
try
{
// Gets the property qualifiers.
ObjectGetOptions op = new ObjectGetOptions(null, System.TimeSpan.MaxValue, true);
ManagementClass mc = new ManagementClass(namespace,
classname, op);
mc.Options.UseAmendedQualifiers = true;
foreach (QualifierData dataObject in
mc.Qualifiers)
{
if(dataObject.Name.Equals("Description"))
{
classdesc =
dataObject.Value.ToString();
}
}
}
catch (ManagementException mErr)
{
if(mErr.Message.Equals("Not found "))
MessageBox.Show("WMI class or not found.");
else
MessageBox.Show(mErr.Message.ToString());
}
This image shows what I need.
Here's the VBScript equivalent of your C# code (only without error handling):
Const wbemFlagUseAmendedQualifiers = &H20000
strComputer = "."
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set oClass = oWMI.Get("Win32_LogicalDisk", wbemFlagUseAmendedQualifiers)
strDesc = oClass.Qualifiers_("Description").Value
WScript.Echo strDesc