Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP to .VBS 1

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
0
0
GB
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


%>
 
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.
 
And, [tt]response.write string[/tt] is replaced by [tt]wscript.echo string[/tt]
 
Hi Guitarzan,

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

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top