Copy a specific value to clipboard using VbScript - vbscript

Below I have my dilemma. I need to get the txtPreview.Value copied to the clipboard and the end of the UpdatePreview sub. As it is showing here, I have the sub UpdatePreview to flood specific data and values from other parts of the page to a preview pane, and the button below to run said sub. I can't seem to get the right combination of things to have the txtPreview.Value copy to the clipboard.
Sub UpdatePreview
txtPreview.Value = "Customer/Agency " &_
vbNewLine & Customer.Value & " / " & AgencyName.value & " #" & AgencyID.value &_
vbNewLine &_
vbNewLine & "1. QUESTIONS/NEEDS/VALUE" &_
vbNewLine & issue1.value &_
vbNewLine &_
vbNewLine & "2. TROUBLESHOOTING" &_
vbNewLine & issue2.value &_
vbNewLine &_
vbNewLine & "3. SOLUTIONS " &_
vbNewLine & issue3.value &_
vbNewLine &_
vbNewLine & "4. OUTCOME " &_
vbNewLine & issue4.value &_
vbNewLine &_
vbNewLine
End Sub
<input type="button" class="note" value="Preview" OnClick=UpdatePreview>

<html>
<body>
<script language=vbscript>
document.write document.parentwindow.clipboardData.GetData("TEXT")
</script>
</body>
</html>
To put text on the clipboard use document.parentwindow.clipboardData.SetData "TEXT", txtPreview.Value

Related

CK Editor 4 - Add script into .asp page

