I've been researching this for a majority of the day and can't find the answer. I am relatively new to stackoverflow. Is there a certain etiquette for asking a number of questions (I've asked three in the last few days)?
Anyways,
Here is the code in a codebehind file. It executes a script systeminfo.vbs, and that is working fine. But in the script I have some variables assigned.
Dim WshShell = CreateObject("WScript.Shell")
WshShell.Run("wscript.exe c:\systeminfo.vbs")
vbscript
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
dim osName
osName = objOperatingSystem.Name
Wscript.Echo "OS Name: " & objOperatingSystem.Name
dim osVer
osVer = objOperatingSystem.Version
Wscript.Echo "Version: " & objOperatingSystem.Version
Wscript.Echo "Service Pack: " & _
objOperatingSystem.ServicePackMajorVersion _
& "." & objOperatingSystem.ServicePackMinorVersion
Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
Next
I want to use osName and osVer and put the values into a label on the ASP side.
I understand that osName and osVer are simple examples, but I just need to figure out the concept of putting variables from a VBScript into ASP. My client has multiple VBScripts they use on a daily basis and I need to automate those scripts and produce a report saying if it failed or not.
Thank you for the help.
David,
As a person new to Stack Overflow myself, I was happy to find this very comprehensive FAQ for Stack Exchange sites. See the 3rd question "Is there a limit on how many questions I can ask?" for an answer to your first inquiry.
Regarding the heart of your question, I agree with #Ramhound that using a log file to exchange information between your WSH/VBScript script and your ASP.NET page is a feasible approach.
What you need is the Scripting.FileSystemObject. Here is a comprehensive WSH reference as a downloadable Windows help file.
Hint: as the download page advises at the bottom, to unblock the help page, 1) Right click on script56.chm, 2) Choose Properties, and 3) Click on "Unblock."
You'll find an intro to FileSystemObject under the heading "Script Runtime."
One more suggestion: since you'll be running this script via ASP.NET in a multi-user environment, you may find you'll need to create a log file per user or per page access. If that is the case, you'll need to generate a temporary file name for each log file to avoid name collisions with other log files. To generate your temporary file, see GetTempName in the WSH reference.
Related
We're trying to read some log files for our application but FileExists is failing in every case. So I simplified the problem with this test code:
Dim filespec, msg
filespec = Chr(34) & "C:\Windows\explorer.exe" & Chr(34)
'filespec = "C:\Windows\explorer.exe"
'filespec = Chr(34) & "C:" & Chr(34)
'filespec = "C:"
'filespec = "default.asp"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " exists."
Else
msg = filespec & " doesn't exist."
End If
Response.Write(msg)
As you can see, we've tried testing with and without added Chr(32) (which is the double quote character). We're testing against the file C:\Windows\explorer.exe and the file C:\Windows\explorer.exe does exist on the computer hosting the asp files and the iis server. We even fail when simply checking to see if the C drive exist.
Additionally, it even fails if we try to see if the default.asp file exists and that file is in the same directory as our filetest.asp file.
Does anyone see why our FileExists is consistently failing? Thank you.
filespec = "C:\Windows\explorer.exe"
Without the additional quotes will work. To find a folder we need to use
fso.FolderExists
Instead of FileExists.
This still doesn't find the default.asp file in the same directory. But that problem is too far removed from our actual problem which is to look at log files on another drive. That problem is too far from this original question so I'll post that problem separately.
You may want to try to load the folder in to a folder object and loop through files in the folder object. Below is an example.
Set fso = CreateObject("Scripting.FileSystemObject")
FileToFind = "explorer.exe"
FolderToSearch = "C:\Windows\"
Set myFolder = fso.GetFolder(FolderToSearch)
For each myFile in myFolder.Files
If myFile.Name = FileToFind Then
Wscript.echo "Found " & myFolder.Path & "\" & myFile.Name
End If
Next
you do not need to insert additional quotes. removing your quotes will work just fine.
Dim filespec, msg
filespec = "C:\Windows\explorer.exe"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " exists."
Else
msg = filespec & " doesn't exist."
End If
Response.Write(msg)
In the past, I have only noticed that you need to insert additional quotes when using the wshshell.run since a space might be interpreted as additional arguments to the filename.
It appears that our problem is not in the VBScript at all. The app is running inside an ApplicationPool in iis. The Identity property of that Application Pool is the dynamically created applicationPoolIdentity user. This is a user with no permissions. So essentially, the application is running as a user which does not have access to any other drives. Therefore, it cannot find any file on any network drive. We will have to create an additional identity with the proper rights and set our applicationPool identity to use that custom account.
I found instructions on how to set this identity account here: http://technet.microsoft.com/en-us/library/cc771170%28v=ws.10%29.aspx
I am using classic ASP to download data from my web server into a word document. I am using the following headers in my ASP script to accomplish this...
Response.ContentType = "application/msword"
Response.AddHeader "Content-Disposition", "attachment;filename=gbResults.doc"
Response.write("<html " & _
"xmlns:o='urn:schemas-microsoft-com:office:office' " & _
"xmlns:w='urn:schemas-microsoft-com:office:word'" & _
"xmlns='http://www.w3.org/TR/REC-html40'>")
Response.write "<xml>" & _
"<w:WordDocument>" & _
"<w:View>Print</w:View>" & _
"<w:Zoom>90</w:Zoom>" & _
"<w:DoNotOptimizeForBrowser/>" & _
"</w:WordDocument>" & _
"</xml>" & _
The data I retrieve from my database is generated by this script following the above code and it successfully downloads the data and opens an instance of MS Word that contains the data returned...fully formatted for the user. This is working as expected.
My question...is it possible to open the instance of word so that the window is not maximized? We would like to keep the main browser in view because some users are thinking that they have left the application running in the browser because they can't see it when word is maximized.
Of course we do not know what browser the end user will employ so an solution that is cross browser compatible is what we're looking for.
I was unable to find a solution via xml, java or asl so far in my research. Any help is greatly appreciated.
I've got a little script (VBS) to change website attribute of all users :
dim objOU, objUser
objOU="OU=Users,DC=mysociety,DC=local"
Set objOU = GetObject("LDAP://" & objOU)
on error resume next
For each objUser in objOU
If objUser.Class="user" Then
Set objUser = GetObject("LDAP://" & objUser.distinguishedName)
objUser.Put "wWWHomePage", "http://mysite.mysociety.local/Person.aspx?accountname=mysociety\" & objUser.mailNickname
objUser.setInfo
if err.number <> 0 then
wscript.echo "Error processing " & objUser.givenName & ":" & err.number & ", " & err.Description
err.clear
end if
End if
Next
So my problem is that if I precise my objOU up to deepest directories it works perfectly. But it is not a recursive script and with this code it doesn't work because of subdirectories.
I am a very beginner with VBS, could you help me to make this script recursive ?
Thank you by advance and excuse me for my poor English
This task can be accomplished very efficiently using threads. In one thread, execute a search
wherein the base object is that point in the directory information tree (DIT) below which all
the entries that must be modified are stored. Use whole subtree for the search scope and a
filter that narrows the search results to just the entries that require modification. Use the
OID 1.1 for the list of requested attributes (this will cause the directory server to return
only distinguished names). Assuming the directory administrator allows this search - it may be
denied for resource reasons or security reasons or other reasons - as the search results arrive,
use another thread to construct the modifications on the distinguished names that are being
returned in the search thread. For maximum efficiency, use multiple threads to make the
modifications and use the appropriate concurrence mechanisms for your API.
see also
LDAP: Programming practices
LDAP: Search Best practices
I am working on an old asp project. I am new in project. My question is,
I required to execute the certain number of pages in a specific time but when I put in a loop to execute the page for certain pattern it execute only one pattern and shows time out expired problem. Though I searched in net what ever answer I get it will not fulfill my requirement. So my team lead said we have to find out some thing that can execute my page for 3 min each then it call back freshly. Is there any method is there in asp. as I am new in asp. as it possible or share some idea.
I want to execute for each pattern. Here is my simple code.
dim arrList()
dim mySQL,x,strPtrn
mySQL=""
x=0
strPtrn=""
mySQL="select distinct(pattern_no) from pattern_master where std between (dateadd(hh,8,getdate())) and (dateadd(hh,11,getdate()))"
set rstptrnmst= conn.Execute(mySQL)
do until rstptrnmst.EOF
for each ptrn in rstptrnmst.Fields
' Response.Write(x.name)
'Response.Write(" = ")
'Response.Write(x.value & "<br />")
ReDim Preserve arrList(x)
arrList(x)=ptrn.value
x=x+1
next
Response.Write("<br />")
rstptrnmst.MoveNext
loop
rstptrnmst.close
conn.close
'for each ptrn in arrList
'response.Write("<br>" & ptrn)
'next
for each ptrn in arrList
Session("pattern")=ptrn
server.Execute("processFNO.asp")
Session("pattern")=""
response.write("The first pattern " & ptrn & "<br />")
next
'Response.Redirect("processFNO.asp?fno="&arrList(0))
%>
So I want execute that page for each pattern. How can I? For each pattern it take 3 min(approx).any idea?
thanks for advance.
If your script is going to take that long to run you will need to set the script timeout option to cater for that:
<%
Server.ScriptTimeout = 180
%>
The timeout is set in seconds, with the default being 90. You should set this at the very top of your page.
More information about timeouts here: How do I increase timeout values
Is there any kind of online "quick" asp/vbscript test tool? It's a pain to load up a test page, put all the stuff in, when I just want to test some ASP VBScript.
Yes, they are called .vbs files. These files are plain text files with a .vbs extenstion. You can run them from the command line. There are some minor differences, just google vbs or WSCript.
One of the most annoying issues is you cannot use response.write instead you use WScript.Echo. This displays the result in a windows style popup messagebox. So, if you use it in a loop to display values, you will have to close the box once for each value that is displayed. Can be a pain. I just contcatonate the results and display one message.
For example save the below code as myloop.vbs
Dim strMsg
Dim i
strMsg = ""
for i = 1 to 10
strMsg = strMsg & CStr(i) & vbCrLf
next
WScript.Echo strMsg
Double-click on myloop.vbs and it runs.
This is a pretty cool way to test out a concept without having to create an asp page and load it on the server.
I realize this isn't a very good/correct answer, but I typically use VB6 (Visual Studio 6) as a quick interactive debuggable VBScript-equivalent testbed. Some syntax is different (CreateObject), and you need to add certain references to your "Default" testing project, but it does allow me to answer any question about type conversions etc within a few seconds (VB6 startup time + type/paste time + F5) rather than the few minutes it will take me to set up an ASP page, and even worse start up ASP debugging, which as of VS2008 and Windows 2003 is just a huge pain.