Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1211
  • Last Modified:

Having trouble trying to execute a .vbs file from my .asp web application page

Hey,

   I have a web application and on one of the pages I have a button which when pressed by a user should run a .vbs script but it doesn't work....is it that the IIS server has to be set so that it can run both scripts and execute .vbs scripts???

I have the .vbs file in the same folder as the rest of my asp pages...

Any suggestions....needed ASAP hence the 500 points!!

Tanx in advance ; )
0
Dcom4CIT
Asked:
Dcom4CIT
  • 2
1 Solution
 
TheMCSECommented:
Can you be more specific?  Is the VBS script that you are hoping to run something that would execute client-side?  If you can post a code-snippet, I suspect that someone could help you out quickly.  Maintaining a *.vbs script on a web server would definitely be abnormal.  Most often if you wanted the script to execute client-side, the contents would be included in <script> tags within your ASP page.  If it needs to execute on the server, it would be "normal" ASP.  Good lucK!
0
 
Dcom4CITAuthor Commented:
Sorry TheMCSE

Here's the vbs code that is saved as NetSend.vbs (saved in the same folder as the rest of my ASP pages..)

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")


'* Connect to data source
objConnection.Open "Provider= Microsoft.Jet.OLEDB.4.0; Data Source=complete.mdb"
If Error <> 0 Then
     CScript.Echo "Error connecting to data source."
     CScript.quit
End If


'* SQL Query
objRecordset.Open "SELECT CompName FROM IPAddress" , objConnection, adOpenStatic, adLockOptimistic
arrIPAddresses = objRecordset.GetRows()
objRecordset.Close
objConnection.Close


'* File Copy
For Each strIPAddress in arrIPAddresses
     CScript.Echo "Updating " & strIPAddress
     objFSO.CopyFile "C:\Inetpub\wwwroot\Service Request Form.url","\\" & strIPAddress &"\C$\Documents and Settings\All Users\Desktop\", OverWriteExisting
     If Error <> 0 Then
          CScript.Echo "Error copying file to " & strIPAddress
     Else
          CScript.Echo "File copied to " & strIPAddress
     End If
     
Next


So any suggestions how to execute this from an asp page... i.e allowing the user to just press a button on my web application page and for it to execute the  .vbs code behind it????????????

     
0
 
TheMCSECommented:
This is likely going to prove tricky :)  Basically, you're going to have to overcome a couple of security hurdles.  Using the .vbs extension, I suspect your web server doesn't know what to do with the file type.  This should be converted to an ASP page to allow proper execution; if the script above were going to work, it would have to be executed on the web server.  Downloading it via HTTP (from the web server) would try to execute on the client devices, which wouldn't know much about wwwroot or your DB.  You can try something like this (obviously change the extension to ASP):

<%

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const OverwriteExisting = TRUE
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objConnection = Server.CreateObject("ADODB.Connection")
Set objRecordSet = Server.CreateObject("ADODB.Recordset")


'* Connect to data source
objConnection.Open "Provider= Microsoft.Jet.OLEDB.4.0; Data Source=complete.mdb"
If Error <> 0 Then
     Response.Write "Error connecting to data source."
     Response.End
End If


'* SQL Query
objRecordset.Open "SELECT CompName FROM IPAddress" , objConnection, adOpenStatic, adLockOptimistic
arrIPAddresses = objRecordset.GetRows()
objRecordset.Close
objConnection.Close


'* File Copy
For Each strIPAddress in arrIPAddresses
     Response.Write "Updating " & strIPAddress
     objFSO.CopyFile "C:\Inetpub\wwwroot\Service Request Form.url","\\" & strIPAddress &"\C$\Documents and Settings\All Users\Desktop\", OverWriteExisting
     If Error <> 0 Then
          Response.Write "Error copying file to " & strIPAddress
     Else
          Response.Write "File copied to " & strIPAddress
     End If
     
Next

%>

And now the hard part :)  What account is IIS running as?  Most of the above code should work, except the file copy (seems to be the key piece).  If you have permitted anonymous access, this is likely the IUSR_ account and it will only have access to the local machine.  If changing this is an option, you could let it run as an account with access to the devices in question.  If not, then you could always use the MapNetworkDrive method of the WScript.Network object.  This would allow you to specify alternate credentials when connecting to these devices.  Let me know how you would like to proceed and I'll post some more code.  Regards.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now