A friend of mine asked me a favor, help him to install CK Editor into SnitzForum (yeah old I know). Since I am not into asp lang. I have a problem since after putting into the head the CDN code I have to put below the tag this code:
<script> CKEDITOR.replace( 'editor1' ); </script>
So this is the part where the textarea is into the file post.asp:
<%
end if
end if
Response.Write " </font></td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" </table>" & vbNewLine & _
" </font></td>" & vbNewLine & _
" <td bgColor=""" & strPopUpTableColor & """><textarea cols=""" & intCols & """ name=""editor1"" rows=""" & intRows & """ wrap=""VIRTUAL"" onselect=""storeCaret(this);"" onclick=""storeCaret(this);"" onkeyup=""storeCaret(this);"" onchange=""storeCaret(this);"">" & Trim(CleanCode(TxtMsg)) & "</textarea><br /></td>" & vbNewLine & _
" </tr>" & vbNewLine
end if
select case strRqMethod
case "Reply", "ReplyQuote", "TopicQuote"
Response.Write " <script language=""JavaScript"" type=""text/javascript"">document.PostTopic.Message.focus();</script>" & vbNewLine
end select
How can I add that script? Thanks :)
Edited Code:
<!--#INCLUDE FILE="inc_smilies.asp" -->
<%
end if
end if
Response.Write " </font></td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" </table>" & vbNewLine & _
" </font></td>" & vbNewLine & _
" <td bgColor=""" & strPopUpTableColor & """><textarea cols=""" & intCols & """ name=""Message"" rows=""" & intRows & """ wrap=""VIRTUAL"" onselect=""storeCaret(this);"" onclick=""storeCaret(this);"" onkeyup=""storeCaret(this);"" onchange=""storeCaret(this);"">" & Trim(CleanCode(TxtMsg)) & "</textarea><br /></td>" & vbNewLine & _
" </tr>" & vbNewLine
%>
<script>
tinymce.init({
selector: 'textarea',
toolbar_mode: 'floating',
});
</script>
<%
end if
select case strRqMethod
case "Reply", "ReplyQuote", "TopicQuote"
Response.Write " <script language=""JavaScript"" type=""text/javascript"">document.PostTopic.Message.focus();</script>" & vbNewLine
end select
Ok, so an working example with a text box could (would) be this:
<script src="https://cdn.ckeditor.com/4.16.2/standard/ckeditor.js"></script>
<div style="width:50%">
<asp:TextBox ID="TextBox1" runat="server" Height="304px" Width="617px"
TextMode="MultiLine"
ClientIDMode="Static"
></asp:TextBox>
</div>
<script>
CKEDITOR.replace('TextBox1');
</script>
And we now get this:
So, as noted, it probably better to hide/show the one div above, then trying to inject the above markup into the page. And the REASON why is that then in code behind, you want to be able to get the textbox by using
TextBox1.text
So, by placing a plane jane text box (TextBox1) on the form, then code behind can use that text box. If you inject the markup, then code behind will have a much more difficult time using that markup and using TextBox1.Text to get the results of the markup in that text box.
So I don't see the need to use "code" to inject the above. As I noted, perhaps you need to hide/show this?
Then add a "ID" to the div like this:
<div id="mycooleditor" runat="server" style="width:35%;display:none">
<asp:TextBox ID="TextBox1" runat="server" Height="304px" Width="617px"
TextMode="MultiLine"
ClientIDMode="Static"
></asp:TextBox>
</div>
Now, in code behind, to display the editor, we can go:
mycooleditor.Style.Add("display", "normal")
So, unless you make a REALLY good case as to why we using code to inject the html into the web page as opposed just dropping in the markup as per above without any code (and saving world poverty's at the same time), then I see no reason to spend the time + effort writing code that does the same thing?
You can write code to inject, but I see no reason why when you can just drop in the markup anyway???
Overworked. Put the tinymce files in their own folder (titled "tinyMCE") below the forum root. In the file "inc_header.asp", look for this code (appx lines 240-242):
'## START - REMOVAL, MODIFICATION OR CIRCUMVENTING THIS CODE WILL VIOLATE THE SNITZ FORUMS 2000 LICENSE AGREEMENT
Response.Write "<meta name=""copyright"" content=""This Forum code is Copyright (C) 2000-09 Michael Anderson, Pierre Gorissen, Huw Reddick and Richard Kinser, Non-Forum Related code is Copyright (C) " & strCopyright & """>" & vbNewline
'## END - REMOVAL, MODIFICATION OR CIRCUMVENTING THIS CODE WILL VIOLATE THE SNITZ FORUMS 2000 LICENSE AGREEMENT
Below that bit, insert this:
If strScriptName = "post.asp" Then
Response.Write " <script src=""./tinyMCE/tinymce.js""></script>" & vbNewLine & _
" <script language=""Javascript"">tinymce.init ({" & vbNewLine & _
" selector:'textarea'," & vbNewLine & _
" theme:'modern'," & vbNewLine & _
" browser_spellcheck:'true'," & vbNewLine & _
" plugins:['advlist anchor autolink charmap code contextmenu directionality emoticons fullscreen hr insertdatetime image link lists media nonbreaking paste print preview pagebreak save searchreplace table template textcolor visualblocks visualchars wordcount']," & vbNewLine & _
" content_css:'css/combined-min.css'," & vbNewLine & _
" toolbar:'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | preview media fullpage | forecolor backcolor emoticons'," & vbNewLine & _
" });</script>" & vbNewLine
End If
That will take over all instances of the text area in "post.asp". If you want to use it throughout the forum for text areas, remove the If/End If lines.

Trigger some vbs code on filename change

