Help with a script dealing with services
The client is Windows XP SP1.
In the properties of the service, under the recovery tab, I want to
modify the following:
first failure: Restart the service
second failure: restart the service
subsequent failure: restart the service
Can this be done with vbs scripting?
--
Eric Sabo
NT Administrator Tag: Test Post Tag: 157111
Free Currency Conversion Web Services?
Is anyone aware of free currency conversion web services? I have an
application that the user must enter the currency conversion rate and if
possible I'd like them simply to pick the type of currency (and then
retrieve the latest conversion information).
Any help would be greatly appreciated.
BBB Tag: Test Post Tag: 157110
How to get the current folder?
How can you get the current folder within a vbscript-program?
I worked around this problem by creating a filesystemobject with the
filename of my program and split the file-path... but if someone was
to change the filename of my program, this wouldn't be working
anymore...
Any suggestions? Tag: Test Post Tag: 157105
Crete exel charts with asp
Hi
I found this code to crete excel charts, with asp, but Im having problems creating custom type charts, I think I need the gallery constants, but I don't know where to find. Can someane take alook at the code and advise
Thanks
Alban
Code asp and html source
<%@ LANGUAGE="VBSCRIPT" %><%
Option Explici
'--------------- WEB SITE: YOUR WEB SITE NAME ---------------
' File Name: 10MinChart.as
' Purpose
' Genearate a Chart using Microsoft Excel in an ASP pag
' Arguments
' Comment
' Author: Rama Ramachandra
' Imperium Solution
' http://www.imperium.co
' Internet: rama@imperium.co
' Date Created
' 8/29/200
' Modification History
'---------------------------------------------------------------------
Dim mintPass, mstrFileNam
Dim i ' misc variabl
Randomize Time
mintPass = Request("pass"
Select Case Int(mintPass
Case
HandleRepeatVisi
End Selec
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE>Create "Excel"lent Charts with ASP</TITLE><STYLE TYPE="text/css"><!-- /
BODY
font-family: Verdana, Arial, Helvetica, Sans Serif
font-size: 10pt
TH
font-family: Verdana, Arial, Helvetica, Sans Serif
font-size: 10pt
font-weight: bold
background-color: #DDDDDD
TD
font-family: Verdana, Arial, Helvetica, Sans Serif
font-size: 10pt
background-color: #EEEEEE
// --></STYLE></HEAD><BODY BGCOLOR="#FFFFFF"><BASEFONT FACE="Verdana, Arial, Helvetica, Sans Serif" SIZE="2"><FORM ACTION="10MinChart.asp" METHOD="post"><INPUT TYPE="hidden" NAME="pass" VALUE="1"><TABLE BORDER="0" CELLPADDING="5" CELLSPACING="2" WIDTH="750"><TR><TD ALIGN="CENTER" VALIGN="TOP" COLSPAN="3"><STRONG>Create "Excel" lent Charts with ASP!</STRONG></TD></TR><TR><TD ALIGN="CENTER" VALIGN="TOP" COLSPAN="3"><STRONG>- by Rama Ramachandran</STRONG>  
<FONT FACE="ARIAL" SIZE="1"><A HREF="10MinChart.Zip">Get the Code for this page here</A>.</FONT></TD></TR><TR><TD ALIGN="CENTER" VALIGN="TOP">Stock Price for:</TD><TD ALIGN="LEFT" VALIGN="TOP"><INPUT TYPE="text" NAME="co" SIZE="25" VALUE="Microsoft"></TD><TD ALIGN="CENTER" VALIGN="MIDDLE" ROWSPAN="13"><% If mstrFileName <> "" The
Response.write "<IMG SRC=""/graficos/chartExcel2/" & mstrFileName & """>"
Els
Response.write "<IMG SRC=""spacer.gif"" WIDTH=""100"" HEIGHT=""1"" BORDER=""0"">
End I
%></TD></TR><
For i = 1 to 12 %><TR><TD ALIGN="LEFT" VALIGN="TOP">Date: <%= FormatDateTime(i & "/01/99", 2)%></TD><TD ALIGN="LEFT" VALIGN="TOP">$ :<INPUT TYPE="text" NAME="v<%= i%>" VALUE="<% If mintPass=1 Then Response.Write Request("v" & i) Else Response.Write Int((100)*Rnd+1) End If %>" SIZE="10" MAXLENGTH="5"></TD></TR><
Next %></TABLE><INPUT TYPE="submit" NAME="cmd" VALUE=" Generate Chart"></FORM></BODY></HTML><
Sub HandleRepeatVisit(
Dim xlapp ' Our Excel Ap
Dim wb ' Our Workbook within the Excel Ap
Dim ws ' Our Worksheet within the Workbook
Dim crt ' The chart objec
Dim SourceRange ' The Source Range for the chart objec
Const xlWorkSheet = -4167
Const xlLineMarkers = 6
Const xlCombination = -411
Const xlColumn =
Const xlBuiltIn = 2
Const xlUserDefined = 2
' -- Create an instance of Excel Applicatio
Set xlapp = Server.CreateObject("Excel.Application"
' -- Create a new workboo
Set wb = xlapp.Workbooks.Add(xlWorksheet
' -- Grab the first worksheet of the new workboo
Set ws = wb.Worksheets(1
' -- Insert the data the user requeste
' -- First, the titl
ws.Range("A1").Value = Request("co") ' -- defaults to "Microsoft
' -- Then the data in two vertical column
For i = 1 To 1
ws.Range("A" & i + 1).Value = FormatDateTime(i & "/01/99", 2
ws.Range("B" & i + 1).Formula = "=" & Request("v" & i)
Nex
' -- Set our source range
Set SourceRange = ws.Range("A2:B13"
' -- Create a new Chart Objec
Set crt = ws.ChartObjects.Add(20, 20, 300, 200
' -- Generate the Chart using the ChartWizar
' -- Syntax is:
' -- crt.Chart.ChartWizard Source:=SourceRange, gallery:=xlLine(4), PlotBy:=xlColumns(default),
' -- categorylabels:=1, serieslabels:=0, HasLegend:=2, Title:="Company Stock Value"
crt.Chart.ChartWizard SourceRange, 4, , 2, 1, 0, 2, Request("co") & " Stock Value"
' -- Configure the Chart
crt.Chart.ChartType = xlLineMarkers
crt.Chart.SeriesCollection(1).Name = "Sheet1!R1C1"
crt.Chart.HasTitle = True
crt.Chart.Axes(1, 1).HasTitle = True
crt.Chart.Axes(1, 1).AxisTitle.Characters.Text = "Months"
crt.Chart.Axes(2, 1).HasTitle = True
crt.Chart.Axes(2, 1).AxisTitle.Characters.Text = "Stock Price"
' -- Determine the name to save this chart as. Use the current Seconds value, overwriting previous
' -- ones
mstrFileName = "junk" & Second(Now()) & ".jpg"
' -- Save the chart on web server
crt.Chart.Export Server.Mappath("/graficos/chartExcel2/") & "\" & mstrFileName, "jpg"
' -- Fool Excel into thinking the Workbook is saved
wb.Saved = True
' -- Set all objects back to nothing
Set crt = Nothing
Set wb = Nothing
' -- Quit Excel to conserve resources
xlapp.Quit
Set xlapp = Nothing
' -- Make sure the Image is not cached but is loaded fresh from the web server
Response.AddHeader "expires","0"
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control","no-cache"
End Sub
%> Tag: Test Post Tag: 157102
integer ?
Hi
I need to use the "If" to check a number, I want to check a number i
an integer, if it isnt I want to go back and generate another numbe
if it is I want to leave the sub
This is a general description of what I am trying to do,
I have tried " If num <> Int Then ", But this doesnt work ca
anyone tell me the correct statement I should use
Thanks Tag: Test Post Tag: 157098
Migrating Printers
I have zero experience with VB, and I have figured out a way to migrate printers by grabbing a couple of values from the Registry, but it doesnt work out so good if i use the whole key. can anyone help out with grabbing specific values from a machine and exporting them to a file such as "username.reg". TIA
REGEDIT
[HKEY_CURRENT_USER\Printers\Connections\,,sdprint1,HP4100TN-21
"Provider"="win32spl.dll
"Server"="\\\\sdprint1
[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices
"\\\\sdprint1\\HP4100TN-21"="winspool,Ne04:
[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts
"\\\\sdprint1\\HP4100TN-21"="winspool,Ne04:,15,45 Tag: Test Post Tag: 157092
paste html code into excel cell?
Anybody can help me?, I need take an string that is HTML code and paste by
code into an excel cell. The code must be shown interpretate, thus in the
same way that if you go to the browser select a pieze of web page and select
copy, go to an excel book and paste it!, anybody have an idea?
Thanks Tag: Test Post Tag: 157081
Path info for VBscript from HTM page
I would like to run a vbscript from a html page on my website.
Being new to this game I made something like:
Set fso = CreateObject("Scripting.FileSystemObject")
set f=fso.opentextfile("mytext.txt", 8, true)
f.writeLine "this is new text"
f.close
This script was placed in a html file (under Frontpage), located in folder
c:\my documents\myweb.
The script runs fine, but the file mytext.txt is placed in the folder
C:\Documents and Setting/MyName, when I run the script under Frontpage, and
it is put on my Desktop when I run the script from the HTML file. When I
upload the html file to my website and run the script I get an error.
Neither is what I want, because basically I want to access (for read and/or
write) a textfile located in the folder with my html document with the
script in it, be it local on my PC or on my Website.
So, if my_file.html (with a script in it) how do I retrieve its absolute or
relative path, when it can sit on my PC or the Website with my provider
Thanks for any suggestions.
Ko Vijn Tag: Test Post Tag: 157079
vb script to VB
H
I need to make a vb script to EXE. But searching the web a few days, advise is to import the script to VB
Anyone can advise how ? And any tools to do it
Thank Tag: Test Post Tag: 157075
Error Handling
Below is my practice sript to display domain names. computers therein and
computer roles. However, the error handling doesn't appear to work...or I
don't understand the correct implementation. Probably the latter.
The computers listed may not acutally be on the network and I thought the
error subroutine would capture and display a message, then move on to the
next iteration..
Can one of you experts give me a correction to this? Thanks!
'***********************************************************************
'Script Name: show_domain_info.vbs
'***********************************************************************
'Initialization Section
Option Explicit
On Error Resume Next
'Variables
Dim colDomains, colRole
Dim objDomain, objUseDomain, objWMIService, objRole
Dim strComputer
Dim strComputerRole
'Constants
Const SPACES = " "
'Main Processing Section
'Display to console the list of domains
'Find all the computers in each domain and write out to the console the
'computer name, domain name, domain role
'Intialize & Bind to the provider
strComputerRole = Spaces
Set colDomains = GetObject("WinNT:")
For Each objDomain in colDomains
Set objUseDomain = GetObject ("WinNT://" & objDomain.Name)
'This is supposed to display an error message if the value is not Zero. The
Subroutine is below.
ErrorHandler
objUseDomain.Filter = Array("Computer")
ErrorHandler
For Each strComputer In objUseDomain
DetectRole
Next
Next
'Subroutines
Sub DetectRole
'Next line for trouble shooting. remarked out.
'Wscript.Echo "in DR " & "Domain= " & objUseDomain.Name & " ComputerName= "
_
& strComputer.Name & "before"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer.Name & "\root\cimv2")
ErrorHandler
Set colRole = objWMIService.ExecQuery ("SELECT * FROM
Win32_ComputerSystem")
For Each objRole in colRole
Select Case objRole.DomainRole
Case 0
strComputerRole = "Standalone Workstation"
Case 1
strComputerRole = "Member Workstation"
Case 2
strComputerRole = "Standalone Server"
Case 3
strComputerRole = "Member Server"
Case 4
strComputerRole = "Backup Domain Controller"
Case 5
strComputerRole = "Primary Domain Controller"
End Select
WriteReportLine
Next
'Next line for trouble shooting. remarked out
'Wscript.Echo "out DR " & "Domain= " & objUseDomain.Name & " ComputerName= "
_
& strComputer.Name & " Role= " & strComputerRole & "after"
End Sub
'Check for value Not Equal to zero and display message, clear error.
Sub ErrorHandler
If Err.Number <> 0 Then
Wscript.Echo objUseDomain & " " & Err.Description
Err.Clear
End If
End Sub
'Write Report line to console and clear variable for next iteration
Sub WriteReportLine
Wscript.Echo "Domain= " & objUseDomain.Name & " ComputerName= " _
& strComputer.Name & " Role= " & strComputerRole
strComputerRole = SPACES
End Sub Tag: Test Post Tag: 157074
making .bat file an .exe file
Forgive me if this is the wrong ugroup. I am trying to make a
self-extracting installation file (of a VBA project), and the installer
software demands an executable file (with extension ".exe"). I have a .bat
file that does all I need it to do (as well as a .xls file), but don't know
how to make that .bat file code "become" an .exe file. Being a complete
novice, I don't even know how ridiculous this question is, but can anyone
help me?
TIA, guys. Tag: Test Post Tag: 157069
Tabbed Pages ?
Hi,
I would like to create a program that has a few app's in one but are
shown by tabbed windows, how do I do this in VB6,
The other thing is how to make a small program form moveable without
the title bar, because it seems that it uses the title bar as a
handle and when I remove it , it becomes immoverable.
Thanks :) Tag: Test Post Tag: 157068
retrieving an ip address
Hey all
is there a way to retrieve the ip address that is being broadcasted by my router to the internet
ari Tag: Test Post Tag: 157065
WMI enumerate printers in ASP page missing shared printers
Hello
If I use the following vbs script on a Win XP machine I get all the printers no proble
strComputer = ".
Set oSvc = GetObject("winmgmts:\\" & strComputer & "\root\cimv2"
Set Printers = oSvc.Get("win32_printer").Instances
for each printer in Printer
WScript.Echo "Printer: " & printer.name & vbTab & "Default? " & printer.Defaul
nex
If I do the same thing in ASP I only get local printers. I don't get printers that are shared from another machine that have drivers loaded on the machine I run the asp script on. Here is the code
<
strComputer = ".
Set oSvc = GetObject("winmgmts:\\" & strComputer & "\root\cimv2"
Set Printers = oSvc.Get("win32_printer").Instances
for each printer in Printer
Response.Write "Printer: " & printer.name & vbTab & "Default? " & printer.Default & "<br>
nex
%
I have tried all kinds of security permissions settings to no avail and am stumped at this point. Any suggestions Tag: Test Post Tag: 157059
Getting computer name of user connecting to XP via remote desktop
Hi,
I need to complete a script that runs at login when a user on the LAN RDP's
to an XP Pro PC using remote desktop. What I am trying to do is to update a
key in the registry of the XP PC being accessed with an identifying
characteristic of who is connected to it, such as the IP address or the
computer name of the machine the person is coming in from, or his/her user
name. Whatever I try just returns the local computer name and local username
of the login at the XP RD session (which is always the same regardless of
who connects to it).
Any ideas?
Thanks
Gary Tag: Test Post Tag: 157051
code for a tab in a string?
Hello,
in the code on my website I use the following code:
dim strText
strText = "Hello," & vbcrlf & "I'm Fredeirk" & " I live in Belgium"
I use the vbcrlf to enter a new line and but before the text 'I live in
Belgium', I want some opening, now I use some spaces.
Does someone now how to enter a tabulator (tab) in the code instead of some
spaces?
kind regards,
Frederik Tag: Test Post Tag: 157047
Mapping printer / installing drivers (locally) via logon script.
A bit of background. Majority of our users print images from a shoddy
imaging software called filenet. The only way it recognises printing
is from an LPT1 port. What we do is install a local printer on LPT1
and map LPT1 to the sharename of the printer in DOS.
Now what i am trying to do is develop a vbscript whereby it looks for
the computer name in a dat file, maps the LPT1 port, tells it which
printer to install (has to be installed locally), makes it the default
printer...all according the the dat file.
I've done the first bit as follows with ALOT of struggle (i am not a
developer by the way):
'*** VBScript Logon Script version 1.0 ***
'
'This logon script should start after the batch file to check for WSH
and VBScript has finished.
'
'Declaring variables
Dim objFSO 'Object file system
Dim objStream 'Object for entering printer.dat and shares.dat
Dim strText 'Variables to contain lines from printer.dat
Dim objWshNetwork 'Object network
Dim objWshShell 'Object shell
Dim strComputerName 'Variable which contains the PC Name
Dim arrFields 'Array which contains mapping info after Split
function
'Creating object objWshShell, objWshNetwork and objFSO
Set objWshNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWshShell = Wscript.CreateObject("Wscript.Shell")
'Creating variables for username and PC name using objWshNetwork
strComputerName = objWshNetwork.ComputerName
'*** CONNECTING PRINTERS ***
'
'Creating object objStream to contain printer.dat
Set objStream = objFSO.OpenTextFile("C:\testing\printer.dat", 1)
'Starting a loop to read objStream and search for all mappings for
a PC Name
Do While not(objStream.AtEndOfStream)
strText = objStream.ReadLine
arrFields = Split(strText,";")
'Mapping the printer if match
Err.Clear
On Error Resume Next
if ucase(strComputerName) = ucase(arrFields(0)) then
objWshNetwork.AddPrinterConnection arrFields(1),arrFields(2)
end if
if Err.Number <> 0 then
Wscript.Echo Err.Number, Err.Description, Err.Source
end if
Loop
objstream.close
The printer.dat has entries like as follows:
computername;LPT1:;\\servername\sharename;"\\path to inf file for
driver installations";Printer name in INF file to make default;
Now i am struggling big time with the telling it which printer it
should install from the dat file. My thinking is going along the lines
of the "objwshShell.run rundll32" commands. I've tried adding the
ucase feature to this commands, but its not having any of it.
I know i am on the right lines (or so i hope so) can someone, please
please please give me some tips and advice on how i can finish this
off?
Best Wishes... Tag: Test Post Tag: 157042
Title Bar ?
Hi
I am making a small program with VB6 and have got stuck on a fe
points , Please help if you can :-
Is it possible to have no Title Bar in the program, if so how do
disable it
How do I enable a "mouse over "Tool Tip""
How do I enable a "Right click , Context menu"
Thanks Tag: Test Post Tag: 157040
Help with Reading REG Keys
Hi scripting experts. I would like a good lead with my current project if
anyone wants to lend a hand. My goal is to read the registry and check for
2 keys. If both exist delete one of them. If only one exist then do
nothing. Below is my sample code.
Thank you,
Juan
Option Explicit
Dim strComputer, objReg
Dim strKeyPath, subkey, arrSubKeys
Dim delKey
Dim return
Dim strKeyPath1
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")
strKeyPath =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{0EFC6259-3AD8-4CD2-BC5
7-D4937AF5CC0E}\"
strKeyPath1 =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{BD12EB47-DBDF-11D3-BEE
A-00A0CC272509}\"
objReg.Enumvalues HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
'objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
WScript.Echo subkey
Next Tag: Test Post Tag: 157031
Monitoring many eventlogs simultaneously
Hello,
I have a script (with the help of the example @
http://www.microsoft.com/technet/community/scriptcenter/monitor/scrmon21.mspx)
that I have turned into a service that monitors the security log for
events (invalid login attempts, accounts getting locked out, yada,
yada, yada)
I had previously tried to use a ExecNotificationQueryAsync and
OnObjectReady but when the interpreter gets to EOF, the thread dies
and monitoring event logs stops. The only way I could receive
real-time notices of event log entries using that method was to use
the Echo method to keep the thread alive. But if I ever click the Ok
button on the popup, the thread would die. Plus leaving a popup
available to the desktop isn't that elegant of a solution.
So after looking at the web page mentioned above I've tried to use
ExecNotificationQuery inside an infinite loop.
Another aspect of what I'd like to do is remotely monitor all the
domain's security logs. There is a method to my madness in the
following script, as I want centralized administration/notification
and this script can be executed on any domain without modification,
(computer names or numbers of computers don't matter to this script).
Here's what I have attempted so far:
1. Dim arrNameArray()
2. Dim arrServArray()
3. Dim arrQueryArray()
4. Dim strText
5.
6. ' Index for computer name array
7. intNameCounter = 0
8. ' Index for service array
9. intServCounter = 0
10. ' Index for query array
11. intQueryIndex = 0
12.
13. strWhatDomain = "mydomain.local"
14. Const SERVICES = "_WMIServices"
15.
16. ' Get the names of all the computers in the domain and place in
arrNameArray.
17. Set objDomain = getObject("WinNT://" & strWhatDomain)
18. objDomain.filter = Array("Computer")
19.
20. For Each Item In objDomain
21. ReDim Preserve arrNameArray(intNameCounter)
22. arrNameArray(intNameCounter) = Item.Name
23. intNameCounter = intNameCounter + 1
24.
25. Next
26.
27. ' How big is the array?/How many computers in domain
28. intArrSize = UBound(arrNameArray)
29.
30. ' Take the names of all the computers, append a string to the the
name, and place into an array
31. For Each Item In arrNameArray
32. ReDim Preserve arrServArray(intServCounter)
33. strText = arrNameArray(intServCounter) & SERVICES
34. arrServArray(intServCounter) = strText
35. intServCounter = intServCounter + 1
36. Next
37.
38. ' Set up services
39. For i = 0 To intArrSize
40. Set arrServArray(i) =
GetObject("WinMgmts:{impersonationLevel=impersonate, (Security)}\\" &
arrNameArray(i) & "\root\cimv2")
41. Next
42.
43. ' Set up queries
44. For Each Service In arrServArray
45. ReDim Preserve arrQueryArray(intQueryIndex)
46. Set arrQueryArray(intQueryIndex) = Service.ExecNotificationQuery
("Select * from __instancecreationevent where TargetInstance isa
'Win32_NTLogEvent' and TargetInstance.EventCode = '517' ")
47. intQueryIndex = intQueryIndex + 1
48. Next
49.
50. WScript.Echo "Service Has Started"
51.
52. Do
53. ' Debug shows that index number 5 is the domain controller which
is hosting this script.
54. Set objLoggedEvent = arrQueryArray(5).NextEvent
55. strNotify = objLoggedEvent.TargetInstance.User & " cleared the
Security Log on " & objLoggedEvent.TargetInstance.ComputerName
56. Wscript.Echo strNotify
57. Loop
To get this thing to work, I've had to hardcode the reference to the
computer in line 54... which as you can see by the previous lines,
I've tried to avoid hardcoding anything. Furthermore, I can only get
the script to work with one computer in the Do...Loop. If I add more
than one computer to the loop, no events get reported.
Does anyone have any suggestions on how I can monitor all the
eventlogs across the domain?
Thanks! Tag: Test Post Tag: 157016
Help with writing to word file
Hi Everyone,
I am posting this again to try and get a little help.
Thanks, Tony
==================== repeat posting ======================
Hello everyone,
I am new to ASP and new to programming in general, so I think my
questions are fairly simple. I have 2 questions:
1. I want to open a word file from ASP and write text to a form field
in the word document. The code below shows where I want to do that.
How can I do that?
2. Instead of just saving, can someone give me the syntax to "save as"
with a new file name and in a new directory?
Thanks so much,
Tony
<%
Dim objWord
Dim objDoc
Set objWord = Server.CreateObject ("Word.Application")
Set objDoc = objWord.Documents.Open (Server.MapPath
(("c:\WordABC.doc"))
<<<< Here is where I just want to write some text to form field in the
word document>>>>>>>>>>
objDoc.Save
End With
Set oWDoc = Nothing
Set oWord = Nothing
%> Tag: Test Post Tag: 157015
batch file
Ive been using a batch file to map network drives but moving to XP it no
longer works.
Is there a way to use VB sripting to do this at startup?
Greg
gclayton@access.inet.co.th Tag: Test Post Tag: 157013
Writing to a text file
Hello
Can anyone help me out with how to open and write to a disk text fil
from VBScript
I was trying to use something like the following
Dim fnu
fnum = FreeFile(
Open "test.txt" For Append As #fnu
But I get an "Expecting end of line" syntax error on the 'Open' statement
Thanks
To Tag: Test Post Tag: 157004
Assistance needed: Can't timeout calling MSXML2.XMLHTTP control
hello all --
First off, let me say that I'm a hack of a programmer ... so my
apologies in advance if I'm not phrasing things quite right.
I'm working on an application which needs to go out to a web page,
download the content, and check a value. It needs to do this every
few minutes, so I need to put in a "timeout" control in my code so
that if the page load takes too long it will abort the transaction and
simply log an error.
However, using the MSXML2.XMLHTTP control, I just can't seem to
accurately get a "complete" state returned. I've been working with
the bAsync value on the actual GET request -- if it's set to TRUE, the
execution happens asynchronously, and I can loop out and start
checking the time. However, the ReadyState value never ever comes
back as anything other than 1 (READYSTATE_INITIALIZED). According to
the docs, I should be looking for READYSTATE_COMPLETE (value of 4) as
an indicator of a successful response.
If I set bAsync to FALSE, the code will freeze at the HTTP GET request
until it has been fulfilled. If the page is successfully returned,
READYSTATE_COMPLETE will be returned (value of 4). However, if there
is some sort of page load error, my application never recovers and
effectively dies at this point.
Any assistance is most helpful - everything I've read leads me to
believe that this should be possible. I've done it before using
InternetExplorer controls on a local machine, but this needs to be
something that a server will do - so no IE controls.
The version of my msxml3.dll file is 8.40.9419 - I'm assuming that's
the latest?
Thanks in advance!
-Douglas Toombs
-----------------BEGIN CODE BELOW (debug wscript.echo line added in do
... loop to check readystate value during execution)
Const READYSTATE_UNINITIALIZED = 0, _
READYSTATE_INITIALIZED = 1, _
READYSTATE_LOADED = 2, _
READYSTATE_INTERACTIVE = 3, _
READYSTATE_COMPLETE = 4
URL = "http://www.whatismyip.com/"
MaxLoadTime = 15
CheckPageLoadTime = 0
PageLoadStartTime = now()
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Call objHTTP.Open("GET", url, TRUE)
objHTTP.Send
Do Until objHTTP.ReadyState = READYSTATE_COMPLETE or CheckPageLoadTime
> MaxLoadTime
wscript.echo now() & " :" & objHTTP.ReadyState
PageLoadEndTime = now()
CheckPageLoadTime = DateDiff("s", PageLoadStartTime,
PageLoadEndTime)
Loop
If CheckPageLoadTime > MaxLoadTime then
wscript.echo objHTTP.ResponseText
wscript.echo "HTTP GET timed out"
else
wscript.echo objHTTP.ResponseText
wscript.echo "HTTP GET loaded in time"
end if Tag: Test Post Tag: 157001
Using WMI scripting in ASP
Hello,
I want to use an WMI script in an Active Server Page.
Which is collecting the Service state of a dedicated service on a
selected server.
When i use the example script form the windows 2000 scripting guide i
receive een http 500 error page.
HAs any one an idea.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! Tag: Test Post Tag: 156998
how to change columns displayed in windows explorer?
could someone give a sample code to change the view of a certain folder
(e.g. c:\temp) in windows explorer to
detail view
add the column "artist", set it to a certain width (e.g. 50 pixel) and
insert it between the Name column and the Size column?
Thanks in advance. Tag: Test Post Tag: 156985
Return value from SQL Stored Procedure
I have a stored procedure that does a few things including returning a
record identifier. The stored procedure works well when running in visual
basic. But, if I try to run it from vbscript using either WSH or ASP, the
record identifier doesn't get returned. The following is an example of the
stored procedure:
CREATE PROCEDURE sp_SARF_CreateDelReq
@USERID char(10), @Requester char(10), @ReqDate datetime, @EffDate
datetime, @ReqID numeric output
AS
INSERT INTO tRequests (Requester, UserID, ReqDate, EffDate, ActionType)
VALUES(@Requester, @UserID, @ReqDate, @EffDate, 2)
SELECT @ReqID = @@Identity
Return @ReqID
GO
The following is an example of the vbscript code. Now, this works well with
Visual Basic, and it works well with Oracle 7.x using vbScript and WSH. But
with MSSQL 2k, it doesn't return a record identifier:
Function Create_Delete(UsrID, Reqsr)
Dim ReqID, cmdTemp
Dim SPONewUserID
Set cmdTemp = CreateObject("ADODB.Command")
Set cmdTemp.ActiveConnection = con
cmdTemp.CommandType = 4 'Stored Procedure
cmdTemp.CommandText = "sp_SARF_CreateDelReq"
cmdTemp.Parameters.Refresh
cmdTemp("@USERID") = UsrID
cmdTemp("@Requester") = Reqsr
cmdTemp("@ReqDate") = Now()
cmdTemp("@EffDate") = Date()
ReqID = 0
Set SPONewUserID = cmdTemp.Execute
For Each prm In cmdTemp.Parameters
WScript.Echo vbTab & prm.name & ": " & vbTab & prm.Value
Next
ReqID = cmdTemp("@ReqID")
Set SPONewUserID = Nothing
Set cmdTemp = Nothing
Create_Delete = ReqID
End Function Tag: Test Post Tag: 156984
working with strings
Hi!
I have a subtitle file and I want to edit it in this way:
read a line,find firs "bracket" "{", then second "}" and read what is
between in to a "buffer" convert this to an integer,multiply this
number and then put it back. What functions I should use for all
this?
Provide some examples please.
Thanks! Tag: Test Post Tag: 156979
disable + clock ?
Hi
Im on my first tutorial and its given me a couple of things to fin
out , please can you help me :-
1, How to disable a button until another button is press
2,On pressing a button I want to take a snapshot of the present tim
and show it in a label (lblOne) ,and at the same time start a runnin
clock in another label (lblTwo)
Remember Im just a beginner so please keep it simple , thanks Tag: Test Post Tag: 156975
Code reuse in VBScript w/ WMI
I'm writing VBScripts as part of our WinXP deployment. I'd like to
setup a reusable function that I can pass a WMI Base name and property
to and have it return the value of that property. Here's an example:
Function GetWMIInfo (WMIbase, ItemName)
dim strComputer, objWMIService, objBaseBoardItems, objItem,
colItems
strComputer = "."
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from " &
WMIbase,,48)
For Each objItem in colItems
GetWMIInfo = objItem.ItemName
Next
End Function
My problem is that I cannot seem to reference the object property
(like Win32Baseboard.model) as a variable. It just keeps coming back
null. Any thoughts would be GREATLY appreciated.
Cheers,
--SaxDaddy
From there here and here to there, funny things are everywhere" (Dr.
Suess) Tag: Test Post Tag: 156962
vbs version of DOS xcopy command?
I've got a couple of .bat files that run automatically (and did the =
service when I's using WIN 98, but in WIN 2000 and WIN XP) they take =
over the screen--it blacks entirely when they run--at least for a second =
or so and I've not figured out how to get them to run minimized or even =
get them to quit taking over the entire screen for a second or two =
before they drop back to a small window in the corner). The purpose of =
the .bat files is copying changed data files mostly to the backup hard =
drive.
One line from one of the files would look like this.
"xcopy d:\files\*.* h:\files /d /s /h /r /k /y /i"
I figure there's gotta be an equivalent vbs line I could use in a vbs =
file (yes, I'm definitely a beginner at this).
Anybody can tell me how to replace a batch file with that line above =
=E2=86=91 with a line from a vbs file that would do the same thing? =
Switches and all? (I'll try to hammer out the entire .bat file =
conversion myself, the practice will do me good I reckon.)
TIA. Tag: Test Post Tag: 156961
Rename
After I process my files I want to rename my files with
filenamemmddyyyyTime.txt...
So file1.txt
becomes file104222004180000.txt
any examples how to do this... Tag: Test Post Tag: 156959
Problem with WMI DNS Provider MicrosoftDNS_SOAType Modify() method
Hello,
I use the WMI DNS Provider to manage some DNS zones on my W2k server.
I can obtain the path of the SOA RR of the zone "100aaa.com" with :
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_SOAType
where DomainName='100aaa.com'",,48)
objItem.Path_.Relpath
which gives :
MicrosoftDNS_SOAType.ContainerName="100aaa.com",DnsServerName="dnsserver.100
aaa.com",DomainName="100aaa.com",OwnerName="100aaa.com",RecordClass=1,Record
Data="dnsserver.100aaa.com. admin.100aaa.com. 9 900 600 86400 3600"
That's OK.
But : when I try to modify this SOA record with :
Set objItem =
objWMIService.Get("MicrosoftDNS_SOAType.ContainerName=""100aaa.com"",DnsServ
erName=""dnsserver.100aaa.com"",DomainName=""100aaa.com"",OwnerName=""100aaa
.com"",RecordClass=1,RecordData=""dnsserver.100aaa.com. admin.100aaa.com. 9
900 600 86400 3600""")
errResult = objItem.Modify(3600,intNewSerial,,,3600)
... I get the following error :
SWbemServices error '80041002'
Not found
I notice that the same thing with a CNAME or an A RR perfectly works!..
Hope someone will be able to help me.
Thanking you in advance,
Jeremy Tag: Test Post Tag: 156956
Checking FileExistence on subweb?
I'm attempting to check for the existence of a file in our intranet
environment from an intranet webpage.
When I use the Scripting.FileSystemObject, I can only access the server's
local & mapped drives. The file that I'm trying to access is available to
the intranet via an IIS subweb.
Is there some way that I can check for a files existence through the subweb?
or
Is there some way that I could check for the existence of a valid URL rather
than an FSO property?
Also, the client side does have permission to the UNC of the desired file.
Perhaps there's something I could do from the client side?
Thanks,
Tim Tag: Test Post Tag: 156955
Control cursor position using VB Script
Is it possible to position the cursor at a set of pre-defined coordinates
and mandate a left mouse button click. I need this to navigate through an
application part of which is not accessible via tabs or other keys. Tag: Test Post Tag: 156954
file download from web site to client computer
Hi
I like to write a asp or asp.net page that allow my client to download a file. I like to put a security - current site - I am doing form based authenticate. I use session object for authentication. Can you please guide me for secure download a file from my web site to his computer
Thanks Tag: Test Post Tag: 156951
Excel WorkSheets and Subs
Me Again with a new problem:-)
All the computers on my network currently with the aid of a script I wrote
log their computer name to a location depending on building they are in:
eg
London computers log to \\myserver\london
Manchester computers log to \\myserver\manchester
A text file is saved with the computer name as the filename in this
location.
In the past I have to manually compile a list of these computer and their
location but now I am trying to automate it a bit. This I have done but now
wish this to log automatically to a spreadsheet.
This example has a problem in that each time the Sub GetAllData runs the
worksheet is not changed causing the data to be overwritten and the sheet to
be renamed. The end result I would like is each time the Sub runs for each
region a new work sheet using the region name is created.
Apart from several customised Subs I have no idea how to do this using one,
the example given shows three regions however the company currently has 10
so customer subs for each one is not ideal.
Here is the example.
Any help is appreciated.
------------------------------------------------------------------------
Option Explicit
Dim objFSO, DataFile, AssetFolder, FileName, SaveFolder, objExcel, objSheet,
objallsheet, Regions, Region
set objFSO = createobject("scripting.filesystemobject")
SaveFolder = "D:\"
Call PrepFile
Regions = array(""London", "Manchester", "Nottingham")
for each Region in Regions
'AssetFolder to point to network location once script working c:\scripts\ is
for testing
AssetFolder = "c:\scripts\" & Region & "\"
Call GetAllData(AssetFolder)
Next
Call SaveFile
Sub PrepFile
' Bind to Excel object.
On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If Err.Number <> 0 Then
On Error GoTo 0
Wscript.Echo "Excel application not found."
Wscript.Quit
End If
On Error GoTo 0
' Create a new workbook.
objExcel.Workbooks.Add
' Bind to worksheet.
End Sub
Sub GetAllData(sourcefol)
dim SourceFiles, sourceFile, FileModified, K
set SourceFiles = objFSO.getfolder(SourceFol).files
K = 3
Set objallsheet = objExcel.ActiveWorkbook.Worksheets(1)
objallsheet.Name = Region
objallsheet.Cells(1, 1).Value = "Region " & "Computers"
objallsheet.Cells(2, 1).Value = "Asset"
objallsheet.Cells(2, 2).Value = "Last Time Logged On"
for each SourceFile in SourceFiles
FileModified = SourceFile.DateLastModified
objallsheet.Cells(k, 1).Value = sourceFile.name
objallsheet.Cells(k, 2).Value = FormatDateTime(FileModified,
vbShortDate)
k = k + 1
next
' Format the spreadsheet.
objallsheet.Range("A1").Font.Bold = True
objallsheet.Range("A2:B2").Font.Bold = True
objallsheet.Select
objallsheet.Range("A3").Select
objallsheet.Range("A1:B1").Merge
objExcel.ActiveWindow.FreezePanes = True
objExcel.Columns(1).ColumnWidth = 25
objExcel.Columns(2).ColumnWidth = 20
end Sub
Sub SaveFile
' Save the spreadsheet and close the workbook.
objExcel.ActiveWorkbook.SaveAs SaveFolder & "asset.xls"
objExcel.ActiveWorkbook.Close
' Quit Excel.
objExcel.Application.Quit
End Sub Tag: Test Post Tag: 156942
Copy array dump onto text file
Hello all,
I would like to dump the array output from the below script onto a empty
text file. I would also like the script to create the file. I know FSO could
do this just need the code.
Thanks!
Set Container = GetObject("WinNT://NEO")
Container.Filter = Array("User")
For Each User In Container
Wscript.Echo User.Name
Next Tag: Test Post Tag: 156938
batch into script
How can I convert this section of a batch file into vbscript so I can add it
to my new login script?
.......
:AUDIT
if exist "C:\aida_scan.txt" GOTO MS823980PATCH
echo.
echo Running a background Hardware/Software Audit.
\\%File_Server%\Data\Support\aida32\aida32.exe /R .\AuditData\$hostname.csv
/NAS /AUDIT /SILENT
echo yes >>"C:\aida_scan.txt"
:MS823980PATCH
.......
--
Posted 'as is'. If there are any spelling and/or grammar mistakes, they
were a direct result of my fingers and brain not being synchronized or my
lack of caffeine.
Mike Brearley Tag: Test Post Tag: 156937
WMI LastBootUpTime wrong value
I am working on an uptime script for servers and can't seem to get an
accurate time when I query objItem.LastBootUpTime from
Win32_OperatingSystem. It always 4:00 hours too early.
If the server logs and uptime.exe say the server is upt 4 hours. My wmi
reports the server came up 4 hours before that. I am on eastern time. I
guess its my off set from UTC time, but I can't figure out how to deal with
that
Dim objWMIService
Dim colItems
Dim endfile
Set fs = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_OperatingSystem",,48)
For Each objItem in colItems
WScript.Echo "LastBootUpTime: " & objItem.LastBootUpTime
WScript.Echo "LocalDateTime: " & objItem.LocalDateTime
strvalue1 = dtparse(objItem.LastBootUpTime)
strvalue2 = dtparse(objItem.LocalDateTime)
WScript.Echo strvalue1 & " " & strvalue2 & " strvalues"
intday = DateDiff("d", strvalue1, strvalue2)
inthour = DateDiff("h", strvalue1, strvalue2)
intmin = DateDiff("n", strvalue1, strvalue2)
WScript.Echo (inthour \ 24) & " day(s) " & (inthour Mod 24) & " hours " &
(intmin Mod 60) & " minutes"
Next
Function dtparse(strvalue) 'this function parses the Time into a readable
format.
stryear = Left(strvalue, 4)
strmonth= Mid(strvalue, 5,2)
strday = Mid (strvalue, 7,2)
strhour = Mid(strvalue, 9,2)
strmin = Mid(strvalue, 11,2)
strsec = Mid(strvalue, 13,2)
strmsec = Mid(strvalue, 16,6)
strtz = Right(strvalue, 4)
strdate = strmonth & " " & strday & ", " & Stryear
strtime = strhour & ":" & strmin & ":" & Strsec
dtparse = CDate(strdate & " " & strtime)
End Function Tag: Test Post Tag: 156932
Open Secure Word Doc
Hi All
I am running a web application that allows users to search / view word
documents and then click on them to open them. The files are stored in a
directory on the server that does not allow anonymous access to stop people
downloading them without using our interface. I currently open the files
using the method below (Binary writing it to the browser). However, this
does not work on Apple Macs (Latest Safari browser) as the browser does not
recognise it as a word document. Does anyone know another way of doing this
on a Mac without making the user download the file first.
Many thanx for any advice
Paul
Set strDocument = Server.CreateObject ("ADODB.Stream")
Response.AddHeader "content-disposition", "attachment; filename=" & FileName
strDocument.Open ()
strDocument.Type = 1
strDocument.LoadFromFile (FilePath)
Response.BinaryWrite
strDocument.Read() Tag: Test Post Tag: 156920
Want to compile ASP
I have an ASP file (VBScript) - I want to compile it for faster response. Can any body tell me how to compile it
Regard
Manisha Tag: Test Post Tag: 156914
Local File System from Webpage script?
Is it possible for a vbscript, running on an intranent web page, to access
the local users' file system object?
I would like to test for the existence of a file on one the users' network
shares.
So far I've tried using the "Scripting.FileSystemObject" but that resulted
in files located on the IIS server rather than the client's local
environment.
Can someone point me in the right direction?
Thank you,
Tim Tag: Test Post Tag: 156911
Writing to a Word Doc from ASP
Hello everyone,
I am new to ASP and new to programming in general, so I think my
questions are fairly simple. I have 2 questions:
1. I want to open a word file from ASP and write text to a form field
in the word document. The code below shows where I want to do that.
How can I do that?
2. Instead of just saving, can someone give me the syntax to "save as"
with a new file name and in a new directory?
Thanks so much,
Tony
<%
Dim objWord
Dim objDoc
Set objWord = Server.CreateObject ("Word.Application")
Set objDoc = objWord.Documents.Open (Server.MapPath
(("c:\WordABC.doc"))
<<<< Here is where I just want to write some text to form field in the
word document>>>>>>>>>>
objDoc.Save
End With
Set oWDoc = Nothing
Set oWord = Nothing
%> Tag: Test Post Tag: 156908
Last Modified file > output.txt
Guys..
I just need your help in scripting ..I am planning to run a script
which goes through the a folder and record the last modified filename,
Date of the file and size to Modified.txt.
Ths file structure is
D:\Data\
System\
Server\
Maintainance\
Workshop\
each folder contains nearly 100 files and I need to keep a track of
remote copy script.
By doing that I will be able to record the last modified File and
folder on to Modified.txt and that we see whether remote copy has
worked..
If you guys have a diffrent and better way can you pls let me know
Thnaks
cha Tag: Test Post Tag: 156901
Variable function name
Hello again everyone.
Is it possible to call function name dynamically? for example:
functSuffix = "First"
RunThis & functSuffix 'or something like that to call function RunThisFirst
function RunThisFirst()
<code>
End function
function RunThisSecond()
<code>
End function
Any suggestions appreciated.
Thanks,
Dave Tag: Test Post Tag: 156896
Automatic Tab in Data Entry Form
I am writing data entry screens for a large application, using
VBScript. The users want automatic tabbing between fields. For
example, when they enter a 2-digit month, 4-digit year, etc., they
want the cursor to jump to the next field without having to press Tab.
That was easy in Visual Basic 6, by doing a form-level check of the
current field length and if it was equal to the max length for the
field, doing a SendKeys "{tab}".
Is there a VBScript equivalent to the Sendkeys command? Without
having to use the Windows Script Host? I have tried the WSH approach
without any luck. Is there another method to accomplish auto tabbing?
Thanks!! Tag: Test Post Tag: 156894
radio button array
hi all
I am having a problem with the following vbscript:
<HTML>
<HEAD>
<TITLE>test</TITLE>
<script language="VBScript">
option explicit
dim i
sub choose_rb
'comment: results in error "type mismatch"
for i=0 to ubound(document.form1.radiobutton)
'comment: this works fine
' for i=0 to 2
if document.form1.radiobutton(i).checked then
msgbox i & " clicked!!!"
end if
next
end sub
sub Button_onclick()
choose_rb
end sub
</script>
</HEAD>
<BODY>
<form name="form1" method="post" action="">
<input type="button" name="Button" value="Button">
<input type="radio" checked name="radiobutton"
value="radiobutton0">
<input type="radio" name="radiobutton" value="radiobutton1">
<input type="radio" name="radiobutton" value="radiobutton2">
</form>
</BODY>
</HTML>
As you can read in the comments the first "for..."-condition results
in a "type mismatch" (i am dutch, so i hope the translation of the
-dutch- errormessage is correct), while the second "for..."-condition
works fine. So there should be something wrong with
"ubound(document.form1.radiobutton)"! But i can't figure out what.
The reason i have to use the ubound-function is that this is just a
testscript for a larger vbscript where the total number of
radiobuttons depends on a date-calculation.
Thanks in advance for your help
gr. Jan Tag: Test Post Tag: 156889