I have a requirement when a user clicks a specific arrangement of radio buttons to run a series of vbscripts (and soon Perl scripts).
I have all of the vbscripts stored server side, they do not need to be on the remote system to run. Oh yes, the scripts are gathering information on remote system in our intranet.
What would be the best way. Currently I have this to run just one script, not multiple...should I keep this or dispose of this idea.
Protected Sub windowsScript(ByVal COMPUTERNAME As String)
' Create an array to store VBScript results
Dim winVariables(1) As String
Dim filePath As String = COMPUTERNAME & "\C$\Windows\somefile.txt"
'Execute PsExec on script
runPsExec(COMPUTERNAME, "systemInfo.vbs", 1)
'Import data from text file into variables
textRead(filePath, winVariables)
System.Threading.Thread.Sleep(1000)
'Delete the file on server - we don't need it anymore
runPsExec(COMPUTERNAME, "systemInfo.vbs", 2)
MsgBox("Windows OS: " & winVariables(0).ToString())
MsgBox("Service Pack: " & winVariables(1).ToString())
End Sub
Also, it is hard to see here because I do have another function "textRead" but what is going on is this particular script is stored client side and the vbscript it outputting to a text file. textRead will read the variable and send a text file back to the server to read it.
This is definitely not what I want to do.
I want to be a little more dynamic, plus with my new scripts...they don't need to be on the client at all.
Any help would be appreciated :)
I'm thinking of making some type of While loop, not sure if that would work.
It's kind of strange to do this through the browser. In my company we collect systeminfo at logontime with a vbscript logonscript and add the result to a logfile which we can access through a webapp to do research. Occasionally when the need rises we run a specific script to gather more data or change some system setting through windows SCCM.
If the goal is to provide the user with info about his system there are some good utilities around which can be run locally (but from a location on a server share).
EDIT
a simple way to start multiple processes
dim scripts_to_run, script
const COMPUTERNAME = 0, SCRIPTNAME = 1, EXTRA_PARAMS = 2
scripts_to_run = Array(_
Array("computer1","script1.vbs",1),_
Array("computer2","script1.vbs",0),_
Array("computer3","script3.vbs",3)_
)
for each script in scripts_to_run
runPsExec script(COMPUTERNAME), script(SCRIPTNAME), script(EXTRA_PARAMS)
runPsExec join(script,",")
next
sub runPsExec(p1, p2, p3)
'here coms your code shat runs the script
wscript.echo p1 & p2 & p3
end sub
or a shorter version
dim scripts_to_run, aArgs
scripts_to_run = Array(_
Array("computer1","script1.vbs",1),_
Array("computer2","script1.vbs",0),_
Array("computer3","script3.vbs",3)_
)
for each aArgs in scripts_to_run
runPsExec aArgs
next
sub runPsExec(aArgs)
'here coms your code shat runs the script
wscript.echo aArgs(0) & aArgs(1) & aArgs(2)
end sub
Related
I wrote a program to easily store/edit my comic book collection. I can add, delete and request anything (comic/character/team) by my update statement doesn't work. I made a copy in a query in my access database and that worked perfectly. The strangest thing is that my program doesn't give any errors, it completes the transaction but doesn't change the data in my database. (this is a problem on both comic, character and team updates).
Here is my code to update a comic.
Public Sub UpdateComic(comic As Comic)
Dim cn As New OleDbConnection(persistenceController.connectiestring)
Dim cmd As New OleDbCommand("UPDATE tblComics SET serie = #serie, volume = #volume, issue = #issue, release = #release, inpossession = #inpossession, timesread = #read, story = #story, Languages = #languages WHERE ID = #ID", cn)
cmd.Parameters.AddWithValue("serie", comic.Serie)
cmd.Parameters.AddWithValue("volume", comic.Volume)
cmd.Parameters.AddWithValue("issue", comic.Issue)
cmd.Parameters.AddWithValue("release", comic.Release)
cmd.Parameters.AddWithValue("inpossession", comic.InPossession)
cmd.Parameters.AddWithValue("read", comic.Read)
cmd.Parameters.AddWithValue("story", comic.story)
cmd.Parameters.AddWithValue("ID", comic.ID)
cmd.Parameters.AddWithValue("Languages", comic.Language)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End Sub
Can anyone help me with this.
Thanks in advance.
Switch the position of the last two parameters added to the OleDbParameterCollection
cmd.Parameters.AddWithValue("Languages", comic.Language)
cmd.Parameters.AddWithValue("ID", comic.ID)
OleDb doesn't recognize the parameters by their name, but by their position. You should add the parameters in the exact order defined by the parameter placeholders in the command text
By the way. OleDb wants its placeholders parameter defined with the single question mark character (?), but MS-Access accepts also the syntax #name probably to have a better upgrade compatibility with its big cousin Sql Server.
I am trying to make a page that lets my admins read the MIRC Log files from our bot...I am having the hardest time trying to get this to work for some reason...i have taken bits and pieces of code to get what i have working...but it still either doesn't display at all OR after about 200 lines, it stops reading each line but instead make it one big mess of text...here is what i have for code
Protected Sub bView_Click(sender As Object, e As EventArgs) Handles bView.Click
Response.Write(Server.MapPath("~/mirc/logs/" & lbfiles.SelectedItem.Text))
lFileOut.Text = ""
Try
Dim FILENAME As String = Server.MapPath("~/mirc/logs/" & lbfiles.SelectedItem.Text)
Dim objStreamReader As StreamReader = New StreamReader(FILENAME, Encoding.UTF8)
Dim cont As String
Do
cont = objStreamReader.ReadLine()
lFileOut.Text = lFileOut.Text & cont & "<br>"
'Response.Write(cont)
Loop Until cont Is Nothing
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Here is a test file i have been testing everything on...it just doesn't do anything nor does it throw any error...i am completely stumped on this one.
test file
Do this: go into your server, in your root folder make a new folder called whatever you want then go into your mIRC script goto tools/options/logging change directory to the new folder you made click save.. that way you or anyone you want to view all logs from your mIRC script can view by going to www.yoursite.net/foldername and it will show you the list of all logged things, status and room window conversations...
If you want to know how to code it so your opers can just have a clickable link in their remotes I can do that for you as well.... hope this helps
Ive created a server monitoring script written in classic ASP (Hosted on IIS 7.5).
It has a main page which uses jQuery to automatically reload the content (updating WMI information) It works great, but seems to have an appetite for memory!
There are 4 pages (Service status for 2 servers, printer status on a main DC and disk usage on the same server) The service status pages update every 10 seconds, the printers every 5 seconds and disk usage every minute.
The script basically works for a few hours, then i get code 500 internal server errors, once checking the IIS logs its because of it being "Out of memory" and look at the processes on the server and WmiPrvSvc.exe (NETWORK SERVICE account) is in the hundreds (500mb) and the ISS worker process (w3wp.exe) is using about 50mb (there are other w3ps.exe processes that are higher)
Once i end them both it kicks back into action… Or if i stop the page/requests for a while (varies between 30 sec and 5 mins) the WmiPrvScs ends and i don't get the problem.
Is there a way to minimise the memory usage or is there a command to properly disconnect / clear the memory?
Below is the basics of one of my pages to give you an idea of what's going on...
Thanks, Paul.
<%
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("SELECT Caption, Started FROM Win32_Service WHERE StartMode = 'Auto'")
Set arrServices = Server.CreateObject("System.Collections.ArrayList")
intServices = colListOfServices.Count
For Each objService in colListOfServices
arrServices.Add objService.Caption & "#" & objService.Started
Next
arrServices.Sort()
Response.Write "<table width=""100%"" class=""tblServices"">" & vbCr
For Each strService in arrServices
If InStr(strService, ".NET Framework") = 0 AND InStr(strService, "Sophos Web Intelligence Update") = 0 AND InStr(strService, "Shell Hardware Detection") = 0 Then
' Above services, start at system startup and then stop after nothing to do
arrServiceDetails = Split(strService, "#")
strServiceName = arrServiceDetails(0)
strServiceStatus = arrServiceDetails(1)
End If
Next
Response.Write "</table>"
Set objWMIService = Nothing
Set colListOfServices = Nothing
Set arrServices = Nothing
%>
Are you calling the above code every 10 seconds?
I´m not sure, but i looks like you are creating a new WMI object / connection everytime and that adds up.
Instead try to keep the object around instead of recreating it. Something like a SingleTon class to hold the connection.
Also, try making a strongly typed class instead of the WMI query, you can do that by looking at this site: MGMTClassGen
I'm trying to upload an MP3 file to a site and finding the duration of the audio at the same time. I'm quite new to ASP and VB.NET, but I've managed to get the file to upload to the server using a file upload tool.
However I can't seem to figure out how to read the duration of the audio file?
I'm not particularly looking for a complete solution (although that would be nice), but if anyone could point me in the right direction I'd be very appreciative.
If you require any more information let me know and I'll add it to the question.
I've done this in a recent project using naudio (download using package manager). I've converted the code from c# quickly without testing so double check for errors.
private shared function GetMp3Duration(filename as string) as double
Dim duration as double = 0.0
using (fs as FileStream = File.OpenRead(filename))
Dim frame as Mp3Frame = Mp3Frame.LoadFromStream(fs)
while (frame isnot nothing)
if (frame.ChannelMode = ChannelMode.Mono) then
duration += frame.SampleCount / frame.SampleRate
else
duration += frame.SampleCount * 2.0 / frame.SampleRate
end if
frame = Mp3Frame.LoadFromStream(fs)
End While
End Using
return duration
End Function
I'm not convinced the "* 2.0" in the previous answer is appropriate. I tried this, and resulting duration was two times the actual, for a stereo mp3 sound sample. I suggest the following code, successfully tested in MSVS Community 2013:
Imports NAudio.Wave
'...
Private Shared Function GetMp3Duration(filename As String) As Double
Dim reader As New Mp3FileReader(filename)
Dim duration As Double = reader.TotalTime.TotalSeconds
reader.Dispose()
Return duration
End Function
hii add this code to trackbar timer dont forgot to add laber to player
Label4.Text = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.durationString
Attempting to keep this short: our shipping personnel use a Windows Mobile-enabled barcode scanner to scan the serial numbers of items shipped on customer orders. That data is submitted via asmx web service and a report is automatically printed to a networked printer showing customer info and the details of items shipped. All of this happens in an intranet environment.
Until recently, I was using the Microsoft Report engine built into Visual Studio (.rdlc files) to generate the reports and the code outlined here to print without user intervention. It worked fine that way for several years.
Recently, I ran up against some report formatting limitations in MS Reports and implemented the reports in Crystal Reports (10.5.3700) instead. The code works fine, but after running in production for a few hours to a day or more, the asp.net worker process is hanging (not sure if this is the appropriate term). The report generating/printing process runs forever without throwing an exception. Recycling the AppPool makes everything work again for a while.
The reports are using "push" mode where the report is given a typed dataset rather than accessing the database itself. To take the CR ReportDocument.PrintToPrinter() method out of the equation, I have considered exporting the generated reports to PDF or similar and then printing the resulting file independently. But I haven't found a great way to do that yet.
Researching the problem, I've read all kinds of complaints about the buggy-ness of Crystal, but I'm hoping that there's is a bug in my code related to cleaning up after the report is printed.
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportAppServer
Imports CrystalDecisions.Shared
Public Class CrystalReport
Private _report As ReportDocument
Public Sub New(ByVal Path As String)
_report = New ReportDocument()
_report.Load(Path)
End Sub
Public Sub SetDatasource(ByVal DataSet As DataSet)
_report.SetDataSource(DataSet)
End Sub
Public Sub AddParameter(ByVal Name As String, ByVal Value As Object)
Dim crParameterFieldDefinitions As ParameterFieldDefinitions = _report.DataDefinition.ParameterFields
Dim crParameter1 As ParameterFieldDefinition = crParameterFieldDefinitions.Item(Name)
Dim parameterValue As CrystalDecisions.Shared.ParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue()
parameterValue.Value = Value
crParameter1.CurrentValues.Add(parameterValue)
crParameter1.ApplyCurrentValues(crParameter1.CurrentValues)
End Sub
Public Sub Print(ByVal PrinterPath As String)
_report.PrintOptions.PrinterName = PrinterPath
_report.PrintToPrinter(1, True, 0, 0)
Close()
End Sub
Private Sub Close()
_report.Close()
_report.Dispose()
_report = Nothing
End Sub
End Class
Any ideas for debugging this further? I've never had to resort to real Windows debugging (WinDbg, Process Explorer, etc.), so any recommendation on which debugging tool to try first would be great.
Thank you.
It sounds like the report actually isn't being released, although by looking at your code you would think you are doing exactly that.
You might try Close()ing and Dispose()ing your report object on the Page_Unload event of your ASP.NET page. This forum post on the Microsoft ASP.NET forums talks about an issue where the maximum amount of report processing jobs is reached, but I imagine the issue could be related.