INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

ASP to .VBS

ASP to .VBS

(OP)
Hi, think this is the right forum?! I have a classic ASP script that works a treat to calculate directory sizes and write them back to a database, code below. The problem I have is I need to run the script in task scheduler on Windows server which you can't do with a .asp file. Apparently a .vbs file will.

Anyone know how I get this script to work and to be able to test it out?

Thanks for looking. (Raw ASP below)

CODE

<%

Dim connStrmpro
Set connStrmpro = Server.CreateObject("ADODB.Connection")
'connStr.Open "Provider=SQLOLEDB; Data Source = (CONCISE-HOST3\SQLEXPRESS); Initial Catalog = wce_site; User Id = sa; Password=concise"
connStrmpro.Open "PROVIDER=SQLOLEDB;DATA SOURCE=10.1.1.1,1433;UID=sa;PWD=password;DATABASE=mysite_db"

 'Option explicit

dim fso
dim objlogfile
dim objFolder
dim s
dim showfoldersize
dim dataFolder
dim colSubfolders
dim strsubfolders
dim objsubfolder
dim myDay 
    Function pd(n, totalDigits) 
        if totalDigits > len(n) then 
            pd = String(totalDigits-len(n),"0") & n 
        else 
            pd = n 
        end if 
    End Function
'Get Current DAte and Time
myDay = YEAR(Date()) & _ 
        "/" & Pd(Month(date()),1) & _ 
        "/" & Pd(DAY(date()),1)

		myDay = myDay& " "&time() 
		
Set dctSizes = CreateObject("Scripting.Dictionary")
dctSizes.Add 1073741824, " GB"
dctSizes.Add 1048576, " MB"
dctSizes.Add 1024, " KB"
dctSizes.Add 0, " Bytes"

set fso=createobject("scripting.filesystemobject")

Set objFolder = fso.GetFolder("e:\web\")


Set colsubfolders = objFolder.subfolders

For each objsubfolder in colSubfolders
	intSize = objsubfolder.size
	For Each intThreshold In dctSizes
		If intSize > intThreshold Then
			strSize = Round(intSize / intThreshold, 2)
			strSize = strSize & dctSizes(intThreshold)
			Exit For
		End If

	Next

qryinsnewlist = "INSERT INTO wce_dir_sizes (dir, size, serverip, recordedtime, day, month, year) VALUES (('"& (objsubfolder.name) &"'), ('"& (strSize) &"'), ('"& ("185.3.164.27") &"'), ('"& (myDay) &"'), ('"& (Day(date)) &"'), ('"& (Month(date)) &"'), ('"& (Year(date)) &"'))"
'response.write(qryinsnewlist)
Set oRsinsnewlist = connStrmpro.Execute(qryinsnewlist)
Next


%> 

RE: ASP to .VBS

For starters, remove the <% and %> tags, and change "Server.CreateObject" to just "CreateObject". Save as a vbs file and type "cscript myscript.vbs" at a command prompt (or double-click the vbs) to run it and check for errors.

Also, your reference to "e:\web\" may not work unless you are executing the script on the same server as the ASP page was on.

RE: ASP to .VBS

And, response.write string is replaced by wscript.echo string

RE: ASP to .VBS

(OP)
Hi Guitarzan,

Thank you so much for your advice, that worked perfectly!

Thanks again.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close