varitem = match.SubMatches(1)
varitemthis = p_variables_list.Item(varitem)
result of
response.write match.Value &" "& varitemthis &" "&varitem & "<br>"
is
{{name}} rrrr name
{{site_root}} www.site.com/ site_root
{{mail}} sdddddsssdfffrrrsdf#ssrsssr.com mail
{{code}} code
result of
p_template = Replace(p_template, match.Value, varitem)
response.write p_template
all right, but
p_template = Replace(p_template, match.Value, varitemthis)
response.write p_template
nothing... why? what's wrong?
A couple of things...
Remember that the Replace function is case sensitive
Do some basic trouble-shooting by making sure you have values.
Response.Write "Original p_template = " & p_template
Response.Write "match.Value = " & match.Value
Response.Write "varitemthis = " & varitemthis
p_template = Replace(p_template, match.Value, varitemthis)
Response.Write "New p_template = " & p_template
In Classic ASP the Replace function is not case sensitive.
Related
I'm using Excel to upload some files onto an server with WinSCP.
This example works:
Sub FTP_upload()
Dim logfile, ftp_login, file_to_upload, upload_to_folder As String
logfile = "D:\temp\ftp.log"
ftp_login = "ftp://ftp_mydomain:mypassword#mydomain.com/"
file_to_upload = "D:\tmep\myfile.txt"
upload_to_folder = "/myfolder/"
'upload the file
Call Shell("C:\Program Files (x86)\WinSCP\WinSCP.com /log=" & logfile & " /command " & """open """ & ftp_login & " " & """put " & file_to_upload & " " & upload_to_folder & """ " & """exit""")
End Sub
I now want Excel to wait until the shell has closed.
Using the information from Wait for shell command to complete, I put it together this code:
Sub FTP_upload_with_wait()
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim errorCode As Integer
Dim logfile, ftp_login, file_to_upload, upload_to_folder As String
logfile = "D:\temp\ftp.log"
ftp_login = "ftp://ftp_mydomain:mypassword#mydomain.com/"
file_to_upload = "D:\tmep\myfile.txt"
upload_to_folder = "/myfolder/"
execute_string = "C:\Program Files (x86)\WinSCP\WinSCP.com /log=" & logfile & " /command " & """open """ & ftp_login & " " & """put " & file_to_upload & " " & upload_to_folder & """ " & """exit"""
errorCode = wsh.Run(execute_string, windowStyle, waitOnReturn)
End Sub
Unfortunately, this doesn't work. Excel reports:
run-time error '-2147024894 (80070002)'
Automation error
The system cannot find the file specified
When I replace the string this way, it works:
execute_string = "notepad.exe"
It seems that wsh.Run doesn't like the quotation marks.
How can I make this work?
The path to WinSCP contains spaces, so you need to wrap it to double-quotes (which need to be doubled to escape them in VBA string):
execute_string = """C:\Program Files (x86)\WinSCP\WinSCP.com"" ..."
But that's only the first set of quotes that is wrong in your command.
The correct command would be like:
execute_string = """C:\Program Files (x86)\WinSCP\WinSCP.com"" " & _
"/log=" & logfile & " /command " & _
"""open " & ftp_login & """ " & _
"""put " & file_to_upload & " " & upload_to_folder & """ " & _
"""exit"""
Assuming that none of logfile, ftp_login, file_to_upload and upload_to_folder contains spaces, in which case would would need a way more double-quotes.
Read ore about WinSCP command-line syntax
The Call Shell must have some heuristics that adds the quotes around C:\Program Files (x86)\WinSCP\WinSCP.com. Though it's just a pure luck that the rest of the command-line works, the quotes are wrong there too. So even your first code is wrong. It runs the following command:
"C:\Program Files (x86)\WinSCP\WinSCP.com" /log=D:\temp\ftp.log /command "open "ftp://ftp_mydomain:mypassword#mydomain.com/ "put D:\tmep\myfile.txt /myfolder/" "exit"
(Note the misplaced quotes around open)
on my excel sheet the user can choose some video clips and arrange in different order to play as a vlc playlist. Unfortunately it can’t be guaranteed that the video file names haven’t any blanks.
To build the vlc playlist I use successfully:
Dim PL
PL = Shell("C:\Program Files\VideoLAN\VLC\VLC.exe " & certainPath & "\Movie6.flv" & " " & certainPath & "\Movie7.flv" & " " & certainPath & "\Movie8.flv ", 1)
'using "\Movie 6.flv" 'doesn't work of course
'using "\'Movie 6.flv'" 'doesn't work aswell
Is there another way to encapsulate file name with blanks?
thankfull for a hint.
Assuming that certainPath folder end with \ ( es. "C:\" ), this should work:
Dim PL
PL = Shell(chr(34) & "c:\Program Files\VideoLAN\VLC\vlc.exe " & chr(34) & chr(34) & certainPath & "Movie 6.flv" & chr(34) & " " & chr(34) & certainPath & "Movie 7.flv" & chr(34))
CHR is a function to returns the character from the ASCII table (the quotes in this case).
I have a script comprising of batch files that generate powershell scripts. I've taken it upon myself to accomplish the same task via VB Script. So far I've assigned most of the info I need to strings. But I would like to have a prompt for a password that is stored as a secure string and can be outputted to a text file for later use in further scripts. So far the only code I've found doesn't work I think perhaps because it was intended for VB rather than VBS. Any help greatly appreciated.
The powershell code previously used was.
echo Please enter admin credentials (This will be stored in a secure string:
powershell -Command "& { read-host -assecurestring | convertfrom- securestring | out-file C:\S3BS\reports\input.txt; } "
You can use this small code with powershell and batch
#ECHO OFF
Title Type a password with powershell and batch
:CheckPassword
Mode con cols=50 lines=3
cls & color 0A & echo.
set MyPassword=Hackoo
set "psCommand=powershell -Command "$pword = read-host 'Enter your password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
if %MyPassword%==%password% (Goto:Good) else (Goto:Bad)
exit/b
::***********************************************************************************************
:Good
Cls & Color 0A
echo(
echo Good Password
TimeOut /T 2 /NoBreak>nul
Exit
::***********************************************************************************************
:Bad
Cls & Color 0C
echo(
echo Bad password
TimeOut /T 1 /NoBreak>nul
Goto:CheckPassword
::***********************************************************************************************
I think this function PasswordBox can help you, just give a try ;)
' Just an example of how to use the function
'
wsh.echo "You entered: ", _
Join(PasswordBox("Enter UID and password", _
"Testing"), ", ")
' A function to present a Password dialog in a VBS (WSF)
' script
' Requires WScript version 5.1+
' Tom Lavedas <tlavedas#hotmail.com>
' with help from and thanks to Joe Ernest and
' Michael Harris
'
' modified 1/2008 to handle IE7
'
Function PasswordBox(sPrompt,sDefault)
set oIE = CreateObject("InternetExplorer.Application")
With oIE
' Configure the IE window
.RegisterAsDropTarget = False
.statusbar = false : .toolbar = false
.menubar = false : .addressbar = false
.Resizable = False
.Navigate "about:blank"
Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop
' Test for IE 7 - cannot remove 'chrome' in that version
sVersion = .document.parentWindow.navigator.appVersion
if instr(sVersion, "MSIE 7.0") = 0 Then .FullScreen = True
.width = 400 : .height = 270
' Create the password box document
With .document
oIE.left = .parentWindow.screen.width \ 2 - 200
oIE.top = .parentWindow.screen.height\ 2 - 100
.open
.write "<html><head><" & "script>bboxwait=true;</" _
& "script><title>Password _</title></head>"_
& "<body bgColor=silver scroll=no " _
& "language=vbs style='border-" _
& "style:outset;border-Width:3px'" _
& " onHelp='window.event.returnvalue=false" _
& ":window.event.cancelbubble=true'" _
& " oncontextmenu=" _
& "'window.event.returnvalue=false" _
& ":window.event.cancelbubble=true'" _
& " onkeydown='if ((window.event.keycode>111)"_
& " and (window.event.keycode<117)) or" _
& " window.event.ctrlkey then" _
& " window.event.keycode=0" _
& ":window.event.cancelbubble=true" _
& ":window.event.returnvalue=false'" _
& " onkeypress='if window.event.keycode=13" _
& " then bboxwait=false'><center>" _
& "<div style='padding:10px;background-color:lightblue'>" _
& "<b> " & sPrompt & "<b> </div><p>" _
& "<table bgcolor=cornsilk cellspacing=10><tr><td>" _
& " <b>User:</b></td><td>" _
& "<input type=text size=10 id=user value='" _
& sDefault & "'>" _
& "</td><tr><td> <b>Password:</b></td><td>" _
& "<input type=password size=12 id=pass>" _
& "</td></tr></table><br>" _
& "<button onclick='bboxwait=false;'>" _
& " Okay " _
& "</button> <button onclick=" _
& "'document.all.user.value=""CANCELLED"";" _
& "document.all.pass.value="""";" _
& "bboxwait=false;'>Cancel" _
& "</button></center></body></html>"
.close
Do Until .ReadyState = "complete" : WScript.Sleep 100 : Loop
.all.user.focus
.all.user.select ' Optional
oIE.Visible = True
CreateObject("Wscript.Shell")_
.Appactivate "Password _"
PasswordBox = Array("CANCELLED")
On Error Resume Next
Do While .parentWindow.bBoxWait
if Err Then Exit Function
WScript.Sleep 100
Loop
oIE.Visible = False
PasswordBox = Array(.all.user.value, _
.all.pass.value)
End With ' document
End With ' IE
End Function
If you are executing the VBScript via cscript.exe something like;
cscript.exe /nologo "test.vbs"
You can use the WScript object to access the StdIn (for input) and StdOut (for output) streams to the command window using a script like this;
Function PromptForInput(prompt)
Dim prog : prog = WScript.Fullname
If LCase(Right(prog, 12)) = "\cscript.exe" Then
Call WScript.StdOut.WriteLine(prompt & " ")
PromptForInput = WScript.StdIn.ReadLine()
Else
Call Err.Raise(vbObjectError + 5, "Must be called from cscript.exe")
End If
End Function
Dim input
input = PromptForInput("Did you wish to continue? [Y/N]")
Select Case UCase(input)
Case "Y", "N"
Call WScript.StdOut.Writeline("You chose: " & UCase(input))
Case Else
Call WScript.StdOut.Writeline("Invalid option!")
End Select
Output:
Did you wish to continue? [Y/N]
y
You chose: Y
You can adapt it to prompt for passwords but be aware that the input is not hidden so all the characters typed are visible in the command window until it's closed.
I have a number of "ad-hoc" stereotypes in a Sparx EA model. That is, I just typed a stereotype name in the element properties, then used the same name in other elements to which it applies ... without using a profiles.
Each of these then appears in Project --> Settings --> UML Types --> Stereotypes.
Eventually, I added Shape Script icons, etc.
However, I created some confusion with one Stereotype name. I used "Tablespace" as a design concept to indicate "group of related database tables". Our database team finds this confusing due to the physical concept of a "tablespace" in Oracle.
So, I want to rename.
If I do this from UML Types --> Stereotypes, all of the existing elements retain the original name (eg. Tablespace) and revert to their Shape Script-less appearance. If I visit an element and change to the new name, the Shape Script, etc. appears.
I'm not keen on finding each element with stereotype and manually applying the new name.
Is it time for me to learn EA Scripting or is there another way?
Your only escape is using the automation (or native DB access). If your stereotype is just used in objects you may iterate over the result of
Repository.SQLQuery("SELECT object_id FROM t_object WHERE stereotype='oldStereo'")
to get all object ids. Then you need to
elem = Repository.GetElementByID(theId)
to retrieve the single elements. Finally you can change the stereotype with
elem.stereotype = "newStereo"
elem.update()
You can also run a direct SQL with
Repository.Execute("UPDATE t_object SET stereotype='new' WHERE stereotype='old'")
Note that the latter uses one of the landmine functions not being supported officially.
Edit: You might also run the last SQL in a native RDBMS client. When using EAP you might need to rename it temporarily to .mdb to pretend it's an MS Access database (which it actually is).
You can use this VBScript to rename stereotypes in EA.
It has been tested on a .eap file, and it is this complicated because of the lack of replace() in MS Access SQL syntax.
Just go the the Scripting view, add a new VBScript and paste this code to your new script. Then modify it to indicate the from and to stereotypes.
option explicit
!INC Local Scripts.EAConstants-VBScript
'
' Script Name: Rename Stereotypes
' Author: Geert Bellekens
' Purpose: Rename stereotypes on all types of elements
' Environment: Tested on .eap file.
' Date: 13/10/2015
'
sub main
renameElementStereotypes "FromStereo", "ToStereo"
renameAttributeStereotypes "FromStereo", "ToStereo"
renameConnectorStereotypes "FromStereo", "ToStereo"
renameOperationStereotypes "FromStereo", "ToStereo"
renameDiagramStereotypes "FromStereo", "ToStereo"
Repository.RefreshModelView(0)
msgbox "Finished renaming stereotypes"
end sub
sub renameElementStereotypes(fromStereo, toStereo)
renameStereotypes "t_object", fromStereo, toStereo
end sub
sub renameAttributeStereotypes(fromStereo, toStereo)
renameStereotypes "t_attribute", fromStereo, toStereo
end sub
sub renameConnectorStereotypes(fromStereo, toStereo)
renameStereotypes "t_connector", fromStereo, toStereo
end sub
sub renameOperationStereotypes(fromStereo, toStereo)
renameStereotypes "t_operation", fromStereo, toStereo
end sub
sub renameDiagramStereotypes(fromStereo, toStereo)
renameStereotypes "t_diagram", fromStereo, toStereo
end sub
sub renameStereotypes (baseTable, fromStereo, toStereo)
dim updateSQL
'first the second part of of t_xref description
updateSQL = "update (" & baseTable & " o inner join t_xref x on o.[ea_guid] = x.[Client]) "&_
" set x.Description = MID( x.Description, 1, INSTR( x.Description, ':" & fromStereo & "') - 1) "&_
" + ':" & toStereo & "' "&_
" + MID(x.Description,INSTR( x.Description, ':" & fromStereo & "') "&_
" + LEN(':" & fromStereo & "'), LEN(x.Description) "&_
" - INSTR( x.Description, ':" & fromStereo & "') "&_
" - LEN(':" & fromStereo & "')+ 1) "&_
" where o.Stereotype = '" & fromStereo & "' "&_
" and x.Name = 'Stereotypes' "&_
" and INSTR( x.Description, ':" & fromStereo & "') > 0 "
Repository.Execute updateSQL
'then the first part of t_xref description
updateSQL = "update (" & baseTable & " o inner join t_xref x on o.[ea_guid] = x.[Client]) "&_
" set x.Description = MID( x.Description, 1, INSTR( x.Description, '=" & fromStereo & "') - 1) "&_
" + '=" & toStereo & "' "&_
" + MID(x.Description,INSTR( x.Description, '=" & fromStereo & "') "&_
" + LEN('=" & fromStereo & "'), LEN(x.Description) "&_
" - INSTR( x.Description, '=" & fromStereo & "') "&_
" - LEN('=" & fromStereo & "')+ 1) "&_
" where o.Stereotype = '" & fromStereo & "' "&_
" and x.Name = 'Stereotypes' "&_
" and INSTR( x.Description, '=" & fromStereo & "') > 0 "
Repository.Execute updateSQL
'then the stereotype itself
updateSQL = " update " & baseTable & " o "&_
" set o.[Stereotype] = '" & toStereo & "' "&_
" where o.Stereotype = '" & fromStereo & "' "
Repository.Execute updateSQL
end sub
main
Here's the script I created, based on #Thomas Killian's answer.
Improvements:
Uses the EAScriptLib Database functions to get the result.
Proper case on Update() method (didn't seem essential, though)
Also sets the StereotypeEx attribute on the Object/Element. This seems to be critical... otherwise, the change is either ignored or new stereotype is simply added to the list of stereotypes for the object
Also, unsure how much it matters, but did not open the components via Project Browser before running script during final testing. This feels like voodoo.
!INC Local Scripts.EAConstants-JScript
!INC EAScriptLib.JScript-Database
function RenameStereotypes()
{
Repository.EnsureOutputVisible( "Script" );
var objectIDs = DBGetFieldValueArrayString( "object_id" /* : String */, "t_object" /* : String */, "stereotype='DBTables'" /* : String */ ); /* : Array */
Session.Output( objectIDs );
for ( var i = 0; i < objectIDs.length; i++ ) {
var theId = objectIDs[i];
var elem = Repository.GetElementByID(theId);
Session.Output( "Id: " + theId + " Name: " + elem.name + " Stereotype: " + elem.stereotype );
elem.stereotype = "DBTables"; /* FIRST VISIBLE STEREOTYPE */
elem.stereotypeEx = "DBTables"; /* CRITICAL - DEEPER LIST OF STEREOTYPES */
elem.Update(); /* CASE CHANGED, NOT SURE IT MATTERS */
elem.Refresh(); /* JUST IN CASE */
}
}
RenameStereotypes();
I am looking for a way to find the log folder path of a certain website in IIS by its ID name, like: W3SVC1 or any other method, from inside my application. Is this possible? I tried looking up and down google and found nothing. How is this achieved?
The following code works, but only gets all of the application names/ids (like W3SVC/1), i need the actual log file path, and since they can change I don't want to use the static default log file directory as the root on this:
Function ProcessWebSite(ServiceType, SiteNumber)
Set IISWebSite = getObject("IIS://localhost/" & ServiceType & "/" & SiteNumber)
Set IISWebSiteRoot = getObject("IIS://localhost/" & ServiceType & "/" & SiteNumber & "/root")
ProcessWebSite = IISWebSite.ServerComment
Set IISWebSiteRoot = nothing
Set IISWebSite = Nothing
end function
Function ShowSites(ServiceType, ClassName, Title)
Response.write "Web Sites Description=" & "<br>"
Response.write "===============================================================" & "<br>"
Set IISOBJ = getObject("IIS://localhost/" & ServiceType)
for each Web in IISOBJ
if (Web.Class = ClassName) then
Response.write Ucase(ServiceType) & "/" & Web.Name & _
Space(17-(len(Ucase(ServiceType))+1+len(Web.Name))) & " " & _
ProcessWebSite(ServiceType, Web.name) & "<br>"
end if
next
Set IISOBj=Nothing
End function
Call ShowSites("w3svc", "IIsWebServer", "Web")
Function Returnlog(WebSitePath)
Dim statut
Set IISOBJRoot = getObject(webSitePath)
Returnlog = IISOBJRoot.LogFileDirectory
set IISOBJRoot = Nothing
end Function
IIsObjectPath = "IIS://localhost/w3svc"
Set IIsObject = GetObject(IIsObjectPath)
for each obj in IISObject
if (Obj.Class = "IIsWebServer") then
BindingPath = IIsObjectPath & "/" & Obj.Name
Set IIsObjectIP = GetObject(BindingPath)
WScript.Echo IISObjectIP.ServerComment & ": " & Returnlog(IISObjectIP.ADSPath) & vbnewline
'WScript.Echo IISObjectIP.LogType & vbnewline
end if
next