VBS file communication/execution - vbscript

I have a ftp server that i have written VBS scripts for, now I need an easy way to run them from my website. So i want to open my website, enter the username, password, users name and click submit, it must then run the VBS and insert the data and the VBS will then create the user on the FTP.
What is the best way to do this? should I load the VBS stuff into a application with webservice listener and build and execute it and then my site must communicate via the webservice, or should i rather build a local asp page and host it which when posted too runs the vbs file and gives it the data. Please explain how you would go about coding it if you leave a response :D

You could use
<%
Dim oWShell
Set oWShell = Server.CreateObject("WScript.Shell")
strCommand = "cmd.exe /c cscript C:\AbsolutePath\To\Your\VBSFile.vbs"
oWShell.Run strCommand, 1, true
Set oWShell = Nothing
%>
WShell and WShell.Run requires elevated access permissions on the web server. Make sure that the authenticated user (or IUsr) has those permissions.

Related

Running an Excel Macro Overnight When Logged Off and Shut Down using Task Manager

I have recently put together a report for my business and I want to have it scheduled to run at 10pm to email end of play sales.
My macro and everything runs fine.. it copies a table as text from an excel file linked to the source data via Power Query, then the table is pasted into an Outlook Email and sent to the distribution list.
Is there a way to send this out without being logged in or have my PC switched on?
I have tried using the "Run whether user is logged in or not" and "Run with highest privileges", but it wont run the task when that is selected.
Is there something I'm doing wrong?
Here is my .bat code
cscript "Q:\Sales\SendEmail.vbs" "Q:\Sales\Sales.xlsm"
Here is my .vbs code
Set args = WScript.Arguments
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open args(0)
objExcel.Visible = True
objExcel.Run "send_email"
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close(0)
objExcel.Quit
Is there something I'm fundamentally missing?

Transfer PDF file to ftp server in MS access 2007

I'm attempting to upload a pdf file to an ftp server. I've tried this by accessing the wininet dll but unsuccessfully.
What is the best way to do this in MS Access 2007 VB6? I can call a .net dll, but that is my last resort.
Thank you in advance.
If you mean VB6 then there's a control you can use for FTP functions. Go to Project/Components and add the "Microsoft Internet Transfer Control" to your project. It's fairly easy to use, but something like...
Inet.UserName = "Username"
Inet.Password = "Password"
Inet.Protocol = icFTP
Inet.RemoteHost = "123.123.123.123"
Inet.Execute , "put " & sFileToTransfer & " " & sFilenameOnRemoteHost
While Inet.StillExecuting
DoEvents
Wend
Check Inet.ResponseCode when it finishes
If you mean VBA in Ms/Access then you could write out a small batch file and then shell out to execute it.

Activex component can't create object:'xyz'

I have written the following piece of VB script which opens
an existing aplication xyz from the path I specfied.
The application (a custom windows application) opens succesfully.
(I would like to use the automation interface of this application
in my vb script.) for that I call CreateObject.
But, then I also get the error Activex component can't create object: 'xyz' for the line Set xyzObj = CreateObject("xyz").
The error is from this line, since if I remove this line there is no error.
Dim objShell
Set objShell = CreateObject( "WScript.Shell" )
objShell.Exec("C:\abc\def\xyz.exe")
Set xyzObj = CreateObject("xyz")
Set objShell = Nothing
You can't use CreateObject like that with a external program, started in your script or otherwise. CreateObject loads a COM-object that is registered on your pc. Google on vbscript and COM objects and you'll find plenty of info like at http://technet.microsoft.com/en-us/library/ee156598.aspx. If you want to interact with a started program you could use the sendkeys method or better use the autoit com object , see http://www.autoitscript.com/autoit3/docs/intro/ComRef.htm

Running vbscript in html file

I wrote vbscript inside my html file for my site and I can't get it to work. I know it only works in internet explorer as thats the common answer I see people write with this issue. I am able to get basic vbscript working, but when trying to use filesystemobjects to open a text file nothing happens. Code being used is below.
<Script type="text/vbscript">
Dim fsobj, objtxt, thearr
Set fsobj = CreateObject("Scripting.FileSystemObject")
Set objtxt = fsobj.OpenTextFile("./subfolder/foo.txt", 1)
thearr = split(objtxt.readline, ",")
document.write(thearr(0) & " and " & thearr(1))
</script>
I get the code to work when saving with asp extension but not when I save as html, is there a way to get it to work with only using the html extension? If not does someone have an explanation as to why scripting filesystemobject without the asp extension doesn't work? I seem to can't search for the answer I'm looking for.
When you were using the FileSystemObject from an ASP page, then you were manipulating the file-system of the server. This is permitted.
However, when you use the code above, you are executing the code on the client. It is not permitted to access the clients file-system from inside Internet Explorer, as it would have serious security implications. The technical term is "sandboxing".
If you need to interact with the file-system on the client machine, you will need to use a technology such as ActiveX.
When you run the script as client script, it would try to access the file from the client computer, not the server. The file isn't there, and even if it was, your script would not be allowed to access it.
You should consider using HTML Applications by renaming your file with a .hta suffix.
An HTA executes without the constraints of the internet browser security model; in fact, it executes as a "fully trusted" application.
HTML files running inside internet browsers are considered as "untrusted" because the code comes from the internet, and is generally considered as "untrusted" as such the browser enforces a tight security model that prevents those HTML pages gaining access to your computer, which is why the FileSystemObject is unable to open the text file. However, as a HTA it is no longer being run by your browser, but via Microsoft's MSHTA application which grants your script full trust.
For more information see HTML Application - Wikipedia.

Entering values to a dialogbox from windows scripting languages like vbs or WSh

I have a web page which when opened gives a dialog box for entering the user name and password. I am tired of giving the username & password every time. Can I code it into a windows script so that when I run the script, it will navigate to that page in IE and will fill the username textbox and password textbox in the dialogbox and click the OK button?
I have tried the following script in VBScript for navigating. the IE opens and navigates to the location but I'm stuck when the dialog box opens prompting for a username and password.
How do I fill them automatically from code?
Set IE = CreateObject("InternetExplorer.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")
IE.Navigate "http://www.google.co.in"
IE.Visible = True
There are three methods of accomplishing this.
SendKeys - You can use the SendKeys method to insert the username and password. It works, but it's not bulletproof and relies heavily upon the app behaving exactly as you anticipate.
HTTP Headers - You can set the HTTP headers so that they provide the username and password when requesting the page. IMHO, this is overly complicated.
Change the URL - If your page is using basic authentication, you can provide the username or username/password combination as a part of the page url. It looks like this:
http://username:password#www.mysite.com
Using this method, you don't even need a script. You can save a bookmark or shortcut with the URL. Understand, of course, the security risk of storing a password in plain text.
I'm assuming you are asking about Basic Authentication dialog.
See my answer here:
Equivalent of DefaultCredentials in VBScript

Resources