I'm a PHP / Javascript developer having to build a "simple" script that will run on a windows desktop that transfers a scanned image to a server. By using a .vbs script I have been able to do everything I need to do except send the file to the server. I have spent the last two days googling and trying examples, but nothing seems to work. Below is the code I'm currently fighting with.
Dim objShell,UserPath,sourcePath,strURL,stream, file, fileString, HTTPSevice, body
Set objshell = CreateObject("WScript.shell")
UserPath = objShell.ExpandEnvironmentStrings("%UserProfile%")
strURL = "www.notWebsite.com/uploader.php"
sourcePath = UserPath & "\Desktop\Scanned\scanned.jpg"
set stream = CreateObject( "Scripting.FileSystemObject" )
set file = stream.getfile(sourcePath)
set fileString = file.openAsTextstream
body = fileString.readAll
fileString.close
set xmlHttp = createobject("MSXML2.XMLHTTP.4.0")
xmlhttp.open "POST",strURL,false
xmlhttp.setRequestHeader "Content-Type", "multipart/form-data"
xmlhttp.send body
msgbox xmlhttp.responseText
The code doesn't throw an error, it just sends an empty request to the server.
Like I said before, I have no experience with developing for/on/near windows, so if a visual basic script isn't the right option, please let me know and point me in the right direction. I'm willing to learn how to make this work, but I'm just stuck on how to move forward.
Thank you in advanced for your help.
Using PowerShell is 100% the way to go for my usecase. Even though I've never heard of it before this morning, I already have the script working and ready for testing.
Related
I am currently tasked with moving one of our older bits of software to a new server. The old server is running 2008 and the new server is on 2019. The code is a mixture of ASP and ASP.NET, both using VB. Unfortunately, I'm a C# developer and my VB knowledge is slight.
The main bit of the code is the older and is all in ASP and works fine on the new server. For a particular set of customers there is an add-on that is more recent and uses ASP.NET. For the new section of code to get the details of the logged in user it uses the code given in this answer. Unfortunately it seems like it is this bit of code that is failing.
We have this bit of code in our site.master.vb
ctx1 = ctx.Request.Url.Scheme
ctx2 = ctx.Request.Url.Host
dom = ctx1 + "://" + ctx2
Dim ASPRequest As HttpWebRequest = WebRequest.Create(New Uri(dom + "/arc/asp2netbridge.asp?sessVar=" + sessionValue))
ASPRequest.ContentType = "text/html"
ASPRequest.Credentials = CredentialCache.DefaultCredentials
If (ASPRequest.CookieContainer Is Nothing) Then
ASPRequest.CookieContainer = New CookieContainer()
End If
The asp2netbridge.asp file is stored in the directory one up from the directory that contains the code and the directory structure looks the same on both servers. The contents of the as2netbridge file are the the same as in the example code linked above with the addition of some extra comments.
It then calls a Stored Procedure on our database with the customer ID from session that should return the customer details as XML, but instead we get a 'Root Element is missing' Error. If I change the Stored Procedure to hard code the customer ID in it, rather than as a parameter then it works as expected.
Is there anything that I need to install on our server to get the system working correctly? Or is there anything else I need to do to get it to work?
I'm trying to do some simple webscraping in OpenOffice (I usually work in Excel but I'm trying to port something over for a coworker that doesn't have Excel). However, when I try to run something very similar to this, it keeps giving me this BASIC runtime error 1.
Here's the relevant code, I'm not sure what I'm supposed to do to make this work.
Sub Macro1
Dim explorer As Object
Set explorer = CreateObject("InternetExplorer.Application")
explorer.Visible = True
explorer.navigate("www.yahoo.com")
Const READYSTATE_COMPLETE As Long = 4
Do While explorer.Busy Or explorer.readyState <> READYSTATE_COMPLETE
Loop
dim page as object
set page = explorer.Document
dim mailButton as object
set mailButton = page.GetElementByID("ybar-navigation-item-mail") 'this is the line the error occurs on
mailButton.Click
End Sub
Do you know that you can save script in vbs file (you have to delete types in variables declarations) and run it directly by double click without using office application? I recommend you to use this way.
I'm trying to improve security on an old ASP Classic site. I need to generate (truly) random numbers, and ASP itself doesn't seem to have that capability directly. So it occurred to me that I might run a Windows CLI script and use the results.
I've figured out how to run a script, but not how to return the results of that script to ASP.
Dim oShell, sCommand
sCommand = "C:\scripts\myscript.bat /foo"
Set oShell = Server.CreateObject("WScript.Shell")
Set oExec = oShell.exec(sCommand)
...?
Set oShell = Nothing
Can anybody help me with that last piece of the puzzle.
(Or... if you know a better way to generate truly random numbers in ASP Classic, that would be excellent)
Make the output of command redirected to text file. For example "dir >test.txt". Then read the file.
I'm working on replacing a system that primarily uses PDF files to give users their monthly reports.
The problem I'm having is being able to prevent one user from seeing another's information. For example if user1 has a file at www.mysite.com/user1/file.pdf they could edit the URL to www.mysite.com/user2/file.pdf and see the files of user2.
The way I've been trying to get around this is to disable anonymous access (it's an IIS server) to the user folders so it's impossible to get direct access to files and have view_file.asp bring in the file using ADODB.Stream. I'm having a problem though that some users have not been able to view the files. It seems to only be people using IE but it's hard to be sure.
I basically just need to either fix this to work in all browser/configs or find an alternative way to display the file through the browser.
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Type = 1
adoStream.Open()
adoStream.LoadFromFile "C:/path-to-file/" & curUser & curDir
Response.Buffer = true
Response.CharSet = "UTF-8"
Response.Clear
Response.ContentType = "application/pdf"
Do While Not adoStream.eos
Response.BinaryWrite adoStream.Read(1024 * 8)
Response.Flush
Loop
Response.End()
adoStream.close
Set adoStream=nothing
I have a small problem. I am busy trying to get messages from a classic asp website to twitter, but I can only find examples of how to do this using php and all other kinds of different languages except for classic asp. Is there anyone here that knows how to get it to work?
I have been looking on the net for over 2 hours and found nothing that gets close. Rewriting the php api that i found will take alot of time since it's using libraries which i won't put the time in to convert as this should be a fast solution.
People,
I have found the solution for classic asp Twitter message posting.
Since i have been looking for it quite a long time, I'll post the solution here so other people can make use of it. Actually it's a quite easy solution :).
Here we go:
function asp_twitter_update(strMsg,strUser,strPass)
dim oXml,strFlickrUrl
strFlickrUrl = "http://twitter.com/statuses/update.xml"
set oXml = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
oXml.Open "POST", strFlickrUrl, false, strUser, strPass
oXml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oXml.Send "status=" & server.URLencode(strMsg)
asp_twitter_update = oXml.responseText
Set oXml = nothing
end function
And usage of the function like this:
Dim xmlStatuses,strMsg
strMsg = "Hello twitter, send with Classic ASP"
xmlStatuses = asp_twitter_update(strMsg,"yvanruth","xxxlol")
Response.Write(xmlStatuses)