I would like to be able run some custom vb script code upon filename change (for instance to keep a list of newly created files or the ones which changed their name).
The vbs should be called on every filename change happening within a specified folder.
I know how to do that with a full directory scan but I would like to find a more efficient method, for instance by the mean of a sort of OS hook calling my code.
Any way to do that ?
Thank you,
A.
There are two simple WMI examples, tracing changes for *.txt files in C:\Test\ folder.
First one is for synchronous event processing:
Option Explicit
Dim oWMIService, oEvents, s
Set oWMIService = GetObject("WinMgmts:\\.\root\CIMv2")
Set oEvents = oWMIService.ExecNotificationQuery( _
"SELECT * FROM __InstanceOperationEvent " & _
"WITHIN 1 WHERE " & _
"TargetInstance ISA 'CIM_DataFile' AND " & _
"TargetInstance.Drive = 'C:' AND " & _
"TargetInstance.Extension = 'txt' AND " & _
"TargetInstance.Path = '\\Test\\'")
Do
With oEvents.NextEvent()
s = "Event: " & .Path_.Class & vbCrLf
With .TargetInstance
s = s & "Name: " & .Name & vbCrLf
s = s & "File Size: " & .FileSize & vbCrLf
s = s & "Creation Date: " & .CreationDate & vbCrLf
s = s & "Last Modified: " & .LastModified & vbCrLf
s = s & "Last Accessed: " & .LastAccessed & vbCrLf
End With
If .Path_.Class = "__InstanceModificationEvent" Then
With .PreviousInstance
s = s & "Previous" & vbCrLf
s = s & "File Size: " & .FileSize & vbCrLf
s = s & "Last Modified: " & .LastModified & vbCrLf
End With
End If
End With
WScript.Echo s
Loop
The second is for asynchronous event processing:
Option Explicit
Dim oWMIService, oSink
Set oWMIService = GetObject("WinMgmts:\\.\root\CIMv2")
Set oSink = WScript.CreateObject("WbemScripting.SWbemSink", "Sink_")
oWMIService.ExecNotificationQueryAsync oSink, _
"SELECT * FROM __InstanceOperationEvent " & _
"WITHIN 1 WHERE " & _
"TargetInstance ISA 'CIM_DataFile' AND " & _
"TargetInstance.Drive = 'C:' AND " & _
"TargetInstance.Extension = 'txt' AND " & _
"TargetInstance.Path = '\\Test\\'"
Do
WScript.Sleep 1000
Loop
Sub Sink_OnObjectReady(oEvent, oContext)
Dim s
With oEvent
s = "Event: " & .Path_.Class & vbCrLf
With .TargetInstance
s = s & "Name: " & .Name & vbCrLf
s = s & "File Size: " & .FileSize & vbCrLf
s = s & "Creation Date: " & .CreationDate & vbCrLf
s = s & "Last Modified: " & .LastModified & vbCrLf
s = s & "Last Accessed: " & .LastAccessed & vbCrLf
End With
If .Path_.Class = "__InstanceModificationEvent" Then
With .PreviousInstance
s = s & "Previous" & vbCrLf
s = s & "File Size: " & .FileSize & vbCrLf
s = s & "Last Modified: " & .LastModified & vbCrLf
End With
End If
End With
WScript.Echo s
End Sub
More info on CIM_DataFile instance properties you can find by the link on MSDN.

execute sequential vbscripts for SAP gui automation

I have a bunch of vbscripts that automate the SAP GUI interactions saved in a folder. I have a master vbscript that loops through the folder and finds all the vbscripts and executes it one by one.
My problem is however there is no control back from the SAP environment stating end of procedure . so what happens is that as one script is executing the next script starts to execute since the master vbs thinks the first vbs has completed executing.
Is there a way in which i could control when subsequent vbscripts will be launched ? like look into the process and check if a cscript is running and pause briefly ?
This is my master code.
Dim myFolder : myFolder = "c:\temp"
Set fso = CreateObject("Scripting.FileSystemObject")
Set sh = CreateObject("WScript.Shell")
For Each file In fso.GetFolder(myFolder).Files
Dim extension : extension = UCase(Right(file.Name, 3))
Select Case extension
Case "VBS":
sh.Run "wscript """ & file.Path & """", 1, True
End Select
Next
An excerpt from next script could help (given all info although checking Caption and CommandLine could suffice). Derived from Scriptomatic utility.
' NameSpace: \root\CIMV2 Class : Win32_Process
' D:\VB_scripts_help\Scriptomatic
'
Option Explicit
On Error GoTo 0
Dim sRes, arrComputers, objWMIService, colItems, oItem, strComputer
sRes = Wscript.ScriptName
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array(".")
sRes = sRes & vbNewLine & "NameSpace: \root\CIMV2 Class : Win32_Process"
For Each strComputer In arrComputers
sRes = sRes & vbNewLine & "..."
sRes = sRes & vbNewLine & "=========================================="
sRes = sRes & vbNewLine & "Computer: " & strComputer
sRes = sRes & vbNewLine & "=========================================="
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Process WHERE Caption like '%script.exe'" _
, "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each oItem In colItems
sRes = sRes & vbNewLine & "Caption: " & oItem.Caption
sRes = sRes & vbNewLine & "CommandLine: " & oItem.CommandLine
sRes = sRes & vbNewLine & "CreationClassName: " & oItem.CreationClassName
sRes = sRes & vbNewLine & "CreationDate: " & WMIDateStringToDate(oItem.CreationDate)
sRes = sRes & vbNewLine & "CSCreationClassName: " & oItem.CSCreationClassName
sRes = sRes & vbNewLine & "CSName: " & oItem.CSName
sRes = sRes & vbNewLine & "Description: " & oItem.Description
sRes = sRes & vbNewLine & "ExecutablePath: " & oItem.ExecutablePath
sRes = sRes & vbNewLine & "ExecutionState: " & oItem.ExecutionState
sRes = sRes & vbNewLine & "Handle: " & oItem.Handle
sRes = sRes & vbNewLine & "HandleCount: " & oItem.HandleCount
sRes = sRes & vbNewLine & "InstallDate: " & WMIDateStringToDate(oItem.InstallDate)
sRes = sRes & vbNewLine & "KernelModeTime: " & oItem.KernelModeTime
sRes = sRes & vbNewLine & "MaximumWorkingSetSize: " & oItem.MaximumWorkingSetSize
sRes = sRes & vbNewLine & "MinimumWorkingSetSize: " & oItem.MinimumWorkingSetSize
sRes = sRes & vbNewLine & "Name: " & oItem.Name
sRes = sRes & vbNewLine & "OSCreationClassName: " & oItem.OSCreationClassName
sRes = sRes & vbNewLine & "OSName: " & oItem.OSName
sRes = sRes & vbNewLine & "OtherOperationCount: " & oItem.OtherOperationCount
sRes = sRes & vbNewLine & "OtherTransferCount: " & oItem.OtherTransferCount
sRes = sRes & vbNewLine & "PageFaults: " & oItem.PageFaults
sRes = sRes & vbNewLine & "PageFileUsage: " & oItem.PageFileUsage
sRes = sRes & vbNewLine & "ParentProcessId: " & oItem.ParentProcessId
sRes = sRes & vbNewLine & "PeakPageFileUsage: " & oItem.PeakPageFileUsage
sRes = sRes & vbNewLine & "PeakVirtualSize: " & oItem.PeakVirtualSize
sRes = sRes & vbNewLine & "PeakWorkingSetSize: " & oItem.PeakWorkingSetSize
sRes = sRes & vbNewLine & "Priority: " & oItem.Priority
sRes = sRes & vbNewLine & "PrivatePageCount: " & oItem.PrivatePageCount
sRes = sRes & vbNewLine & "ProcessId: " & oItem.ProcessId
sRes = sRes & vbNewLine & "QuotaNonPagedPoolUsage: " & oItem.QuotaNonPagedPoolUsage
sRes = sRes & vbNewLine & "QuotaPagedPoolUsage: " & oItem.QuotaPagedPoolUsage
sRes = sRes & vbNewLine & "QuotaPeakNonPagedPoolUsage: " & oItem.QuotaPeakNonPagedPoolUsage
sRes = sRes & vbNewLine & "QuotaPeakPagedPoolUsage: " & oItem.QuotaPeakPagedPoolUsage
sRes = sRes & vbNewLine & "ReadOperationCount: " & oItem.ReadOperationCount
sRes = sRes & vbNewLine & "ReadTransferCount: " & oItem.ReadTransferCount
sRes = sRes & vbNewLine & "SessionId: " & oItem.SessionId
sRes = sRes & vbNewLine & "Status: " & oItem.Status
sRes = sRes & vbNewLine & "TerminationDate: " & WMIDateStringToDate(oItem.TerminationDate)
sRes = sRes & vbNewLine & "ThreadCount: " & oItem.ThreadCount
sRes = sRes & vbNewLine & "UserModeTime: " & oItem.UserModeTime
sRes = sRes & vbNewLine & "VirtualSize: " & oItem.VirtualSize
sRes = sRes & vbNewLine & "WindowsVersion: " & oItem.WindowsVersion
sRes = sRes & vbNewLine & "WorkingSetSize: " & oItem.WorkingSetSize
sRes = sRes & vbNewLine & "WriteOperationCount: " & oItem.WriteOperationCount
sRes = sRes & vbNewLine & "WriteTransferCount: " & oItem.WriteTransferCount
sRes = sRes & vbNewLine & "."
Next
Next
WScript.Echo sRes
Function WMIDateStringToDate(dtmDate)
WMIDateStringToDate = ( _
Left(dtmDate,4) & "/" & Mid(dtmDate,5,2) & "/" & Mid(dtmDate,7,2) & " " & _
Mid (dtmDate,9,2) & ":" & Mid(dtmDate,11,2) & ":" & Mid(dtmDate,13,2))
End Function

How to create a tab delimited string for QR code?

I have been tasked with populating a QR Code with a tab delimited string in classic ASP - not getting anywhere fast.
Dim tabForQRCode
tabForQRCode = strSourceCode & vbTab & strSourceCode & vbTab & vbTab & strSiteCode & vbTab & reference & vbTab & vbTab & vbTab & "1" & vbTab & vbTab
tabForQRCode = tabForQRCode & "y" & vbTab & "n" & vbTab & "n" & vbTab & "n" & vbTab & strTestCode& vbTab & secondName & vbTab & firstName & vbTab
tabForQRCode = tabForQRCode & gender & vbTab & dob & vbTab & vbTab & telephone & vbTab & "y" & vbTab & vbTab & addressLine1 & vbTab
tabForQRCode = tabForQRCode & addressLine2 & vbTab & addressLine3 & vbTab & email & vbTab & ethnic & vbTab & symptoms3 & vbTab & symptoms4
tabForQRCode = Server.URLEncode(tabForQRCode)
I am using
https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=" & tabForQRCode
My problem is that the generated QR just shows spaces. I have suggested that the client accepts XML but I suspect the answer will be no.
Any ideas? Would I have more success writing my own class or DLL?
I have tried replacing vbTab with chr(9).
Since you're sending a web request, use percent-encoding for your tab characters:
Dim tabForQRCode
tabForQRCode = strSourceCode & "%09" & strSourceCode & "%09%09" & strSiteCode & "%09" & reference & "%09%09%091%09%09"
tabForQRCode = tabForQRCode & "y%09n%09n%09n%09" & strTestCode & ...
...

Having issues outputting msgbox in VBScript

I'm running a script that performs multiple checks on a Windows machine before running a program. I'm running a VBScript script that checks things such as patch status, firewall status, and antivirus software status. After the script runs, the information needs to be output so the end user can fix any issues that arise. This needs to be output in a single message box that shows everything that is not compliant on the end users machine.
Right now after the script runs I'm getting multiple boxes for output, and none of them are displaying the names of what needs to be fixed. I'm just getting the information in quotes in the dialog box.
errors = Array(strSUpdate,strFirewallStatus,strProdState)
Dim errorfix
For Each item In errors
set errorfix = errorfix & item & vbnewline
if (errors = "Off") Then
msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
"The following requires attention" & vbNewLine & errorfix & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check"
Else
msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
"Everything looks good." & vbNewLine & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check"
End if
Next
My suggestion is to avoid arrays altogether and use the much more convenient dictionaries instead.
If nothing else you will create much more readable code that way, but they are also a lot more powerful than arrays.
Option Explicit
Dim errors
Set errors = CreateObject("Scripting.Dictionary")
' fill the dictionary troughout your program. Fill in just the
' actionables and don't insert the stuff that's okay.
errors("Firewall Status") = "Off"
errors("This other thing") = "Missing"
If errors.Count = 0 Then
MsgBox "Compliance Check results" & vbNewLine & vbNewLine & _
"Everything looks good." & vbNewLine & vbNewLine & _
"Press OK to Continue", vbOkOnly, "Moka 5 Compliance Check"
Else
Dim item, toFix
For Each item In errors
toFix = toFix & " - " & item & " is " & errors(item) & vbNewLine
Next
Msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
"The following requires attention:" & vbNewLine & _
toFix & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check"
End If
I think you need to get the return value from the msgbox, i.e., tempresponse = Msgbox(""). The link is here
errors = Array(strSUpdate,strFirewallStatus,strProdState)
Dim errorfix, tempresponse
For Each item In errors
set errorfix = errorfix & item & vbnewline
if (errors = "Off") Then
tempresponse = msgbox ("Compliance Check results" & vbNewLine & vbNewLine & _
"The following requires attention" & vbNewLine & errorfix & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check")
Else
tempresponse = msgbox ("Compliance Check results" & vbNewLine & vbNewLine & _
"Everything looks good." & vbNewLine & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check")
End if
Next
As #Tomalak has said, after each iteration you will need to clear the msgbox. Would a popup work better, as it will clear the message after x seconds.

Resources